Lesson 11 of 11
New Features
In this lesson
The pair test that two stones which are not fully surrounded are not removed, and make the almost surrounded check count three edges of the other color and one of the same. The fix also checks a diagonal, which they call the board-scanning algorithm rather than a game rule, like dispersing the fog in DND games. They add test cases, then a check above the stone for vertical pairs, fixing out of bounds errors at the top edge by returning empty there.
Transcript
[00:07] (external link, opens in new tab) >> Hey, so where you want to continue from? >> exactly where we left off. >> All right, so so yeah, right now I was renaming this test, not surrounded. >> Okay, so we were we were just saying even when it's not supposed to feel surrounded, it does feel surrounded. Right. >> Right. So, we're removing the >> Yeah, just like my emotional state sometimes. >> All right. Two is not surrounded. All right. I should not
[00:48] (external link, opens in new tab) Not remove. So, this one you could probably check both of them still like what we did last time. >> Yep. Just double control D. >> Okay. So I can just control D. >> You don't have to. You can just not have any selection. It will just do the whole line. >> Oh, okay. Oh, that's cool. And 33. All right. Cool. So,
[01:19] (external link, opens in new tab) Let's get rid of this assumption. Oh, God. Please. Let's do it. But you do it. I do it. All right. I definitely think it has to do something with this logic is almost fully surrounded. I'm sure >> the bug is that it thinks it is fully surrounded
[01:49] (external link, opens in new tab) And then it changes the stone color. No, >> no. The book is it is fully surrounded, but we shouldn't be removing it just because it is almost fully surrounded, right? >> Mhm. So it maybe the best way would be to check out what is the stone that is not
[02:23] (external link, opens in new tab) That is not the of the opposite color that is the same color. the stone. Maybe check what stone is that that is the same color and check if that stone is almost surrounded except for >> Oh, that's a good check. I like that. >> You know what I mean? So, like when we get this >> It's already doing that. >> No, it's not doing that right now. It just checks if this if it's there's four stones surrounding it
[02:55] (external link, opens in new tab) >> and there's a black. Right. So what we need to do is that we if this is a black we also need to check this black is also have is full almost fully surrounded with one black actually that yeah that's one black that'll get passing it for now. So you need to check both of them is fully surrounded almost fully surrounded that would make it pass. >> Okay. >> So it would need to
[03:33] (external link, opens in new tab) Have maybe out out X out Y for would that be like to make it too complicated. Is almost surrounded to the left, >> right? >> X + one minus one. Left should be minus one, right? >> I meant to the right. >> To the right. Yeah.
[04:18] (external link, opens in new tab) >> to to the left. Try minus one. >> You think he's checking on the other direction? >> Yeah, just try minus one. >> Okay. >> Should I try it? It's almost as good. I think your change was better. >> So, the reason those are breaking, we Let's see the names of the tests that are failing right now.
[04:50] (external link, opens in new tab) >> oh, this runs the debugger. >> crap. That's not what I wanted. Do you know what's the you want to make a shortcut for the running all tests? What I usually do is basically just have a shortcut to right click on the solution
[05:21] (external link, opens in new tab) And then I just repeat that. >> I see. >> But yeah, you can have a shortcut to that. So which ones failed? Surround opposite color stones. Surround to opposite color stones. No, not near top edge. And surround opposite color stones remove. So we just broke all the existing edge cases because because in in all those edge in all those two color stones, this actually didn't work.
[05:53] (external link, opens in new tab) So I I don't think we're far off from the solution. I mean not all these tests have us almost surrounded on right and on left. >> Do you understand what I mean? >> No, I think I'm a little lost with that. What I'm saying is that the only thing we broke >> is the three tests we currently have, >> right?
[06:24] (external link, opens in new tab) >> For when we have two consecutive stones of the same color which are surrounded, >> right, >> which are fully surrounded. >> Oh, it's because we didn't because maybe this one keeps on checking to the right. So almost fully surrounded is returning false. >> Almost fully surrounded. It should return true if we actually check on the left as well.
[06:55] (external link, opens in new tab) Right now we're only checking on the right. >> Yeah. So maybe we make a copy of that method. >> I don't think we need to make a copy. We just need to fix it. This is the the fix we wanted to do before, remember? >> Right. Okay. board get stone color of X and Y. Okay, at least I didn't break anything else. Oh, cuz that's the bottom. What I meant is
[07:26] (external link, opens in new tab) The one on the left board or get stone color X Y almost. And yeah, I I guess we should just check fully surrounded by check by by by counting, >> right? >> Mhm.
[07:56] (external link, opens in new tab) It might be easier. >> Sorry. >> No, but yeah. >> We're just going to go ahead and see what happens when I just start counting. intented edges zero. And if surround on left
[08:28] (external link, opens in new tab) On top, right, surrounded edges plus+ basically agreed. So right now it's just it's it's checking if the color on the left and the right and the top is equal to
[09:05] (external link, opens in new tab) >> You want to fix it? Now I want them all to be in the same line. >> I see. >> So I want it to be a single line for each one just so it's it's very simple just like this. Then we have >> surrounded on Right.
[09:40] (external link, opens in new tab) Surrounded left equals. And then we would have basically surrounded edges is
[10:24] (external link, opens in new tab) >> right now. I think you need to change this back to surrounded color. >> Why? >> Because you changed it. It's basically surrounded by its own color. You're trying to check it's surrounded by >> remember that it's it's ore. We are already checking. Oh, so we need to add an ore, a third ore to each one. So it's either surrounded by a different color or its own color.
[10:55] (external link, opens in new tab) Agreed. >> Oh no. Then that then it will be four. Then the value will be four for the other one. I think this method is getting confusing now. >> Yeah, it does. But just to understand the logic here, something is considered almost surrounded when it's surrounded. For us, the simplest case is that it has three different color edges and one same color edge.
[11:27] (external link, opens in new tab) >> Right. >> Okay. >> So, we need to have surrounded edges three and we also need to check u same color edge one. >> Right. I guess just copy and paste. It'll be messy. It will be a lot of code, but let's get it working. >> I just want to see if because it makes sense to me and it does.
[12:01] (external link, opens in new tab) It is a lot of checking. We can make it nicer later. Right now, we have a bigger problem. Oh god, everything is moving so slowly on my machine here. So now we have surrounded edges. Same color. >> No, you're changing the wrong one. Of course, >> you want to change the one. Hold on. >> Same color. And here.
[12:32] (external link, opens in new tab) Same color. >> Okay. I'll I'll do the changes if it's a little slow for you. >> Well, now I'm I'm in the flow, dude. >> All right. >> But now you can go ahead. Everything that requires scrolling is kind of a problem. >> All right. Oh, this one. Same color.
[13:15] (external link, opens in new tab) What do we type before? Was it rules? >> No. board.get color >> board I get color stone color of XY exactly >> XY. >> Okay. >> And now we have to do the final check is we have three of one and one of the other.
[13:51] (external link, opens in new tab) Okay, still failing. >> Yeah, I noticed that. Okay. So, that wasn't the simplest thing that could possibly work (external link, opens in new tab), I guess. But it definitely feels right to me. So, I'm trying to understand what have we missed and are we breaking different tests now? Just make want to make sure. So, it's still surrounding and surrounding.
[14:24] (external link, opens in new tab) So, what I would go ahead and do is take one of the failing, debug it. Actually put a break point right here. Where would I put the break point? Actually, we need to check for X and Y on H1.
[14:55] (external link, opens in new tab) >> So, we need to go to the add stone method. Right. >> All right. Notify stone added. So that's what we want for now. >> You want to set a conditional statement. >> >> so be four 44. >> Sure.
[15:35] (external link, opens in new tab) Okay. Run it. >> Yeah. Debug it. fully surrounded. We expect. Okay. This one. >> This is 43. We're we're this is exactly what we want to check. Right. >> Right. >> Or three. Almost surrounded. Let's see what almost surrounded returns right now.
[16:06] (external link, opens in new tab) >> Returns true. >> That's good for us, right? >> Right. So surrounded to the right returns false. So let's go back into that. >> Okay. So almost surrounded returns true or false. >> So almost surrounded returns true. Almost surround to the right returns false. >> Okay. So >> let's go to the first one. Just debug the first one. Well, the almost surrounded returns true. So, we want to do the to the right one, right? >> From what I saw, almost surrounded returns false and almost surrounded to the right returns true.
[16:36] (external link, opens in new tab) >> No, it it returned it. No, almost surrounded to the right. I'm pretty sure I saw almost surrounded to the right. How do I back out of this then? >> just press F5. See what happens. >> All right. So, if I do F10, almost returns true. F10 again almost surrounded to right returns false. >> Okay, >> so we want to look at almost surrounded to the right. >> Well, actually that makes sense because almost all to the right is
[17:07] (external link, opens in new tab) Actually 53. >> You're right. So you want >> almost rounded to the left. >> Okay. All right. So let's run. Let's get out of this. >> Yep. Let's >> just All right. This one white left. >> So it's still still something wrong. >> Let's go back. Go back. Go back.
[17:38] (external link, opens in new tab) >> Oh, go back. >> okay. That's better. Okay. I guess we have to continue to debug because I'm want We will be checking the one to the left of it at some point. >> So, that's bore four, >> right? >>
[18:17] (external link, opens in new tab) Okay. Now, we want to check is the the one at y - one. We don't have a y - one and a y - one and x - one. I think we should. >> Well, y - 1 is x -1 is a diagonal and we don't care about diagonals. >> We do care just for checking. No, I mean in this case wrapping the the black >> we would care about checking the one on the top left.
[18:50] (external link, opens in new tab) We would care about checking three >> surrounded is only like top left bottom right. The diagonals don't make it surrounded. So I'm not sure what what she's trying to go with the diagonals part. >> We're not checking the the that the current stone is being surrounded. We're checking that the stones around the stone are being surrounded. >> Right. So this >> so we can check six stones, we can check eight. >> No, but like why would we want to check the stones in the diagonal are surrounded?
[19:21] (external link, opens in new tab) Because the reason we check around the stone we were checking around where we added the stone is because it affects the stones only immediately around it like left, right, and top and bottom. It doesn't affect the stones in the diagonals. >> the reason I'm I'm thinking about it is because it's the best way for us is if we edit this, if I think if we just check this one, everything will be good.
[19:52] (external link, opens in new tab) That's why I think it would work. >> Okay. >> We're not >> cuz I think our algorithm is specifically designed currently for checking just this one. >> All right. Sure. We could try that. Or we can just rewrite the test to make it pass. I think if we take this one out and add it last, it would make it pass. >> Sure. >> So like if I >> But I I don't think Well, I don't think the problem is with the test.
[20:26] (external link, opens in new tab) That's the thing. I think >> I mean the test >> the test >> I mean we can try it right now but I think a lot of Oh I guess we can try it. It just seems a little bit weird to me. >> Oh it's definitely I think it feels weird. I agree. I'm just it's it's more of a what if this happened just like a like an Excel sheet. >> Just just control D, dude. >> Oh, it's too late. I already did it.
[20:57] (external link, opens in new tab) All right. Okay. Everything less. >> Yeah. >> All right. Wait. Okay. Sure. >> Interesting. So, do you think if we add another test that that puts the the white on the left last we will have a breaking test? >> no. because the this
[21:28] (external link, opens in new tab) That one will use this one to check it. So when once it gets to this one where checks the top it will actually check this and check that. So what what's happening right now is that these these two have to be almost surrounded. That's what our implementation is doing. So by by doing the oneway check diagonal we're checking if these two are surrounded. So for so if we take if we add this one last this will check these two are surrounded for the top part. So it'll pass. >> Okay. So my question to you is do you have a problem with the current implementation?
[22:03] (external link, opens in new tab) Except >> I mean with with the with the line I just added, you just added >> besides that it's a little bit weird because it doesn't make it doesn't really apply to the the game like checking diagonally. But it works though. So >> well I I don't it it has nothing to do with the rules of the game. It just has to do with the algorithm that looks at the board. >> Yeah. >> Okay. So given something it it right now looks at up down left right and also diagonal left.
[22:35] (external link, opens in new tab) That's it. That's all it does. >> Right. I just just imagine if I was to take this code and explain to someone how it works. It's a >> So maybe we we need to name this method differently. We can call it I mean look at the name of the method. Check stones around position and remove if needed. That's all that's what it does. >> Yeah. Yeah, I guess so. All right. We we'll continue and we'll see if >> the way I think about it is it's like do you know in all those DND games where you have the fog of battle >> and you look around it but you can only see part of the map as you walk around.
[23:13] (external link, opens in new tab) >> Mhm. >> So this is like this is what we're doing. This method is like dispersing the fog. >> It's just a different algorithm for looking around. It has nothing to do with the game. >> Right. >> Right. stone. It It checks it based on the rules of the game, >> which I mean it could easily have gone through now all the squares in the game and check them. Who cares, >> right? >> Yeah. >> It's just >> so >> So obviously I obviously something is missing and all all the pet tests pass.
[23:46] (external link, opens in new tab) First first of all we need to commit because this obviously doesn't happen a lot when everything passes. So, let's say >> All right. >> What features did we just add, by the way? >> the the one where >> where vertical vertical two two stones. >> No, we didn't. I commented that one. We added this one.
[24:16] (external link, opens in new tab) >> Oh, so what? >> We added the one where >> Oh, where it's not fully >> assumption. remove the assumption where it's not fully surrounded then it doesn't remove the stones but I would also suggest that we do multiple versions of this test >> I agree >> so that we feel more confident but just commit for now so we have something
[24:58] (external link, opens in new tab) Okay. >> Okay. So, let's do multiple versions of this test. Let's see what happens. >> What do you mean multiple version? You mean the vertical one? >> No. No. The one you just added where you said, "Oh, that's but it's hardcoded." >> Oh, this one. >> Yeah. Where you say, "Well, it's not really checked. It's just checked." it shouldn't be replaced if it's not fully surrounded. >> All right. So, forget control D again. >> Do you think the test case?
[25:30] (external link, opens in new tab) No. Maybe. I'm not sure. >> Oh, you want to use the test case? Oh, so I see. I see what you meant. Okay, that's cool. Yeah, we can do the test case. Because you did something similar like that earlier. >> Yeah. But would it would it complicate things for you or not? >> No, I think it's perfect for this. Where did you add that though? >> But you should double click on the on the pane here so it's easier to add it.
[26:01] (external link, opens in new tab) >> Double click. Didn't work. I had to drag it. Okay. >> Yeah. Double drag >> this thing here. This thing. It's pretty cool. Where where is you? Cool. >> I just replace the string with the other string >> first. Yeah. So, what did you call it? The other one
[26:32] (external link, opens in new tab) >> called >> board map. I just wanted to make it consistent. Okay, >> but you have the wrong board map here. Yeah.
[27:21] (external link, opens in new tab) Yeah. It's okay. Just remove that line. Cool. It's not pretty. It's not pretty at all. What is Oh, this ghosting. >> maybe you should copy it after uncommenting it and then comment out the other one. >> Okay.
[27:53] (external link, opens in new tab) Whoa. Okay. Okay. Now you have the part in the test that doesn't compile. >> Cool. Now we but we do need to check different position statuses for each one. >> Oh, I was just going >> hold but but you need one more parameter.
[28:25] (external link, opens in new tab) >> Oh, you just want to move the the missing things around. >> Yeah. >> Cool. Cool. Okay. Same positions though. >> Yeah. So, I was going to put the W back in here, but Oh, >> yeah. >> move this W. >> Nice. And then we can just check the other ones too. >> Nice.
[29:19] (external link, opens in new tab) Cool. >> It took care of that. >> How many tests do we have so far? >> does it say doesn't say right now? 28. Okay. Commits. Well, >> first I want to make sure. >> Oh, so so add that as a test case, dude.
[29:50] (external link, opens in new tab) >> okay. >> If you really care about it, >> I didn't really care too much. >> Set a tree with a test case. But if it makes you feel more confident, then do it. It's really important that you feel confident. >> We need some confidence after these few days, past few sessions, >> right? >> Okay. >> And just make sure >> commit.
[30:29] (external link, opens in new tab) So increase confidence. >> >> no. >> Yeah, maybe. No. >> Added variations of
[31:05] (external link, opens in new tab) God darn it. Okay, cool. All right. >> Okay. Let's see. >> Okay. So, you want to let's see what happens with this test now. This one fails. >> Okay, now it makes sense. >> So, let's make this pass and finish for today. >> Okay.
[31:40] (external link, opens in new tab) >> Another option is to refactor some of the ugly code we wrote before. I'm trying to understand why why is it failing first still because we basically we do the checking around it if oh we >> we don't check on the top >> right >> partially surrounded I think so basically
[32:10] (external link, opens in new tab) The easiest implementation would be basically copying what we did before. >> But hold on. What do you think is missing? >> Well, what you just said, we were not ch we're not checking on top. We're just checking almost surrounded to the right. This one would be checking almost surrounded on the top. >> Okay.
[32:47] (external link, opens in new tab) I think you just duplicate the if and change the if. Yeah. Yeah, I agree. Yeah. Yeah. We need an almost round on top. I agree. All right, let's see if this breaks it. Minus one. Oh, 15.
[33:28] (external link, opens in new tab) It's It's kind of like the same thing we did with the the left thing. So >> now six are broken. >> Oh, what? Oh, it's because >> the original one was this. >> No, what I'm saying is keep let's see which tests fail just to see what happens. >> Okay. >> Oh, by the way Oh, yeah. Hold on. >> >> Oh, >> no, no, no, no, no. What what I'm saying is you didn't make it on top.
[34:00] (external link, opens in new tab) Really? Just you didn't fix this. >> Oh, no. That one was 15. >> I'm saying is is that we're changing the wrong positions. We should say here >> >> minus one. >> I see. Oh, you missed it. I'll fix it. >> 14 now. But now would be a good time to to alt R and see just the names of the failing ones.
[34:31] (external link, opens in new tab) >> Well, the if actually I saw this one looks pretty nice this way. >> Okay, >> let's >> so let's just look at the names and see what kind of features you break. So we we broke add stone. We broke determine winner. >> This one is just surrounding a stone and removing it. >> Which one? >> This is the first one. >> Add stone to empty position is broken. >> Oh, this one's an index was outside the bounds of the array.
[35:04] (external link, opens in new tab) >> Look, look at this. Look at this. The second test right here. Add stone to empty position. Other empty position is unaffected. What is the What's the It looks like these are all outside the bounds of array errors. >> Oh, let's see. Index out of bounds. Okay, that's good. That's not so bad. They're all out. >> So, we just need to check if there isn't a Y minus one because all our tests are really at the top. >> So, that makes sense.
[35:34] (external link, opens in new tab) So, what if we shift escape this one? It's because when we when we did this, let's control VP. Remember how we added >> the edge? We have an edge. >> We have an edge. So maybe there's something wrong with that edge. >> Let's just check if y is bigger than board size minus edge. >> I mean if it's not bigger than that's that's all the check we need actually. I mean if we go here and say also surrounded
[36:06] (external link, opens in new tab) And y is bigger than edge it like this. I think you need to do that a little bit higher because the the the break the error is probably from right from the method when it calls is almost fully surrounded. >> Is it? >> I think it was >> I I think actually we're doing it right here.
[36:37] (external link, opens in new tab) I think if >> we don't need to check for Let's see. Okay. Y is bigger than two actually. >> And just add this here. Oh, you think it's almost surround checking? >> Yeah. Can we take a look at the error message again? >> Yeah, I see what you mean. I mean, yeah, we can we can do the whole thing here basically. >> Well, let me let me check the error message first.
[37:07] (external link, opens in new tab) One more time. How come? Where is the Okay, >> the call stack. It's yeah, it's it's when it calls it's almost fully surrounded and then it calls get stone. >> Unfortunately, it doesn't say the what the X or Y value is, >> but I wish it >> get stone returned like an like an edge over edge and then it wouldn't break >> and then it's not and it's not white and it's not black.
[37:40] (external link, opens in new tab) >> That's one way to solve it. >> That's interesting. like basically if x is all right for now just for us is if y is smaller than zero or is it one? Yeah. One. One. Yeah.
[38:11] (external link, opens in new tab) >> Return. You know what? Let's just say empty. >> No, no. Edge. Edge is good because empty would mean like it's empty position. So like anything we do the edge. Well, we can do empty right now and then we'll just add that feature later on. >> I just want you to notice that all the tests are passing now, >> right? Right. >> All right. We'll just keep this for now and then >> You're welcome. >> Thank you.
[38:41] (external link, opens in new tab) >> but yeah, but you can change it to edge. >> All right. >> And then we can do a test that says we need to check for X as well. But >> for now, >> so what did we just do? What feature did we just add by the way? >> vert vertical Okay, sounds cool. >> That's cool. >> Let me add in a todo.
[39:13] (external link, opens in new tab) >> Yep, I think that's good. >> All right. All right. >> Commit. Push. >> Commit >> and pray that nothing fails on my machine tomorrow. >> All right. >> Okay. >> >> let's see. Commit added vertical to surround two opposite color stones in vertical mode. Okay, that's good. Virtual. Virtual. >> Yeah. Nice. >> All right. >> Okay, Raymond. >> I forgot I forgot to >> Yeah, sure.
[39:46] (external link, opens in new tab) >> Cool. >> I'll see you in session number 1 million35. >> Okay. Cheers everyone and hopefully you've had a better time than us. >> Cool. Okay, now it's stopped. Let's see if it actually