Hi, welcome to this fifth video on our wave function collapse project series. We are at the point of starting to learn about propagation. What do we mean by propagation? We are at the point where we have collapsed one cell at random in our grid. This cell needs to look to its adjacent neighbors. We have done calculations such as this one with the Langton's Ant, I think that was in Course two. In many cases we've seen that data structure of a grid lends itself to understand neighborhood calculations in an easy fashion. Similarly, we're going to be using some of that. We're going to write it slightly different just because we're wrapping up and getting towards the very end of the course, we're going to be seeing different ways in which we can access neighborhood information in this case using a dictionary and a tuple. Let's see the kind of structure that we're going to be using. We're going to be using a dictionary that will combine a direction. Direction is going to be, again, top, bottom, left, and right, which talks about the adjacencies of the cell, and then we're going to be coupling that with a tuple, which is going to be the adjacent coordinates in relative space. That means that whatever that cell is a -1. In y, it's going to be our top neighbor. A +1 in y it's going to be our bottom neighbor. A -1 in x, left, +1 in x, right. We're also going to have to learn once we create this matrix of neighbors, how do we loop through these possible neighbors? This is going to be a very interesting structure that could be expanded to all sorts of different types of geometry later down the line. But it's a very different way in which we're going to be looping through this neighbor adjacencies. Let's write it and see how it works. We are continuing where we left off. I'm working within the second tab called Environment. We just wrote in the last video the wave function collapse beginnings of the algorithm. I invite you to add documentation and comments to your own code. We also wrote the collapse cell, which is a rather simple function that selects a random entity. From within here we are going to propagate. Let's just call a function we haven't written yet. We're going to call propagate x and y. We want to make it within this function because we're passing this information x and y to basically the collapse cell will propagate. Let's define the propagate function by self, x, y. What do we need here? I'm going to create some data we'll definitely need, but we're going to stop a bit short of using it. What would be the collapsed tile? The collapse tile we know is the self.cells [x] [y]. Because we're working within the collapse tile, we can select the first entry of that list, which is going to be the only entry available. That's the collapse tile. That's going to be useful for us in a minute. Let's define the possible neighbors of that tile. Neighbors. As we discussed in the intro slides, we are going to be doing a dictionary, where we're going to be using a direction in the form of a string that would be coupled with a tuple x, y. We could do this, x, y, like that first. Repeat this four times. Now we can say bottom, left, and right. Now we can actually identify what are the coordinates. Top, as we discussed, is the y - 1. The bottom would be +1, and left and right. Left is -1 in x, +1 in x for the right neighbor. That's so good. What we haven't done yet in this course is how do we loop through this dictionary and how do we get access to both the direction and the tuple. Let's do a four where we use something we're going to call this temporary variable direction, nx, ny. What we're doing here is giving a placeholder name to the direction. Basically the tuple nx is going to be neighbor x and neighbor y in neighbors. Just want to make sure that we spell it correctly, neighbors.items. This is a function that will allow us to iterate over a dictionary. We know that there is a case on the edges in which we do not want to be checking. We are going to be writing one function. If 0 is smaller or equal than nx and smaller than self.columns and, this is basically ruling out the cases in which nx or ny, the neighbors in relation to the cell wouldn't actually work. We're dealing with the edge cases. Let's just double check that that's correct. Smaller than columns and smaller than rows, so it has to be within zero and the size of our grid. Right now I'm just going to type something like x = 1. This wouldn't run if we don't really have, but the calculation that happens at this point, we're in fact already achieving the propagation. We're evaluating the cell, we're defining the neighbors, and we are going to be checking the adjacent neighbors of the cell. Let's just double check that we're not running into any errors. That's good. But the calculation that would happen here, let's just write it as a comment before now, because we're going to see this in the next video. So update the neighbors. The way we update the neighbors will be done through evaluating the neighbors and saying, am I compatible, is this like let's kill all the non-compatible options of that neighbor. We have to start running the compatibility test between the collapse cell and the neighbor cell. Within this loop we're already propagating, we're already in a loop that's dealing with the adjacent neighbors, and we're going to be writing more logic to understand how do we evaluate this compatibility test between tiles. We're going to be seeing that in the next video. We'll leave this one here. I'll see you then.