Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,060 --> 00:00:07,200
Now that we have implemented our first pathfinding algorithm breadth first search, let's put it to the
1
2
00:00:07,200 --> 00:00:08,940
test and execute it
2
3
00:00:08,970 --> 00:00:15,000
with a grid. And you can find this example in the attached project for this course, but I'm going to
3
4
00:00:15,000 --> 00:00:16,590
quickly show you how to use it.
4
5
00:00:16,680 --> 00:00:25,350
So you have the left click to put the start position, left click again to put the end position, and with
5
6
00:00:25,350 --> 00:00:30,720
the right click we can specify some walls between our two positions.
6
7
00:00:31,110 --> 00:00:35,100
This will actually make the map harder for the algorithm.
7
8
00:00:35,760 --> 00:00:45,570
And if we click execute, then we can get a step by step path from the origin to the final position.
8
9
00:00:45,900 --> 00:00:53,520
Now, let's see if we put the start position and the end position and execute the algorithm step by
9
10
00:00:53,520 --> 00:00:53,880
step.
10
11
00:00:53,910 --> 00:00:58,110
So the first step is actually to check the direction above.
11
12
00:00:58,110 --> 00:00:59,250
So we'll see.
12
13
00:00:59,250 --> 00:01:03,690
The next position is labeled two because we need two steps to go here.
13
14
00:01:03,780 --> 00:01:08,850
And in our queue we have [1, 2], which is this one.
14
15
00:01:08,850 --> 00:01:10,140
It's line one and two.
15
16
00:01:11,370 --> 00:01:15,480
Please note that the first line is zero and the first column is also zero.
16
17
00:01:16,560 --> 00:01:19,980
If we click next step again, then the right position was checked.
17
18
00:01:19,980 --> 00:01:22,650
But it's a wall, so nothing to do here.
18
19
00:01:23,070 --> 00:01:24,930
The next one would be down.
19
20
00:01:24,930 --> 00:01:30,660
So another wall, nothing to do here but the left position in this case, it's okay.
20
21
00:01:30,670 --> 00:01:34,860
So this would be added to the queue as well as the step number would be updated
21
22
00:01:35,070 --> 00:01:35,940
with two. Now,
22
23
00:01:35,940 --> 00:01:41,070
if we proceed, the first one to get out of the queue would be [1, 2], which is this one and we'll
23
24
00:01:41,070 --> 00:01:47,220
check top, left, down, which is already parsed so we don't count that and left.
24
25
00:01:47,310 --> 00:01:48,120
Let's do it.
25
26
00:01:57,030 --> 00:02:01,020
As you see this position ended because there's no way to continue.
26
27
00:02:01,350 --> 00:02:04,590
So the algorithm will just continue with this and this.
27
28
00:02:17,700 --> 00:02:20,880
And boom, now we have the end position.
28
29
00:02:21,270 --> 00:02:24,240
So this is how breadth first search works.
29
30
00:02:24,450 --> 00:02:31,950
Of course, it is good to keep in mind that this is the first step because we need to recreate the path
30
31
00:02:32,040 --> 00:02:33,450
and to recreate the path.
31
32
00:02:33,840 --> 00:02:38,040
We use the recursive function that we discussed in the previous section.
3222
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.