In the previous cooling session, we developed a graph class to store our math.
Now we will utilize it to create a graph representation for our maize.
For this, we move inside the initialization function of our board member class where we create a new
instance variable that we name as crop and we initialize this to the object of the graph class, thus
providing us access to the graph class from inside the board member class.
Next, we create or define a set of state variables that are connected to their connected, uplift up
and upright.
Basically the for direction any node might be connected to to its neighbor nodes.
So as this is the initializing point, all these particular boolean variables have been initialized
to false.
But if a particular note is connected to its neighbor node in any one of these directions, then they
will be set to true respectively.
Now we need to define the function that actually performs the task.
Now, if you define the function that actually performs the task of connection of each node to its neighbors.
So that function is known as connect neighbors.
So what this function will do is takes these arguments that is, makes no drawing node column representing
the current node.
Then we have the case for that particular node.
Then we have the step and step up representing how many steps have taken in a particular left sort of
direction.
For example, one represents one pixel to the left direction for step out and for the total character
basically represents how many nodes have been connected to a node as this is the initialization point
and we are defining the function, it hasn't been defined to be zero at this point.
Now we define this particular function where we start by defining the note that is basically tuple.
Of consisting of not rule and not column.
Then we start by looking for a path in one of the four directions that is left.
Then top left.
Then top and then top right.
So in this way, we are going to find a neighbor in one of these direction for each note.
So starting off, we start by looking in the maze.
All right.
Ignored route minus.
Step up the note column when it's simpler and if it is greater than zero, then that means that we have
found a path and now we need to find a node in that particular path and connect to it.
So it is a probable neighbor node right here.
And what it would be equal to is basically a tuple that is no draw minus step up note column.
Minus step left.
And this probable note we need to check whether this note exists or not at this particular point, and
that can be done by calling the neighbor node in self node graph, not graph that.
Keith So if it is part of the keys for the graph, then that node is part of the graph.
Then all we need to do is simply connect the current node to our neighbor node, and for that we need
to require information about our neighbor node and that can be accessed by simply writing.
We first need to extract the neighbors case so the neighbors case can be simply extracted by start calling
the sales dot graph.
And graph again and then passing in the neighbor node.
As the key and then the key of this dictionary for the neighbor.
Note It falls in the case.
So we accessed the case for the neighbor.
Note And then to extract the cost of traversing from the current nor the neighbor note all we need to
do is simply write the max value between the absolute of the step left.
And absolute of the step up.
So this provides us the cost of traversing between the neighbor node and the current node or the current
node, put it or not.
So they are interchangeable.
Now, once we have this information, we simply increment the total increment connected by one.
So we have found a connection to the from the current node, the neighbor node.
So we have found one connection.
So the total connected has been incremented by one.
Now all we need to do is simply create the connection.
And that can be done by simply calling a graph object and then calling our vertex function.
So we provide the vertex that is current node and then the neighbor node.
And then for the kids, as we're connecting to the neighbor, you'll we providing the neighbors case
and then we providing the cost in the same way reconnected back by providing the neighbor with.
And connecting it to the crime scene and for the Casey files in the case and for the courts to pass
in the courts now that they have done this connection between the cardinal and the neighbor, knowing
that you just going to present it to the user and that can be done by writing a nice little print or
just a space to the user.
And this connection has been done in a special direction.
So we don't know in which direction.
So we are going to look in all of those directions to see which was the connection that has been just
been done.
So this is following the specific cycle, as I mentioned before, that is start looking in the left
direction if a note is found, look connected to that.
Otherwise look in the opposite direction next to this phone and look in connected with that and then
look up direction and then in the upper right direction.
So this is how the cycle votes.
So we are going to do exactly that.
And simply check whether if you have not already connected to the left, then this means this connection
was to the left.
So the first thing that we need to do is to display this connection to the user.
And that can be done by simply calling a function that is displaying connected notes.
We have not define this function, so let's define this function right here.
So we define this function right here.
And what this function does is simply it takes the current node, takes the neighbor node, and draws
a line on the Miss Connect.
This is the variable.
This is the first hole that will be created later on to simply display the connection between each and
its neighbors.
So we call this particular function to display the connections.
And then because we are not we have not connected to left before.
And there was a connection that this indicates that we have connected to the left now.
So we need to set this group and then we need to look in the next election in the cycle, and that is
up there.
And that can be done by sending the step left one and step up to one.
So once we have done this, we have updated the step left and step up.
Then the next thing that we need to do is to simply call the connect neighbors function.
So what this function does is simply recursively call the connect neighbor functions.
Now that we have opted into, step there and step up variables.
And what this updated thing does, it simply says that now we are connected to the left direction.
Look in the upper left direction because we are looking one pixel two and pixel two dot.
So we need to add a few more parameters.
That is the operative step right here and ability to step up and the total connected.
Now, once you've done this to address all the rest of the cases, there is uplift up.
Just like this.
So what we're doing is similar to what we did in the previous case.
That is for the uplift we look.
If we are not connected to the uplift, we display that connection by writing uplift right here and
then exiting that uplift connected uplift boolean to true starting this step lift and step up to zero
one, basically indicating that now look in the other direction and then calling that connect neighbors
again the same way we go up all of the upright function operate boolean where we simply said this to
true and not call the connect name but it's function.
This is because we have completed the cycle and all the connection has been done.
So now we address this condition.
We are to address the condition.
What would happen if the neighbor node was not found in the can?
Step there a step up that we were looking at.
So we are already on a path and if we have not found the node in that particular path, then that means
we need to look a little more in that direction and that can be done by simply implementing whatever
the step, left step of was before.
So for example, to check with the first check whether we have completed the cycle that that was necessary
for us and that means, if not certain, connected upright, then the cycle has not been completed.
We are still looking to connect to its neighbors.
So we start again from the start by looking at the self not connected left.
So we see that if we are looking in the path and we were looking in a particular direction that was
left, so we were looking in the left direction and we haven't found the node, but there was a path
there.
Then the north should be a little more to the left and that can be done by simply incrementing the step
left.
One.
One pixel more to the left.
And we try to find our dear assembly.
We address the rest of the cases where if we are looking if we are looking in the upper left, then
we need to look a little more up there.
We're looking to look up.
We need to look a little more up.
And if we look upright, we need to look a little more upright.
And for the upright instead difference, the step left of step left is not incremented because it either
decrement because minus minus gives this step there positive.
And then we call the connect neighbors recursively basically start looking a little more in that particular
direction to connect to the neighbor node if found now, now that we've addressed all these cases,
we address the case.
What would happen if the direction that we are looking does not contain a but that means no, it is
there.
We need to look in the next election in our cycle.
So we need to address that case and that can be done.
This ls right here.
So the direction that you were looking is was not a path.
So for that else case, we need to start looking from the start and that is if not self not connected
left.
So the first direction, the cycle, what we need to do is simply say the sender connected left is true.
So don't look in the left direction anymore because we haven't found it.
That part's blocked.
So we update the step left to one and step up to one.
We basically say to the goal to simply loop in the opposite direction and then we call the connect.
Neighbors function once more and provided the new primitives of step left and step up and a total connected.
And once we have done this to address all the other cases that might come and that are up, left up
and upright.
So finally, when we get to the upright, we said that to upright or true, this was the last of action,
the cycle.
We reset the step there and step up to zero and simply return the function.
This completes the function definition.
And now we can simply utilize this function inside the One Path algorithm.
So instead of one path algorithm, the very first thing that we need to do is to simply call that graph
or the graph object and call the graph dictionary inside of it and simply clear it so that whenever
we call this one false function, it does not start filling it in the previous dictionary.
So this gets cleared whenever this one passed functions your scope.
The next thing that we need to do is to simply create the disconnect that we were talking about earlier.
This is basically the variable or the image which will display the connection from each node to its
neighbor nodes.
And then we simply create a few counters that are the count of the number of times that be a phone,
number of three junctions, a number of four junctions that we have.
And because we have created a miss connect or an instance variable, Obama is going to to initialize
this inside.
Our initialize and function.
So right here we initialize them is connect.
So this is we have initialize this to an empty list.
Now we move inside.
The iterative loop that we were doing to loop over our in time is right after we have found a particular
part.
What we need to do is to simply really slice.
Our myths connect to the gray or BGR myth.
So basically, if we are debugging the mapping, we are going to display the individual connection of
each node to its neighbor nodes.
So this is just for debugging.
Then after we have found the start and end, we need to add the start and end to the graph now.
So instead of just displaying them in the form for nice looking colors, we now add them to the graph.
And that can be done by simply going.
The graph.
And add vertex and vertex passing information, that is.
The tuple that is row and column.
And for the neighbor, we have no neighbors.
We are simply adding this particular vertex that is a current vertex and we pass in the case.
That is because this this was formed as a start.
So the case is basically.
Start.
Represented.
This is the start.
And then if we have the costs, we don't have the cost.
And then we simply update the graph information of the start that this is the start and by writing the
tuple after four column.
So basically we now have updated that we have found the start of the graph that is the role column at
this particular moment and the ROIs zero.
And we have added this particular node to the graph and we have named it name this node or named the
case of the node as start.
We do the same process for the end node when we have found it, so that can be done by system graph
added vertex.
Your boss in the win column as the vertex.
And then for the case.
We're right here.
That this is the end.
So.
And here we also need to write here that this was the case.
So once we have done this, we need to also update the instance variable of graph that was the and as
we have found.
And so we need to simply say that this particular row and column that we are on right now is the end.
Now for the end.
And from this point onwards, we need to also perform the connection from our current note to its neighbor
note because for the start we could not connected to anywhere because the the cycle that we were looking
for, for any neighbor notes, does not exist for the start note as it is on the first row.
So the cycle was looking left direction.
Look in the top left direction, look in the top and look in the top, right.
So none of these conditions occur for the start note so we don't connected to any and they were not
but for the end or we can do that so we simply right here so that connect neighbors.
And that can be done by simply passing in the midst.
For the no rule, you passing the rule for the note column you pass in the column and for the kids in
Boston that this is the end.
So once we pass this information.
And once they passed the information, they basically called to connect this and vertex to all of the
neighbor vertex that might come in any of the four directions that we mentioned before.
So in this way, we connect our end vertex to all of its neighbors.
So one thing that we need to do before this particular function is to simply call another function that
is self-talk graph, but self-talk.
Reset or reset?
Connect parameters.
This function will get called right here.
This basically resets the connection parameters or the state variables that represents the connection
for each particular node.
So these needs to be reset for every time we want to connect a particular node to its neighbors.
So this needs to be called every time we want to connect to particular Northwest neighbors.
So these are the two things that we need to perform.
The same way we look for the dating after we have found a dating.
So what we need to do, we need to add that different or note to the graph.
We're writing at Vertex for the Vertex three path in the row and column and for the case you pass in
that this is a dead end.
So once we have mentioned this information, we need to reset, reset the correction parameters and
then call.
To connect neighbors.
We need to connect this dating to its neighbors and that can be simply be done by setting the miss.
And that in order to grow and passing the column as not going and for the kids we passing.
The case of this particular note that is it said there that.
So once you've done this, you basically perform all the connections for any dating that we might come
across.
And then we need to address the same case for the tenants.
So once we have found the tone.
So once we have found a tone, we do the exact same thing and add the words.
Writing the ruined column say that that case was stones.
And we just said the connect barometers.
And we connect the neighbors to these stones.
And then we increment the tone counter.
So basically, we now know that how many stones that we have in our particular mix.
And then we do the same for the three junction.
The same exact same thing that is adding that note the vertex saying that that is the tree junction
connecting it to its neighbors after resetting the connection perimeters, updating the junctions,
three junction that we have found, and the same for the four junction.
And then finally printing the tones, the three junctions and the full junction that we have found in
our growth.
So this completes our whole mapping process, and now we can simply test this out to see whether this
performs in the way that we wanted to build in.
Thank you and bye.