[TRAIN HORN]
What's that?
The train is pulling to the station again?
Back for a third part of this A* algorithm ThingamaBob because I
did want to-- what you saw actually in the first part is
visually--
this is a surprise third part, by the way.
I didn't mention it was going to be three parts.
It's fine, though.
It's fine.
It's what it is.
You're watching or you're not watching, that's life.
In the first part, I showed it visually
a little bit different.
And so I'm going to get to there,
and I just want to kind of play around
with the visually a little bit to give you guys
some things to think about.
And I'm hoping that I'll see a lot of you
sharing the 3D versions or other types of visual versions.
So let's see what we can do here.
The first thing that I'm going to look at
is a different way of drawing the path.
So one way that I want to draw the path
is actually by a continuous line.
So I'm going to say begin shape and, oh, begin shape and end
shape.
And I'm going to have this same exact for loop,
but instead of calling that show function that
draws a rectangle, I'm going to add a vertex.
And the vertex needs to be at each path's I times
w and it's j times h.
And we don't want this to have a fill,
and we do want this to have a stroke.
I'm just going to make it white right now,
and we'll see if that comes up.
So let's look at what happens there.
So oops, I don't see that.
Why don't I see that?
Oh, path j.
Shoot.
Always-- I need like a sound effect,
not just for this dot problem but the i versus j, x versus y
problem.
So if we come back and see that, we
can see oops, still not working.
Oh.
Dot j.
Oh, my goodness.
I can't do it anymore.
OK, there you go.
So we can see that I'm drawing a line.
So this is connecting a little bit.
You can see the line, though, is kind of connected
from the edge.
So as it goes across the top or goes across the bottom, which
isn't exactly right, so I also should
consider the line between the center
of each one of these cells, which is adding the height
or width divided by 2.
So now we can see, I'm seeing the path as a line.
Now, there is this kind of issue of should I
be allowed to go between these two?
Right?
This is a valid diagonal step, but is this really
a valid point?
So I think an interesting exercise
for those of you watching would be how do you modify this
so that's not a valid move.
I would have to actually go around that somehow.
I can go diagonally, but not if there are two,
only if this was open as well.
I don't know if it should be or not,
but one way I could visually at least address this
is I could say, if I come back up, sorry,
to the where I'm drawing these, let's make
these actually circles.
And so actually, I'm going to take
the same exact line of code, and I
need to draw the circles based on the center.
And I also could draw their size a bit smaller.
So let's draw all those as points, as circles.
You can sort of see, ah, look.
So there's some strange things going on now the way
that I visualize this.
Really weird things actually.
I shouldn't be allowed to record videos
after a certain amount of time.
OK, so now we can see, and I don't
want to draw the path anymore, I mean the circles
anymore for the path.
So I'm going to take out those.
I also want to make this stroke weight--
let's just make it a little bit wider,
so it's a little bit stronger.
And now what are the white circles?
Why are there white circles?
The only thing that I'm drawing now are the path and the grid.
So I'm showing the grid as white and I'm only--
so everything is white unless it's an obstacle.
It's black.
So what I actually want to do is only draw it
if it's an obstacle.
And I also need the background therefor to be white.
Wow, I really did this in a crazy way.
What's the background now?
The background is-- so and then those are the obstacles.
Now where is the path?
Let's make the path some kind of color.
There we go.
So we can see now that I'm getting
a path that's kind of going or almost looks a bit more
realistic.
I don't know if this is better.
I had something different at the beginning of the video,
but what I might do is make some more obstacles.
Or actually, instead of making more obstacles, what
I might do just to see this a little bit better
is to make a larger grid.
We can see.
So this we could see a bit more about how
you could start to imagine visualizing this pathfinding
thing in a different way.
It almost looks like lightning in this crazy way.
But you could think about, what does
it mean to have autonomous agents following the path?
How would you draw these obstacles in different ways?
What kinds of colors?
You know, what if again I said this before,
but what if the way that you arrange these obstacles is
actually some type of image or a geometric pattern using
Perlin noise or perhaps actually creating an actual maze,
using some of the maze generation algorithm
that you can look at.
And, boy, why didn't it go to the top left that time?
Oh this because this had no solution.
OK, so I think--
I don't know if this third part of the video should actually
anybody should ever actually watch it.
But I guess if you're watching it, then it did happen
and it is online and you watched it.
But, so I should connect obstacles which are connected.
That's a really good idea.
So I'm going to leave that as an exercise for those
of you watching.
I'm making this video just to give you some more thinking
and possible ways about revisualizing
this in a different way.
And I would love to see what you make out of it.
And so thanks for watching.
Coding Train is leaving the station.
[DING]
[UPBEAT JINGLE]