 Welcome to Minesweeper, basic game functions in Python with Tokyo EdTech, that is me. And let me give a quick shout out to my members. You can see here, people who have chosen to pay and support channel, thank you so much. I appreciate every single one of you. I do also appreciate viewers, subscribers, everyone. I appreciate everyone, what can I say? So today we're gonna be taking a look at how to make the game Minesweeper. Now I got this off of the Wikipedia, but basically hopefully you know what Minesweeper is. There's some Mines, you have to find them and you click and you right click and do different things. Now today, what I'm gonna be looking at is not that big nice graphical thing. And this is where beginners often get hung up on, okay, well I gotta have all these graphics, how am I gonna click on it, how am I gonna right click, how am I gonna do all these different things? And what you need to realize is that a text-based version of the game is gonna have all of the basic features that you need. And once you solve that problem first and then you can start solving the graphical side of or how you interact with the computer. And so what I wanna do today is basically as you can see down here in this image is to come up with a basic text-based version. This is not gonna be a working game. This is just gonna be the functions that you need to create the game. And again, this is I think a really good lesson for beginners especially just because beginners need to understand how, how can I put it, that the way the information is represented in the computer's memory is different to how it's displayed. And that's a really key concept. It's a type of abstraction that you see. So let's go ahead and start doing some coding and we'll see how far we get here. I've chosen a nine by nine board and the reason I've done that is because, well actually the reason I'm making this video is one of my students is working on this for her final project and so I can help her, actually so I can better help her, I'm gonna sit here and figure out how to do this. So I've done some of this already so I have an idea of where I wanna go but I do wanna make some changes. So let's go ahead and do that. So the first thing we're gonna need is we're gonna need a grid. Okay, and this grid is gonna be a two-dimensional list and as I mentioned earlier, it's gonna be nine by nine. Okay, so I'm gonna go ahead and put zero comma zero, maybe no spaces to keep it easy to read, zero, three, four, five, six, seven, eight, nine and comma, I'm gonna go ahead and copy that and see here, two, three, four, five, six, seven, eight, nine. Okay, so I now have a grid of nine rows and nine columns. Now note, we're doing rows and columns, not columns and rows and this is important because of the way this is structured and it's just, if we think like that, so it's all rows then columns so we're doing basically y than x if you wanna think of it that way but it's probably easier to think of it as rows and columns. Now this particular grid, yeah, I'm doing, I'm just gonna say I'm using it to represent where the mines are. That's the only job of this particular grid. So I'm gonna go ahead and just put a one where I want the mines to be and I'm gonna put that like that and I'll put some more stuff over here and I'm just making them randomly, doesn't really matter where I put them. Again, I didn't need to choose zero and one but it makes sense and it's kind of basically what our grid is going to look like. Now what I'm gonna recommend doing here is the following. I'm gonna say empty equals zero. I'm gonna say mine equals one. So anywhere there is a zero or that means that it is empty and where there is a one, it means there is a mine. Now I'm gonna be using this later in my code. So I'm gonna put this declare constants. All right, now we have a grid and this is where, again, this is where all of the, I put it, this is where all of the mines are located but we're also gonna need a secondary grid for the player. And what I can do actually is, well actually I'll do this way, player grid equals. Now the player grid has to be the same size as the grid and what I'm gonna put in here, I'm gonna put minus one and I'll explain why in a second. So two, three, four, five, six, seven, eight, nine. And again, I don't know if this is the absolute best way but I know it's a way and I think it's a way that my student will understand as well. Three, four, five, six, seven, eight, nine. And hopefully people viewing this will understand. Okay, so you can see I've got a nine by nine grid here, I hope, I'm gonna go ahead and run this and see if anything happens. Okay, good, there's no errors, so far so good. And then what I wanna do is up here I'm gonna make unknown, negative one, oops, unknown. So the player grid, now when we start the game, the player hasn't made any guesses yet. So the player doesn't really know what's in the grid. So it is unknown as opposed to we know how many there are, how many different neighbors there are. Okay, so this is an important thing. We have basically chosen a way of representing the data. Now I could have done it like this, I could have done an empty space and then I could have done, say, M for mine. Okay, that would work. And it'll take up a little bit more memory, it'll be a little bit more processing, I believe. But I think this is an easier way just by using integers to represent these values. And then by declaring these constants, we get to still use the integers as our data type, but we also get to use variable names to make our code clear and easier to understand. So in no particular order, what I wanna do is I wanna start making some functions. So I don't know if it matters which order we do it in, but some of the things in this game, we're gonna need to click, okay, and so I'm gonna make a function called define click, and I'm just gonna put pass for now. We're gonna need a set flag function and pass. Let's see what else. We're gonna need a function that will count how many mines there are near our particular spot. So I'm gonna say, you know, count is called count, it's fine, and pass for now. And then also we're gonna need a function to show the grid. So I'll say show grid and pass. So I mean, for now, we can just basically print the grid, but what we wanna do is, I'm trying to think where we wanna start here, because we started any of these. Now count is pretty complicated. Click is pretty complicated. Set flag's not too complicated. Show grid's not particularly complicated. So let's go ahead and let's do a basic click, okay? So thinking about our grid, what we wanna do is we're clicking on the player grid, well, I guess it doesn't really matter, we're clicking on the grid somewhere. And what we're gonna do in this program is we're going to basically simulate that. We're not gonna be doing the actual clicking, we're just testing the functions. So let's go ahead and click, and we're gonna be clicking on a row and a column. Now how we get that information into the function will depend on which GUI toolkit we're using, but for now we're just gonna use some simple functions. So the first thing I wanna do is check if it is a bomb. So this is probably the easiest part. So what I have to do is check the grid. So if grid row, remember it's row column, not column row, equals, do we do a bomb? Oh, mine, not bomb. So equals mine, and again, this is equal, this is the same as putting one, but I figured if we do it this way, it's a lot easier to understand what the code is doing. I'm gonna say print, boom. And basically you've died. And we could end the game here, but this is just for testing purposes. So let's go ahead and run this. Okay, nothing happened. So what I wanna do is I'm gonna put some testing code down here. So let's look at our grid. So this is row zero, one, two, three. So you can see at zero, one, row one, column one, there is a mine. So that should give us a boom. Let's go ahead and test it. So we're gonna say click, one, one. Let's run it, and you can see down here we got a boom. Now, it doesn't mean the code is working correctly. So we should also test it on an empty spot. So I wanna do zero, zero, and run it, and you can see nothing came up. So this gives me some confidence that it is working correctly. And I think it's working correctly. That one's pretty straightforward. Now at this point, we probably wouldn't print, boom. We would print out the whole thing with all the bombs printed and sort of things. But for now, we're just gonna do boom. And again, we're just testing the logic of our game. And the logic is a bit complicated as you'll see. The next thing I wanna test out, which is probably the, well, tie it, let's go ahead and do set flag. Set flag's pretty easy actually, I think. So again, we'll do row, and call. So when we set a flag, we can only set a flag where it is unknown. Where the player hasn't already clicked or hasn't already, how can I put it? Hasn't done the count, so we don't have a count yet. So what I wanna do is if player grid row and call equals unknown. And again, unknown is simply negative one. But because I did it this way, it makes it more clear. Then what we can say is player grid row, call equals and what I'm gonna do is I'm gonna use negative two for flag, equals flag. Okay, so up here I'm gonna put flag equals negative two. Now, if you're wondering why I didn't use like positive numbers, like two for unknown and three for flag, it'll become clear in a little bit. So just trust me on this one for now. And let's go ahead and test this. Let's go ahead and test that. So we've got to click and let's go ahead and do set flag. And let's go ahead and look at our thing. Yeah, let's set a flag here at zero, zero. Okay, so zero, comma, zero. Again, this is row column. And then to test it, yeah, so what we'll do is we'll say print player grid. So let's go ahead and run that. And you can see we got a negative two there. Now, this is not a particularly attractive way of printing this out. So let's go ahead and fix that, okay? So let's go ahead and do our show grid method. And what we're gonna do is we're gonna do the following. So we're gonna do four row in range, the length of the grid. And I guess we could do this with, we'll just set it to player, because I don't think we ever actually really need to see this grid. But we do need to see what the player is doing. So I'll go ahead and put that player grid. And again, it would be smart to put the value here and pass it in. I could do this with classes, but I think this is probably an easier way for most people. And then I'm gonna say row, let's see. And then for call in range, length. And then watch this carefully. It's player grid row, because it's the current row. Make sure you have enough parentheses there. So row and column. Now I could have just done nine because we set the size. But if we do it this way, if we change the size of the grid later, it's still gonna work. Now watch what I do here. Well, for now, I'm gonna go print. I'm gonna use an F string. Okay, and this is Python 3. This will not work in Python 2. So what I wanna do is I wanna type, let's see here. Let's just say value for now equals player grid row call. And let's go ahead and print the value. Okay. And so down here I'm gonna go ahead and do show grid. And then also at the end of every row, I need to print. And what this does here, this section here, you may not have seen that, is it prevents the print statement from going to the next line. Because what I wanna do is I wanna print across. And this is similar to if you're coming from Java, this would be like print versus print line, or print line. Okay, there we go. So now there is our player's grid. These are all unknown. And this is where we put the flag. Now you can see we click zero, zero and nothing happened because we're not finished with that code yet. But what I wanna do here with the grid is I wanna print it out a little bit nicer than this. It just happened to work out because they're all negative numbers. But if some of them weren't, it would get kind of messed up. So what I wanna do, I'm gonna type symbols equals, and I'm gonna make a dictionary here. And so let's see, our first one is gonna be a negative one, and that's, I'm gonna use a period for that. Our second one's gonna be negative two. I should've probably just done the other order. Do negative two, and that's gonna be an F for flag. And then if it's a zero, actually if it's a number, we'll just leave it the way it is. And yeah, we'll do it that way. So if it's a one, no, we can't do it that way. So negative two, F, negative two, and I guess that's it, actually. Yeah, for now, that's gonna have to be it. Yeah, so I'll say if value in symbols, we'll say, hmm, symbol equals symbols value. So if it's negative two, give me an F, if it's negative one, give me a period, and we'll put symbol here. Else, symbol, we wanna equals the number, equals value. Maybe I'll make that a string just in case, because we wanna print out the numbers. Let's try that one more time. Okay, that's pretty good. So now we've got a flag, and we've got a number, and we've got a number. A flag, and nothing else. All right, yeah, so far, so good. So let's go ahead and take a look here. The next thing we wanna deal with is counting. Okay, is how do we count? And this is where it's a little bit more complicated. So we wanna count how many minds there are adjacent to a particular spot, okay? So let's say, for example, we're at row zero, one, two, column one, so we're here. The answer, obviously, should be four. Okay, so what we have to do, is we have to check this space, this space, this space, this space. So we have to check all eight locations to see if there is a mine. If there's a mine, then we count it. Now, the thing we have to be careful of is let's say we're here, there is no space here. We'd get an error if we tried to access that. Okay, so we have to deal with that situation. So let's go ahead and give that a shot and see what happens. I have a pretty good idea of how to do it. And let me get a drink here, so you can probably hear my voice is getting a little dry. This is kinda interesting, this is actually an interesting problem. And so basically what we're gonna do is we're gonna return the count. Okay, now, in this case, we're only looking at this grid. Okay, we're not looking at the player grid. But the answer is actually gonna end up going into the player grid, but that's for a different section. So what we're gonna do, is we're gonna be starting at a particular row and column. Okay, and as I mentioned, we need to look at the upper left, top, top, right, bottom. So I'm not quite sure what we can call this. Let's go ahead and try and call this offsets. Okay, and then we're making a tuple here. And it's a tuple, not a list, because it's never gonna change. Okay, so again, so from here to here, so starting here and going here, it's minus one row, minus one column. Okay, so I need to do the, let's see, where's that at? I need to do all of those in this tuple. So it's gonna be minus one and minus one. Let's put them together, save space. Then we're gonna be doing minus one, zero, because it's, again, it's Y in X, it's columns, it's rows, and then columns. And then we're gonna be doing minus one and one. Now we wanna do the right middle. So it's gonna be the same row, but plus one for the column. Then we're gonna do the bottom, that's gonna be one and one. And normally I would put spaces in here, but I don't want to go off the screen. So then it's gonna be one and zero. And the order doesn't really matter here. Then it's gonna be one and negative one. You'll see what I do here in a second. And then we need the box to the left, the cells to the left. And that's gonna give us zero and negative, negative one. So this is all of the offsets. Now we're looking for a count. So we're starting out count zero. And what we're gonna do is for offset in offsets. So we're gonna have an offset for the row and an offset for the column. So offset row equals offset zero. Offset for the column equals offset one. As this is the rows and this is the columns. And we're just iterating through each of these particular offsets. There's eight of them. Now I could have done a bunch of if else statements and that would work, but this is gonna be a little bit better for you I think. Now, as I mentioned, actually offset row, yeah. So then our row that we're looking at, actually we'll do it this way. Offset row equals row, the current row plus the offset. And the current column plus the offset. Okay, so if we're at, what do we say here? So if we're at zero, one, two, if we're at two, one, we wanna look at one, zero. We wanna look at one, two, and one, three and all the way around. Okay. So we take the row that we got passed into the function, that's the center, and then we add the offsets for the row and the offsets for the column. Now, we have to check four boundaries. Okay, now, it's very, very easy to do. So if offset row, actually we got a couple different conditions here. So if offset row, it has to be greater than or equal to zero and offset row is less than or equal to eight because there's gonna be nine. And offset call has the same restrictions, greater than or equal to zero. And offset call is less than or equal to eight. And again, I know I could generalize this a little bit better but I think this is easier to understand. So basically as long as these offsets are within the boundaries of our grid, then we can go ahead and count it. So if grid offset row, offset call for column equals, and again, I'm gonna put mine here. Because mine is one and zero and one tells us it's a mine. Then we say count plus equals one. And again, there's a loop here. So once the loop is finished, we return the count. And that is it, that's the function. So we have our offsets because minus one, minus one, minus one zero, minus one one, zero one, one one, one zero, one negative one, zero negative one. Again, these are row column combinations. And then we count and for each offset, we calculate the new row and the new column. And some people might write temp row, temp column, whatever you write is fine. I'm really particular about variable names so that it is obvious what's going on. And then here we gotta check and make sure that it is within the boundaries of the grid. And then return the count. So let's go ahead and test it. So again, let's do zero, one, two. So column, or row two, column one. So let's go ahead and print, get, count. Nice, all right, let's call it count. Count, okay, let's do it, call it count. And the row we said was gonna be two and, was it two and two? Or two and one, two and one, I think. Two and one, yeah. So we should get a four there. So let's go ahead and test it. And we got a four, I'm really happy with that. Okay, now let's test a couple others. Let's test a case where there's none. So let's do this one here. So this is gonna be zero, one, two, three, four. And column seven, so four, seven. Okay, zero, that's good, that's what we wanted. And let's do one more. Let's do row seven, column two. Okay, we got two. So far it's working. Now I should test more combinations to make sure I didn't make a mistake, but I'm pretty confident that I did it correctly. It's not my first time with the rodeos, they say. All right, so now we have a way to count how many there are, okay? So far so good, I'm pretty happy with what's going on. Now, this next part is where it gets a little complicated. Yeah, it gets a little bit complicated. We gotta think about how this is going to work. And those of you who've done a bit more programming, we could do this, I think, as a recursive function, which would be a way of doing it. I'm just gonna do it with a little bit of loop action and some if statements. So we gotta think about what happens in this game. And it's a little bit similar to what's going on here. So I'm gonna be copying some of this code, actually, and using it. So what we gotta do, so let's say the player clicks, let's say the player clicks here. And again, I'm not an expert on this game, so I might be doing it wrong, but we'll worry about the exact rules later. So I'm gonna click here, and then I'm gonna start checking. Well, first I'm gonna check if it's a bomb or not, if it's a mine, if it's a mine, game over. We've already done that. We've already got our click method, and if it's a mine, boom. And I could just say, exit game over. But probably what we're gonna do is we're gonna print it out with a mine shown. So let's come back to that in a bit. So we click a spot, and then we look up here and check if that's a mine or what the count is of that particular spot. This is my understanding of how this game works, because I'm not an expert on this. And so if there is a count, then we stop checking from that spot. If it's zero, if it's empty, yeah, so we gotta kinda combine the two different grids, and again, there's probably an easier way to do it, but this is the way I came up with. And so we gotta look at each grid and figure out kinda what's going on. So I'm gonna go ahead and take a shot at this. So again, if it's a mine, print, boom, game over. If it's not, so if it is not, what we wanna do is we wanna look at a couple different things. First, we wanna know is the grid empty? And actually I guess we don't need to do that because it's either a mine or it's not, so I guess we can skip that check. But what we wanna know is, actually, yeah, I guess we can say, let's try this. So if the player grid row and column is unknown, so that means if I've chosen a spot that is a period, that means we don't know what we're looking at yet. Okay, if we go back to this, this would be an unknown. Okay, you can't see my, sorry, you can't see my mouse, but any of those gray boxes would be unknown because we haven't clicked on it yet. Okay, so I'm gonna go back to the main screen and so if it is unknown, then we're gonna say that grid spot is now empty. So player grid row call equals empty. Now empty, if we go up here, is zero. Now I could have put a zero there, but that's okay. And I think this is correct. Again, I'm not 100% sure about the rules of this game. Yeah, my student chose this game, not me. It's a cool game, but I just don't know it that well. Let me go ahead and try this and see what happens. So let's go ahead and click on a space that is empty. Click on a space. So, oh, we did, we already did click on zero, zero. So let's go ahead and test that. I know because we set flag. So let's click on different spots. So let's go ahead and click on, no, I don't know. Let's say row one, one, two, three, four. Row one, four. Okay, so row one and four, so one and four. You know, I had this when I was testing it and I do this every single time and it is line 55. So probably those of you who are following along realize I did this wrong. And I don't know if that's like an old, I don't know if it's a different, it must be the way it's done in a different language. It's why I keep getting confused from the Python way of doing it. And let's go ahead and run that again. Okay, aha, that's what I wanted. So this is the spot that I clicked on and it has got a zero. But actually now that I think about it, it shouldn't be a zero because what if there was, what if there was something near it? So what I'm gonna do is instead of right equals empty, I'm gonna say equals count row and call. Let's go ahead and run it. Function object is not scriptable. So this is row comma column. That's where I was getting confused. Count count count and I'm gonna use parentheses because it is a function, not a list. Okay, now it's still giving me zero, which is probably correct because there are none around it. But what I'm gonna do is I'm gonna test this spot here instead, so I'm gonna do row one and column, so basically one and zero. Let's go ahead and test that, one and zero. Scroll up and there we go. It's basically functioning as I expected because there are two mines near there. Now what we gotta do, and this is the hard part, is we have to check all of the connected spaces. Okay, and again, I'm not 100% sure the rules of this particular thing, but my understanding is that we check up, down, left, and right and the corners. If it's not the corners, we can take that part out, but we'll test it so that it works for all of them. Up, down, left, right are all of them. Actually, I don't know. Let's look at the secondary screen here. You know what? It must be only up, down, left, and right because it's not extending. Yeah, I think it's up, down, left, right. I'm gonna program it up, down, left, right, but it would be easy to add because I'm gonna make it very general. So let's go ahead and take a look at this. So, this is where it gets a little complicated. Ah, that's what I did. Okay, so I did it a little bit differently before. I'll leave it the way it is. So, I'm gonna go ahead and do this. Okay, so find all connected, I'm gonna call them cells, find all connected cells and their values. Okay, so what I'm gonna do, and this is a bit algorithmic type stuff, so I'm gonna make a list, excuse me, and I'm gonna start at the current row and column, okay, which is where I just clicked. And then what I wanna do is I wanna get the same offsets. Again, I think I need to change this because I don't think I wanna do the diagonals in this particular case. And if that's wrong, it's easy to fix. So I'm not gonna do the diagonal, so that means anything that doesn't have a zero in it, I'm not gonna use because there's up, down, left, and right. So let's do it that way and we can change it again later if need be. I'll have to ask somebody how this game works. Okay, so I'm looking at up, I'm looking at right, looking at down, I'm looking at left. Now this is where it gets a little bit, you know, you may not have seen some of these things before. So while the length of the cells is greater than zero, so currently, cells has one cell in it, that's the starting point. So while the length of cells is greater than zero, what we wanna do is do some checking. We're going to first take a cell and we're gonna pull that cell out of cells. So to do that, I'm gonna do cells.pop. Okay, and what pop does, if you haven't seen that before, is it removes the last item in a list and returns it. So in this case, there's only one item, so it's gonna pop that off of the list. So what I'm gonna do is check this particular cell and everything around it. And this is basically what we just did. So watch what I do here. So for offsets, for offset in offsets. And then the row is going to equal offsets zero. Zero plus cell zero. And the column is gonna equal offset one plus cell one. So again, cells is a bunch of rows and columns. Right now there's only one. You'll see what I'm gonna do in a second. So while the length is greater than zero, so right now there's one. So the length is greater than zero. We pull off one of those. And then for each offset, same thing we did. So we take the offset plus the row. We take the, and again, I could have done it, I could have done it, like I did up here, I could have done offset row and offset column. And, but since we've already done it once, I'm just gonna do it this way. Okay, so our row and column. So we're looking at the, okay, we're looking at the cell above it. We're looking at the cell below it. Cell to the right, cell to the left. So what we wanna do, we've got several, how can I put it? We've got several conditions that we need to satisfy. So first, the order doesn't really matter. So if we look at the player grid, we can only go where there's a negative one. We can only go where it's unknown. So that's our first condition. So if player grid, row, call equals unknown. And again, this is just a negative one. Now I'm gonna put a little extra parentheses around here to clarify. And here's gonna be our second condition. In this case, we gotta make sure that the grid, so we gotta make sure that this is empty at the same spot. So I'm gonna say, and grid, not frig, grid, row, column equals empty. And unknown counts, let me just check real quick. Okay, then I think what we're gonna do, can I think what we're gonna do is this. There might be another condition. Let me just play with this for a bit. I'm gonna say player grid, let's see it's zero. Player grid, if it's empty. Okay, so if it's unknown, so if we don't know what it is. Okay, it's unknown, that's right. Okay, so then player grid, row, column equals count, row, column. So the count that goes there. Now, no, we are looking at the offsets from our current spot. So, what we gotta do, this is where it gets a little complicated, if it's not already. So if this row and column is not in cells, so if we haven't already looked at it before. Well actually, all right, let's play around for a second, I'm not sure, but I think there's a mistake, it's not in the cells. Then we're going to append it, so cells.append, row, call. And then there's another condition up here. And it's empty, and sorry, then this is complicated. This is a tough one, what is it? So if it's empty, so count, row, call equals empty. So that's the next condition. Don't forget the extra parentheses at the end here. Then we put the count in there. Now if it's not in cells, pen, row, column, else, player, grid, row, call. Equals, double equals equals count, and row, and call. And I am hoping that this is right. So we'll find out in a minute. So let's go ahead and run it and see what happens. I don't know. Function object not subscriptable because counts, yeah, I did that again, line 67. So it's telling me that the function is not subscriptable because count is a function, not a list. So I'm going to do row, column, parentheses. Let's go ahead and run that, and okay, so it did not work. I just did not do what we wanted it to do. So that's, well, did it? Actually no, it did do what we wanted it to do. But do we have to do these? This is the part I don't remember if we have to do the other angles. Let's go ahead and do the other angles, just see what happens. That's something, if I'm wrong, you can fix later. Part two, I'll come back to that after I talk to my student about this one. Okay, where did I go wrong? Again, I probably did count, row, yeah. So I did the exact same thing. It's probably annoying for those of you watching at home and I'm doing this, and you know I messed it up. And line 68, I did the same thing. I did that everywhere, didn't I, for having sex? So we got list index out of range because I forgot to do the checking like I did up here. So I'm just gonna go ahead and copy this, check for the boundaries first, and all this has to be indented. This is pretty complicated. Again, there's probably a much simpler way to do it, I just don't know it. And this should be row, not offset row. And again, I'll put a link down to this code down below. It's still not doing quite what it's supposed to, I don't think. Let's give this some thought here. Good white equals unknown. And it's a shame if anybody's watching, we can ask, but in grid, row, column equals empty, and counts, row, call, empty, okay. My chain, empty, empty is not, that's not correct. It should be zero. Or is empty zero? Let's check real quick here. Yeah, empty is zero, so I guess it doesn't really matter. But we'll leave it there. Let me try another spot just to see what happens. And this, like I said, this one's complicated. All right, let's try different spots. So we clicked here, because it should go up here. No, because there's a flag there. So let's get rid of the flag and see if that makes a difference. Flag, flag, flag, flag, flag. No, because the click comes before the flag, so this doesn't really matter. Yeah, so you see how it's not expanding, which is kind of annoying. So let's give it some thought. That's correct. Player grid is unknown. And the count is zero. And the grid is empty. And if row column not in cell, cells append row column. Okay, now naturally, of course, this worked when I tested it earlier. I'm gonna pause this, try and figure out what's going wrong. If I can pause it. No, there is a pause method. So you just have to bear with me here, because I don't like to, I'm gonna put it. I forget, I don't know how to. Anyway, yeah, so I'm a little tired, so I'm getting a little rambly here. It's unknown. So the player grid is unknown, yes. And the grid is empty, yes. And count row. Hmm, player grid row equals empty, yeah. So far so good. This is the only part I'm not sure about. Well, it shouldn't be zero, because it's, ah, that's not possible, I don't think. Okay, well, that's a start. Now that is not what I expected to happen, but it's probably closer to what I wanted to happen. Let me go ahead and delete all the diagonals again, just see if that's what I needed to do. So I just had a situation I think, I think it was just a little stupid error, but this is a complicated one. And again, it took me a while to figure this out earlier as well, so. Okay, so then, all right. So if count zero, because if it's not a zero, yeah, and I think this might be it. Let me test it, if it works, I'll explain it. Yeah, yes. This is what I wanted. Okay. Yes, I think this is it now. Okay, so we don't keep expanding. So like, for example, this is where we clicked, okay? And there is one, two, okay? So we didn't do this one. So I don't know if I'm supposed to do diagonals or not. I think maybe I am supposed to do diagonals. Let me go ahead and throw that back in. It's not quite looking like what I wanted to. Again, those of you who know the game are probably like, duh. But yeah, I think, is that what we wanted? Yeah, I just, I'm not sure about this game. I just don't know how it's played. But let's do it without the diagonals for now and then we can add it later if you need it. So let me go ahead and try. I'm gonna go ahead and put a one here. And then I'm gonna click on this spot, so which would be eight, eight. And what should happen is this whole section, we should have zero, two, et cetera, et cetera. Okay, so let's test that one. And we're gonna click on eight, or because I think counts working. Okay, I think that's correct. Let's scroll up here, because this should be zero. This should be zero. This is a one. Because that's one. This is a two, because that should be a two. And why is that not working? Oh, that's a three. So that's a two. That's a three. Yeah, I think it's working. I think that's what it's supposed to do. Again, I'm not 100% sure, because I just don't play the game. But I think that is basically what's supposed to happen. I think. I'm just gonna throw a couple more clicks in here just to kind of experiment here. Let's put some more ones in. One here, one, there's a whole dividing line here. And then I'm gonna click on zero, one, two, three, four, five, and zero. So click, click, zero, yeah. Zero, row zero, and column five. Let's go ahead and run it. And, yeah, I think it's doing what it's supposed to do. Yeah, I don't know about the diagonals. That's the only part I'm really unsure about. If I throw the diagonals in there, does it look better or worse? Yeah, I might have to put that. Yeah, in part two, I'll come back and hopefully have the answer for you. But yeah, I think the diagonal, I think that's what it's supposed to look like. I think that's better. I'm happier with that. That looks more like what the game looks like that I can think of. So I think it is working. I think it's working. Let me go ahead and add a flag. Okay, so let's put a flag, let's say here. So that'd be zero, one, zero, one, two, three, four. So it'd be one and four. I'm gonna put a flag at one of four. So set flag at one and four. Just see what happens. Okay, and I think that's what's supposed to happen too, because does the flag block it? I'm not sure, I'll be honest. I don't know enough about the game. I have to go review the rules and kind of play it a couple of times to figure out if this is right. But I think this is basically the idea that I wanted to get across tonight. Was that the representation of the data, in this case, zeros and ones for the grid, where the mines are, and then using negative one for unknown, using negative two for the flag, and then zero means it's empty, and then one means there's one mine in the area, two in the area, three, et cetera, et cetera, et cetera. So this shows you that the representation here is different to how we output it, because we used an F for negative two, we used a period for negative one. Now, if we're gonna switch this over to a different graphical toolkit, of course, we will show the grid in a different way, but we have a function to do that now. And so we can easily convert it, but the basic game itself is kind of working in the background. We can do the count, we can click, we can set a flag, and probably what we might wanna do is LF player grid, rows, row, call equals flag, because if it's a flag, we wanna reverse it, player grid, row, call equals unknown. So I think that's how we would reverse that. So let's go ahead and test that real quick. So set flag one four and set flag one four. So that should erase the flag. And it didn't get an error, which is good. Oh, the flag is still there. So set flag. Why is that not fixing itself? Set flag one four. Equal sign, duh. And so yeah, so the flag is missing. That's about what I wanted. Again, I'll have to check the rules to confirm, but hopefully you can see now, we at least have the grid working for the most part. Again, the rules are maybe a little bit off, but I will put a link to this down below and you can enjoy that. Okay, so thanks for watching. Click like, subscribe if you can, sign up as a member for Early Access and all that kind of goodness. Hey, take care and as I like to say, keep on coding.