Welcome to this new lesson. In this lesson, we're going to continue with what we left off. We're going to start learning about grid operations. We introduced a little bit of this idea in the previous lesson. We started talking about how in a grid, an index position in a grid has adjacent or neighbors, if you want, entities or neighboring cells. Let's take this example, for instance. The position that we have here in the red spot, which is in the coordinates 2 and 3, that doesn't mean that it is in fact the index 2 and 3 as we saw last lesson. But this position has neighbors, and we will consider these neighbors. The first order neighbors are going to be the direct adjacent entities. Depending on the data structure we're using, minus one in this direction, plus one in this direction, we will actually need to be able to locate the position of those neighbors. We can also think of neighbors of a more extended order. The certain operations that we might want to do that involve a whole range of neighbors, and you can continue this thought to even much larger range of neighbors like second rows and so on. But these are some of the first concepts of neighboring cells that we will actually start identifying. What we're going to start doing here, we're going to create an entity like this red dot here that we're going to call walker. We're going to just start in a position. We are going to identify a position. It could be a random, but somewhere in the grid. Instead of creating a new entity at a random position, we're going to ask it to, let's say, delete a white rectangle, which is exactly what we were doing in our previous example, but adjacent to its current location. How would it be if we have a worker that starts eating up the color but gradually moves through the grid in adjacent cells? That we can do those operations just by understanding where the unit is located and how would we move back and forth within the grid. Let's just get started with them. As I mentioned, we are going to continue working with our script. We're going to be basically using the same script, but let's just create a variable that will represent our worker. Up here, we're going to identify a variable which is going to be an integer and we'll call it integer current x. We're going to start with a zero and an integer current y, that is also going to be a zero. If you want to make a comment here, this entity, let's call this the walker. These two variables are going to represent where our unit that will move around will be located. That's what we need to do at the level of the global variables. Let's bring those variables in here with global. Now that we have those variables here, let's just double check that this is all working. That's fine. This is where we left off last week. Instead of creating a random movement, we're going to delete that, we don't need that anymore. Let's just get rid of that so that it's less confusing. We are going to define one position, let's start with something like a 20 and a 30, which is going to be an arbitrary position where we want our workers to start. This is going to be defined in index coordinates, so we need to make sure that we multiply this value by its cell size if we want to convert it into actual coordinates. Let's go ahead and remove some of the code that we left from last lesson. We don't really need to do the random index anymore, we can also get rid of this part down here. But the new position x and the new position y, which identifies the position of the rectangle. This time it's going to be identified by the walker variable. Let's do current index times cell size. We have to do this just because we want to convert index into a natural coordinate within the world. Let's see that. We have this information here and then we have this 20 and 30. Is this the rectangle? Let's just double check if we want to be more explicit with this, we could actually do an ellipse and let's do red. We can see if we identify its position. I find it. I guess the colors are pretty. We wouldn't find it because we have an error here. Let's see. Oh, there we go. Here is this red circle. We see that it's in fact located in the corner, the ellipse actually draws itself from the center. Let's just do a rectangle again. Here we go. That is the red rectangle. If we want it to be, again, more explicit, we can do it black or let's just, let's see if black, it's a bit more visible. There we go. It's a black pixel. We are going to do it as we did before with the white color. I think the white color works quite nicely. What we want to do now is that now that we have the rectangle in the grid being determined by this current index or the integer current x, which is the variable for the worker, so the worker variable here, what we want to do, let's do a comment here. What we want to do is make the worker move randomly in x or y. The way we would do that is saying that the integer x could get a plus or minus. Let's add to that value which is currently 20. Let's add a random value of minus 1 and 1. Random.rangrange. We will add plus one or minus one at random. Let's do the same thing for y. At any given in every frame because we're doing this within the draw, we will add one in x and one in y. There's going to be some errors here. They are going to be some exceptions that we're going to run into. But let's see if this starts to make sense. Again, we're running into an error. Let's double check what's wrong. Random range is going to give us floating point. Let's run in. I think I misspelled that it should be rang int. We want to make sure that we keep the random to give us integer values. The rang range could be able to give us a floating point and that would actually make our system not really work the way we're intending. Let's just create a random integer which is a minus 1, 0 or 1. Let's see if that actually works. We have that working. We have this little entity. I call it an entity, but in fact it's just a number that is randomly going up and down, positive or negative, until it reaches an H condition which should be something that we want to avoid because we run into an error there. Let's see how we can actually do some exceptions. Now we actually have a walker. We are identifying that we can actually create one unit to move plus or minus within this grade just by adding a random number to it. But here we could also say, there's an exception, there's an if this entity or the coordinate in x is smaller than zero. Let's just do it this way. If the index in x is smaller than zero, let's just make it remain in zero. So we're going to make sure that it never goes below zero. In a similar way we could actually say that for y. So let's just copy paste that statement. That would fix that our unit does not go outside on the left or on the top right, because those coordinates are defined by the zero boundary. We're covering for two of the four boundaries of the screen. We could also identify the maximum number which is basically the resolution in x. So let's just do if this is for in the uppermost boundary. If it's bigger or equal than the resolution in x, we will keep it equal to the resolution in x. What we're saying is that if we reach that number which is 100 in the x, we reach 100. Make sure that you never go beyond 100. Stay with 100. No matter what plus and minus equation is happening here, you cannot go further from 100. We will do the same thing for the boundary in y. Let's make sure to type those numbers correctly. I like adding comments here, because what we're doing here is boundaries. Sorry, boundaries. There we go. So it's not running. We're having an error. Let's just find that error before we wrap it up here. What I like doing when I find some of these errors is to comment out the lines that I just added. So let's see. The error is not running at that point. Is it here? It's not there either. Is it here? That's the line. So this line has an error. I can see it here. Instead of resolution in x, I typed res_x. So that's why it's always good to double click on your variables. I'm terrible at remembering sometimes the name of the variables. Here we have it. Now we can see that whenever the walker reaches the lower boundary condition, it will stay there. It will never go below that boundary. It's still random. Every time that you run the script, it will run differently. You will get a different pattern. This is actually a form of Brownian motion. It's a form of behavior that is starting to pick adjacent locations next to the entity, and it's moving to one of those locations. We're actually creating this random walker idea. There's a lot more interesting layers of behavior that we could start adding to this. It basically operates as how do we understand the information of the grid that we're in, and how do we actually start moving to an adjacent tile or adjacent cell. It gets a lot more interesting as we start introducing data like the grid itself could be a form of data that we use in order to take decisions on where to move next. I'm going to leave this lesson here and I'll see you in the next video.