Hi. Welcome to this new lesson. We're going to continue working with our project, the Wave Function Collapse project. We're in the middle of working on this propagate function. At this point, what we are meant to do is to evaluate if the cells are compatible with each other. We're going to be talking about neighbor compatibility. What do we mean by neighbor compatibility? As you know, we have been describing the compatibility of a cell with a dictionary that has the top, bottom, left, and right keys basically, and we're using A and B to define what is compatible. Let's look at it in the case of when two cells are in fact compatible, we're going to have a cell on top of another one. If the bottom of a cell has the A level and the top of another cell has also the A level, we'll consider that to be compatible. We're going to do an operation where we're going to do a check of true or false, are those equal? If so, we have compatibility. If that is not the case. If you can see here, if the bottom is A and the top of another cell is B, then it's in fact not compatible. We're going to just give a false. We are going to be writing this function as follows. This is going to be part of the tile. The tile will be able to evaluate if basically a cell, it's in relation to another cell. If the direction that is being given is the top, bottom, left or right, and depending on those conditions, we will be able to define true or false for a compatibility test. Let's write this function together and apply it to the algorithm so that we can actually start reducing the possibility space of the cell from many to what it will become ultimately a collapse cell. We're going to continue working where we left off. We are here. We have our main tab, then we have our grid tab. Let's just expand this a little bit, a bit more space. But first of all, I would like to go to the tile class. Right now, we only have a couple of functions. We have a way of displaying the cell when it's collapsed, when it's not collapsed, and a way of defining color depending on the type of edge, so color by edge. Let's just define another function here, which we're going to call is_compatible. We're going to use self, other, and direction. Direction is going to be a string and other is going to refer to another cell. We're going to say if other is none, return true. This is like a safety measure. Let's just quickly return if that other for some reason is empty, we're just going to say true at this point. That's just to make sure that we're not running into a bug. But let's just actually write the directions first. If direction equals top, we're going to return true or false here. Let's return an evaluation of adjacencies. We will return the current cell, so self.edges. Here, because this is a dictionary, we will select bottom. If our bottom edge is the same then the other edges top, so if those are the same, that's going to be true. If not, false. That's one of the conditions, that's if we are asking for the top of a cell. We're going to be doing this four times. We have direction top, bottom, left, and right. Let's write those one at a time. Bottom, left, and right, and then in the case of bottom, we need to make sure the top, and let's just write that correctly, bottom like that. Bottom. We just basically invert those two. In the left we have right here and left here. Basically, what you're doing is checking the opposite orientation across cells. In case of the right, we will put the right here and the left here. So this is a function and if none of those conditions are true, we can say return false just for good measure as well. So we have the compatibility function written within our cell class. So this is what we were pending. If you remember from last video, we started writing the propagate function here and we reached the point where we would expand a search from one cell to its adjacent neighbors. What is the step that happens after? The adjacent neighbors, we have to check compatibility. So we actually do have a function now that would actually allow us to do that. Let's just remove this placeholder code here, x+1. Let's write self.update_neighbors. This is a function that we haven't written yet. By the way, we will pass some information here which is going to be the neighbor nx, the neighbor ny, and the collapsed_tile, and the direction. All this information we do have. If you look up here, we have the collapsed_tile which is the tile we're evaluating; basically the tile we'll be checking at the center of the neighbor. Then we're looping through the neighbor so we're going to be evaluating all the adjacent neighbors in this loop and with each one of those neighbors, we're passing a direction. We're passing top on the neighbor, bottom on the neighbor, and so on. We're passing all the information that is required for that to be handled by this update neighbor function. So let's write that function together as well because we don't have that function. So update_neighbors. We're going to take self, the neighbor x, the neighbor y; these are going to be basically the same requirements that we provided. Actually I think we actually wrote it. Let's just spell that correctly. I think I was spelling it with a single l by mistake. We will need the collapse style as an argument and the direction. So all of these are the arguments required for this function to work. So let's first of all ask ourselves, what are we doing in this function? What we're doing is checking one of the neighbors and we're going to check if the tiles within that neighbor are in fact compatible with the collapse cell. If they're not, we're going to remove them from the list. So we're going to only end up with tiles that are compatible. Let's say we have two tiles that are not compatible and two tiles that are in fact compatible, we're going to kill the ones that are not compatible. We're reducing the possibility space of that tile to in this case, four to two or four to one, and so on. What are the possible tiles? Let's start with that. On neighbors, neighbor_possibilities. So this is the possibilities of a neighbor. Will be calculated with the self.cell of the neighbor we're evaluating. Remember that the nx and ny stands for the index of our neighbor. Before we would usually use x and y. It's the cell that we're evaluating, but with the nx, we're denoting that it's the neighbor of the cell we're evaluating. Let's say at that point we have access to that neighbor. That neighbor requires or has four possibilities. That's great. We have that. If the length of that possibility, if there's more than one, because if it's only one, it means that the cells collapse and we already have the solution in a way for that. If it's more than one, let's do something. What do we want to do here? We want to loop through each one of the possibilities. Let's just do four tile in neighbor possibilities, and here I'm going to do the same notation that we use before to make a copy of this list as opposed to a reference to it. I just want to make sure that because what we're going to be doing is removing entities from this list, we want to make sure that we're not looking through the list itself but a copy of it. If, note, a tile. Here's where we're going to use the function that we wrote in the tile. Let's copy the name of That's compatible. Which are the arguments that we need to provide? We need to provide the collapsed tile, so that's the cell we're evaluating and the direction. If you remember, this function takes the direction. If it stop, we're basically asking this tile, I'm going to pass you an adjacent tile. Are you compatible in the top, on the bottom, on the left, on the right? We're looping through the different directions and finding if in fact those tiles are compatible to this one. These are the two tiles that are being compared through this function, tile and the collapse tile through the function is compatible. This will return true or false. We're doing it as an if. Saying if it's not compatible, what do we do? Well, from the possibilities we remove the tile. We're saying check this style one at a time. We're looping through all of them. If this style is not compatible, remove it. We're reducing the possibility space of that cell. That's it. I think that's everything. We're basically making sure that every time we do one loop of propagation, we check all the neighbors and we kill the non compatible tiles. That would allow the system to be at a perfect state where we can move to a new cell and start repeating the process. But let's just see if we wrote any errors. Yes, it seems like it. Let's just revise a little bit of our code. Let's just make sure I actually realized that there was a misspelling of cells. I spell cell instead of cells, so make sure that you correct that. I think that now we should be able to have it running. This is what we have. We have one tile collapsed, and now we have some neighbors adjacent to it, we changing the number. This tile on the left has 2, a 2, a 2 and a 3. That's basically what we wanted. We wanted to be able to change the entropy of our neighbors adjacent to it. The compatibility test is in fact working, and we have done one loop of the algorithm. At this point, we will move to select the lowest entropy and repeat the process again. We're close from concluding just because once the algorithm starts looping, it's going to resolve the entire grid. We just need to do one loop and we are good. We're going to continue next video, we're going to see how to move to the lowest entropy point available within the cells. See you in the next video.