1
00:00:05,190 --> 00:00:07,930
Hi, welcome to this new video.

2
00:00:07,930 --> 00:00:10,750
In this lesson, we are
going to finally start

3
00:00:10,750 --> 00:00:14,290
addressing the final
script of the second week,

4
00:00:14,290 --> 00:00:16,750
which is the Langton's
ant algorithm.

5
00:00:16,750 --> 00:00:18,950
I'm a big fan of this algorithm.

6
00:00:18,950 --> 00:00:21,290
It's the way I learn how to deal

7
00:00:21,290 --> 00:00:23,710
with the data
structure of grids and

8
00:00:23,710 --> 00:00:25,630
really start
understanding principles

9
00:00:25,630 --> 00:00:28,695
of generative design,

10
00:00:28,695 --> 00:00:32,330
how you could actually create
emerging systems between

11
00:00:32,330 --> 00:00:36,430
a simple interaction between
a grid and a walker agent,

12
00:00:36,430 --> 00:00:38,470
something that moves around.

13
00:00:38,470 --> 00:00:40,880
Let's talk a little bit about
what the algorithm does.

14
00:00:40,880 --> 00:00:44,690
We have an entity that
is situated in a grid.

15
00:00:44,690 --> 00:00:46,710
The grid has a bit of data,

16
00:00:46,710 --> 00:00:50,430
so we can actually have
cells being black or white,

17
00:00:50,430 --> 00:00:54,340
represented by 0 and 1 in
the data that they contain.

18
00:00:54,430 --> 00:00:58,510
This walker, as we've been
talking, has a direction.

19
00:00:58,510 --> 00:01:00,865
It has an orientation.

20
00:01:00,865 --> 00:01:03,230
If we say move forward,

21
00:01:03,230 --> 00:01:05,230
it would move along the axis

22
00:01:05,230 --> 00:01:08,260
of what we consider
a forward direction.

23
00:01:08,260 --> 00:01:11,625
You can see here we
can also rotate.

24
00:01:11,625 --> 00:01:14,150
What we will actually
write is a function is

25
00:01:14,150 --> 00:01:18,010
rotate clockwise
and move forward,

26
00:01:18,010 --> 00:01:19,690
which are going to be
two different functions.

27
00:01:19,690 --> 00:01:21,990
One that allows us to rotate
the direction of the agent,

28
00:01:21,990 --> 00:01:25,300
and another one that would
allow us to move forward.

29
00:01:25,300 --> 00:01:27,780
The other function
which we have already

30
00:01:27,780 --> 00:01:30,200
been writing is the flip cell,

31
00:01:30,200 --> 00:01:33,520
the capacity for
the agent to change

32
00:01:33,520 --> 00:01:39,480
the information of the grid
in which it's sitting.

33
00:01:39,480 --> 00:01:42,260
These are kind of
basically the moves.

34
00:01:42,260 --> 00:01:44,800
We're going to start this
first video creating

35
00:01:44,800 --> 00:01:47,140
some functions of
the possible moves

36
00:01:47,140 --> 00:01:49,180
that this agent
will be able to do.

37
00:01:49,180 --> 00:01:51,340
We're going to understand
what those moves could be,

38
00:01:51,340 --> 00:01:52,900
and then we're going
to start putting them

39
00:01:52,900 --> 00:01:55,140
together into a pattern.

40
00:01:55,140 --> 00:01:57,820
A sequence of moves
that actually creates

41
00:01:57,820 --> 00:01:59,780
a very specific pattern

42
00:01:59,780 --> 00:02:04,180
and what we would actually
call the Langton's ant.

43
00:02:04,190 --> 00:02:07,005
Let's just jump into it.

44
00:02:07,005 --> 00:02:09,140
I'm going to continue from

45
00:02:09,140 --> 00:02:12,885
this script that we
left in last session.

46
00:02:12,885 --> 00:02:14,680
Let's just make sure that we are

47
00:02:14,680 --> 00:02:16,800
all in the same page. This
is where we left off.

48
00:02:16,800 --> 00:02:19,890
We have a random
walker that it's kind

49
00:02:19,890 --> 00:02:24,240
of flipping the information
of a grid in the background.

50
00:02:24,240 --> 00:02:27,470
We have a grid made out
of black and white cells.

51
00:02:27,470 --> 00:02:29,930
We can initiate that
information at random,

52
00:02:29,930 --> 00:02:32,650
but we're currently
initiating that information.

53
00:02:32,650 --> 00:02:35,110
If you remember at the
very end of the lesson,

54
00:02:35,110 --> 00:02:37,470
we actually turned off this line

55
00:02:37,470 --> 00:02:41,510
here that would initiate all
the information at random,

56
00:02:41,510 --> 00:02:43,530
and we replaced it with
a zero so that we could

57
00:02:43,530 --> 00:02:46,270
actually start with
all the cells black.

58
00:02:46,270 --> 00:02:50,495
Therefore the agent
starts printing in a way,

59
00:02:50,495 --> 00:02:53,490
white cells as it moves.

60
00:02:53,490 --> 00:02:56,690
We have an area here
which has to do

61
00:02:56,690 --> 00:03:00,095
with redrawing of the
cell, separate frame.

62
00:03:00,095 --> 00:03:03,850
Finally, the area in
which we have our walker.

63
00:03:03,850 --> 00:03:08,350
The main bit here, the walking
behavior has to do with

64
00:03:08,350 --> 00:03:12,390
the area in which we are
adding a random movement.

65
00:03:12,390 --> 00:03:15,285
This is what it's going to
be replaced in our case.

66
00:03:15,285 --> 00:03:19,365
Currently, this is the
movement of our walker.

67
00:03:19,365 --> 00:03:22,030
Let's just comment that out
because we want to make sure

68
00:03:22,030 --> 00:03:24,350
that our walker doesn't move

69
00:03:24,350 --> 00:03:25,370
anymore and we're going to

70
00:03:25,370 --> 00:03:28,030
introduce new forms of walking.

71
00:03:28,250 --> 00:03:32,570
If you wanted to run it
here, nothing should happen.

72
00:03:32,570 --> 00:03:36,730
You shouldn't move. This
is a boundary condition.

73
00:03:36,730 --> 00:03:40,510
We also don't need these lines.

74
00:03:40,510 --> 00:03:44,470
We can delete that. There we go.

75
00:03:46,380 --> 00:03:52,500
This is the information of
the flipping of the cell.

76
00:03:52,500 --> 00:03:54,040
We are going to start breaking

77
00:03:54,040 --> 00:03:56,505
these blocks into functions.

78
00:03:56,505 --> 00:03:58,800
So we're going to be a
little bit more clear

79
00:03:58,800 --> 00:04:01,130
of how we are moving the agent.

80
00:04:01,130 --> 00:04:05,790
Finally, this is the area in
which we draw the walker.

81
00:04:05,790 --> 00:04:08,180
Let's go all the way to
the top of the script

82
00:04:08,180 --> 00:04:11,540
and define a new variable.

83
00:04:11,580 --> 00:04:14,060
This variable is
going to represent

84
00:04:14,060 --> 00:04:15,730
the direction of the agent.

85
00:04:15,730 --> 00:04:18,170
I'm going to use an integer,

86
00:04:18,640 --> 00:04:21,040
I'm going to call it direction,

87
00:04:21,040 --> 00:04:22,400
and it's going to be zero.

88
00:04:22,400 --> 00:04:25,080
If you remember a little bit

89
00:04:25,080 --> 00:04:27,655
of what we've been
discussing in prior lessons,

90
00:04:27,655 --> 00:04:32,085
this direction, it's
going to be either 0,

91
00:04:32,085 --> 00:04:34,185
or 1, or 2, or 3.

92
00:04:34,185 --> 00:04:37,180
That's going to represent
the four cardinal directions

93
00:04:37,180 --> 00:04:39,925
in which this agent
will be able to move.

94
00:04:39,925 --> 00:04:44,840
This algorithm works with
these four orientations.

95
00:04:45,530 --> 00:04:48,765
Now we have a direction. Let's
visualize that direction.

96
00:04:48,765 --> 00:04:50,490
Let's just go all the way to

97
00:04:50,490 --> 00:04:52,680
the bottom here when
we're actually drawing

98
00:04:52,680 --> 00:04:57,120
the agent and let's
just do a bit of logic

99
00:04:57,120 --> 00:05:00,690
or some representation that

100
00:05:00,690 --> 00:05:03,030
would allow us to
draw the direction.

101
00:05:03,030 --> 00:05:04,905
Where do we want to
draw the direction as?

102
00:05:04,905 --> 00:05:06,945
We want to draw the
direction as a line?

103
00:05:06,945 --> 00:05:10,510
We could say something
like a line.

104
00:05:10,520 --> 00:05:16,170
That goes from the position.

105
00:05:16,170 --> 00:05:23,130
A line it's a primitive that
requires 4 pieces of data,

106
00:05:23,130 --> 00:05:24,180
two points basically,

107
00:05:24,180 --> 00:05:25,590
if we're doing a 2D line.

108
00:05:25,590 --> 00:05:27,960
We need the position of
the agent in x and in

109
00:05:27,960 --> 00:05:34,290
y and we need to
provide a distance.

110
00:05:34,290 --> 00:05:38,610
We will use the
same position in x,

111
00:05:38,610 --> 00:05:43,305
but we're going to give it a
little bit of maybe plus 20,

112
00:05:43,305 --> 00:05:51,780
some amount of distance and a
position in y just like so.

113
00:05:51,780 --> 00:05:54,765
We're going to draw a
line in the x-axis.

114
00:05:54,765 --> 00:05:58,125
For the second point
in x, we add 20.

115
00:05:58,125 --> 00:05:59,910
That means that the
line is just going

116
00:05:59,910 --> 00:06:02,475
to be flat horizontally,

117
00:06:02,475 --> 00:06:06,220
and that should
represent our direction.

118
00:06:07,460 --> 00:06:13,720
We're going to actually
use a stroke to be red.

119
00:06:14,270 --> 00:06:17,590
Let's just do a little bit of

120
00:06:19,460 --> 00:06:24,910
the stroke weight to
be slightly stronger.

121
00:06:26,150 --> 00:06:28,755
We could parameterize.

122
00:06:28,755 --> 00:06:30,840
This Number 20 is something

123
00:06:30,840 --> 00:06:33,225
that we could make
a variable here.

124
00:06:33,225 --> 00:06:37,890
Let's call it the arrow size

125
00:06:37,890 --> 00:06:39,570
because we're going to be using

126
00:06:39,570 --> 00:06:44,640
this variable a few times.

127
00:06:44,640 --> 00:06:48,220
Let's see what we're
getting at this point.

128
00:06:48,320 --> 00:06:53,085
You see the agent is not moving,

129
00:06:53,085 --> 00:06:55,845
but we could actually
see the dot and a line

130
00:06:55,845 --> 00:07:00,430
20 pixels to the
right in red color.

131
00:07:00,830 --> 00:07:04,230
That's certainly showing us

132
00:07:04,230 --> 00:07:05,730
a little bit of the
information that

133
00:07:05,730 --> 00:07:11,970
the agent will need for
demonstrating its direction.

134
00:07:11,970 --> 00:07:13,950
But if we actually
change the direction,

135
00:07:13,950 --> 00:07:15,705
the direction
currently it's zero.

136
00:07:15,705 --> 00:07:17,550
If we change the direction,

137
00:07:17,550 --> 00:07:20,160
this arrow wouldn't change.

138
00:07:20,160 --> 00:07:22,755
The line wouldn't change
under this formula.

139
00:07:22,755 --> 00:07:24,570
Let's just create
an if statement or

140
00:07:24,570 --> 00:07:26,490
a condition by which
we could say something

141
00:07:26,490 --> 00:07:29,380
like if the direction

142
00:07:33,530 --> 00:07:39,100
is zero, let's draw this line.

143
00:07:39,110 --> 00:07:42,030
This line is only
going to be drawn in

144
00:07:42,030 --> 00:07:45,030
this way if the
direction is zero.

145
00:07:45,030 --> 00:07:49,540
Let's again, double check
that. That's the case.

146
00:07:50,000 --> 00:07:54,150
Now we have one condition
if the direction is zero.

147
00:07:54,150 --> 00:07:56,535
We know that the direction
could actually be 1,

148
00:07:56,535 --> 00:07:58,230
2, 3, or 4.

149
00:07:58,230 --> 00:08:02,520
Let's just copy this
line a handful of times,

150
00:08:02,520 --> 00:08:05,610
four times
specifically and let's

151
00:08:05,610 --> 00:08:08,535
just change the number
here to Direction 1,

152
00:08:08,535 --> 00:08:11,590
Direction 2, Direction 3.

153
00:08:12,020 --> 00:08:16,035
Basically, every time
that we draw this line,

154
00:08:16,035 --> 00:08:19,590
there's going to be a
slightly different place

155
00:08:19,590 --> 00:08:22,125
where we have to
locate the arrow size.

156
00:08:22,125 --> 00:08:25,740
In the case of the Direction 1,

157
00:08:25,740 --> 00:08:30,375
we are going to move
the arrow size here.

158
00:08:30,375 --> 00:08:33,060
Because this is going
to be facing downwards.

159
00:08:33,060 --> 00:08:35,770
The position in y,

160
00:08:36,890 --> 00:08:41,100
the size is going to
be facing downwards.

161
00:08:41,100 --> 00:08:43,440
Let's just do it for

162
00:08:43,440 --> 00:08:47,145
the position when we're
looking to the left.

163
00:08:47,145 --> 00:08:50,550
That's in the same location
that we had it initially.

164
00:08:50,550 --> 00:08:51,930
But instead of being a positive,

165
00:08:51,930 --> 00:08:52,890
it's going to be a negative.

166
00:08:52,890 --> 00:08:55,215
We're going to say
minus arrow size.

167
00:08:55,215 --> 00:08:58,905
Finally we are going to
get rid of this line here.

168
00:08:58,905 --> 00:09:00,840
We're going to do
the same thing for

169
00:09:00,840 --> 00:09:04,605
D. Final direction, which is up,

170
00:09:04,605 --> 00:09:06,840
we're going to have
the arrow size

171
00:09:06,840 --> 00:09:13,275
facing up by using the negative
size of the arrow side.

172
00:09:13,275 --> 00:09:15,255
If we're looking to the right,

173
00:09:15,255 --> 00:09:16,830
we have 20 pixels to the right.

174
00:09:16,830 --> 00:09:18,375
If we are down,

175
00:09:18,375 --> 00:09:21,810
we have 20 pixels down
because the processing

176
00:09:21,810 --> 00:09:25,950
counts positive
numbers as we go down.

177
00:09:25,950 --> 00:09:28,320
Then if we are
looking to the left,

178
00:09:28,320 --> 00:09:30,150
we have the arrow on
the left and so on,

179
00:09:30,150 --> 00:09:32,210
and we have finally
the direction

180
00:09:32,210 --> 00:09:35,760
Three. We have all the
possible directions

181
00:09:35,760 --> 00:09:37,290
as something that
we can represent.

182
00:09:37,290 --> 00:09:39,020
But there's nothing
at this point

183
00:09:39,020 --> 00:09:44,180
changing the way in
which our agent rotates.

184
00:09:44,180 --> 00:09:47,105
We want to start doing
functions for this,

185
00:09:47,105 --> 00:09:48,645
because as you can
start understanding,

186
00:09:48,645 --> 00:09:52,955
this is where our scripts
really start becoming long,

187
00:09:52,955 --> 00:09:54,970
and it's not really a
good practice for us

188
00:09:54,970 --> 00:09:57,845
to keep writing code
within these structures,

189
00:09:57,845 --> 00:10:00,100
so we're going to
start learning how to

190
00:10:00,100 --> 00:10:02,790
implement some of
the knowledge that

191
00:10:02,790 --> 00:10:05,630
we've already acquired
through Pros sessions,

192
00:10:05,630 --> 00:10:10,410
put it to exercise,
creating some functions.

193
00:10:10,410 --> 00:10:12,860
What would be a rotate function?

194
00:10:12,860 --> 00:10:16,330
Let's just write first our
first rotate function.

195
00:10:16,330 --> 00:10:23,095
Let's define that as
a rotate_clockwise,

196
00:10:23,095 --> 00:10:24,760
because we could actually do

197
00:10:24,760 --> 00:10:30,620
an anti-clock or
counterclockwise rotation.

198
00:10:30,620 --> 00:10:33,815
I'm going to also say of 90,

199
00:10:33,815 --> 00:10:36,675
because the rotation, again,

200
00:10:36,675 --> 00:10:38,375
we could use a parameter,

201
00:10:38,375 --> 00:10:40,410
but because this agent

202
00:10:40,410 --> 00:10:41,800
specifically can only rotate

203
00:10:41,800 --> 00:10:43,615
between four
cardinal directions,

204
00:10:43,615 --> 00:10:46,085
we're just going to
be very explicit with

205
00:10:46,085 --> 00:10:50,690
the naming of this function.

206
00:10:50,690 --> 00:10:57,590
Let's use the global
int_direction,

207
00:10:57,590 --> 00:10:59,680
which is the variable
that we're going to

208
00:10:59,680 --> 00:11:02,575
be transforming or
affecting here,

209
00:11:02,575 --> 00:11:04,670
and we are going to say

210
00:11:04,670 --> 00:11:08,990
that whenever this
function is invoked.

211
00:11:09,530 --> 00:11:14,035
If the current indirection

212
00:11:14,035 --> 00:11:16,220
or let's just say the statement,

213
00:11:16,220 --> 00:11:22,160
if the indirection equals 0,

214
00:11:22,160 --> 00:11:26,090
the direction becomes a 1.

215
00:11:26,090 --> 00:11:28,720
It's a very
straightforward function,

216
00:11:28,720 --> 00:11:32,600
but it's basically quite
effective in this case.

217
00:11:32,600 --> 00:11:34,620
We are making sure that
if this direction is

218
00:11:34,620 --> 00:11:36,820
0 and we invoke this function,

219
00:11:36,820 --> 00:11:38,065
it's going to be now 1.

220
00:11:38,065 --> 00:11:40,365
Let's do an L if statement.

221
00:11:40,365 --> 00:11:41,985
Just make sure
that this actually

222
00:11:41,985 --> 00:11:45,255
checks all the four possible
conditions that we have.

223
00:11:45,255 --> 00:11:47,720
This cannot be an if by itself.

224
00:11:47,720 --> 00:11:49,455
If you do an if, you would

225
00:11:49,455 --> 00:11:51,910
cascade from one statement
to the next one,

226
00:11:51,910 --> 00:11:53,165
and that's not what you want.

227
00:11:53,165 --> 00:11:56,535
You need to do it as
an L if statement.

228
00:11:56,535 --> 00:12:01,985
When if is a 1,

229
00:12:01,985 --> 00:12:04,240
it should become 2.

230
00:12:04,240 --> 00:12:08,890
Let's just do one more of those,

231
00:12:09,720 --> 00:12:12,095
actually two more of those.

232
00:12:12,095 --> 00:12:14,910
Those are all the different
versions just to make

233
00:12:14,910 --> 00:12:17,800
sure that we have all the
different information here.

234
00:12:17,800 --> 00:12:18,985
If it's a 2,

235
00:12:18,985 --> 00:12:20,765
this will become a 3,

236
00:12:20,765 --> 00:12:22,220
and if it's a 3,

237
00:12:22,220 --> 00:12:26,485
it will become a 4.
This is a function.

238
00:12:26,485 --> 00:12:30,005
The function takes the
current direction,

239
00:12:30,005 --> 00:12:33,305
and it will change it with
a 90 degree rotation.

240
00:12:33,305 --> 00:12:35,510
Which is just basically,

241
00:12:35,690 --> 00:12:38,135
perhaps a quite a long way

242
00:12:38,135 --> 00:12:40,205
but very explicit way of saying,

243
00:12:40,205 --> 00:12:42,890
hey, we're going to
rotate in 90 degrees.

244
00:12:42,990 --> 00:12:45,320
What other function do we want?

245
00:12:45,320 --> 00:12:48,590
The other function that
we want to draw here is,

246
00:12:48,590 --> 00:12:53,440
before we were doing a function
that would move randomly.

247
00:12:53,440 --> 00:12:55,825
Let's think of a function,

248
00:12:55,825 --> 00:12:58,845
what would it be
to move forward.

249
00:12:58,845 --> 00:13:00,900
Move forward means that I move

250
00:13:00,900 --> 00:13:03,395
along the axis of my direction.

251
00:13:03,395 --> 00:13:08,120
Let's define a function
that we're going to move

252
00:13:08,120 --> 00:13:14,830
forward and we are going
to provide a direction.

253
00:13:16,230 --> 00:13:19,120
We're going to provide an
argument which is going to

254
00:13:19,120 --> 00:13:21,530
be the direction which
we're going to evaluate.

255
00:13:21,530 --> 00:13:24,670
Let's just affect the
values that we want

256
00:13:24,670 --> 00:13:27,600
to affect or change.

257
00:13:27,600 --> 00:13:32,730
Is the global, basically
these number is here,

258
00:13:32,730 --> 00:13:43,010
the index in x and
the index in y.

259
00:13:43,380 --> 00:13:46,835
These are the values that

260
00:13:46,835 --> 00:13:50,330
represent where the walker
is located in the grid.

261
00:13:50,330 --> 00:13:53,605
If I'm facing to the right,

262
00:13:53,605 --> 00:13:57,920
I want to move to the
cell on the right.

263
00:13:57,920 --> 00:13:59,955
Let's just evaluate.

264
00:13:59,955 --> 00:14:04,660
The direction passes the
argument direction here.

265
00:14:04,880 --> 00:14:07,630
Check if that is 0,

266
00:14:07,630 --> 00:14:13,015
that means that we are in
moving to the right state.

267
00:14:13,015 --> 00:14:16,635
What we want to say is
that, in that condition,

268
00:14:16,635 --> 00:14:23,180
the index of the
cell plus equals 1.

269
00:14:23,180 --> 00:14:25,510
Again, it's a very
straightforward thing,

270
00:14:25,510 --> 00:14:27,610
but if we're adding
these conditionals,

271
00:14:27,610 --> 00:14:29,125
if statements to check,

272
00:14:29,125 --> 00:14:32,000
if I'm looking
towards the right,

273
00:14:32,000 --> 00:14:35,335
I'm going to change my
value in this direction.

274
00:14:35,335 --> 00:14:40,190
Let's add an elif statement

275
00:14:40,190 --> 00:14:44,555
if the direction is equals to 1.

276
00:14:44,555 --> 00:14:48,335
Remember that, what
I'm using here,

277
00:14:48,335 --> 00:14:52,145
the value there for direction,

278
00:14:52,145 --> 00:14:55,130
represents the current direction

279
00:14:55,130 --> 00:14:57,005
that is going to be passed
on in this function.

280
00:14:57,005 --> 00:15:01,860
We're using a placeholder
name for that function.

281
00:15:03,490 --> 00:15:06,830
Here, if the direction is one,

282
00:15:06,830 --> 00:15:11,430
what we want to do is that
the current index in Y,

283
00:15:12,820 --> 00:15:18,570
so now X is going to
be plus equals 1.

284
00:15:19,060 --> 00:15:22,910
This would allow us
to move move down,

285
00:15:22,910 --> 00:15:25,500
and we need two more conditions.

286
00:15:29,200 --> 00:15:32,060
we have those two. Copy pasting

287
00:15:32,060 --> 00:15:34,235
both at the same time so
we could start seeing,

288
00:15:34,235 --> 00:15:36,800
I really like seeing
the code as a texture.

289
00:15:36,800 --> 00:15:38,840
Sometimes I start understanding,

290
00:15:38,840 --> 00:15:41,370
we're doing this four times.

291
00:15:43,030 --> 00:15:47,150
Then the second, for the
direction number two,

292
00:15:47,150 --> 00:15:49,130
which is when we're actually
looking to the left,

293
00:15:49,130 --> 00:15:54,840
we will use the X axis
with a minus one.

294
00:15:55,240 --> 00:15:58,535
If we are using the
direction three,

295
00:15:58,535 --> 00:16:01,610
we are going to do
the Y axis with

296
00:16:01,610 --> 00:16:04,775
a negative facing up. That's it.

297
00:16:04,775 --> 00:16:10,560
We have rotate clockwise
and move forward function.

298
00:16:10,960 --> 00:16:13,130
Let's try to use them.

299
00:16:13,130 --> 00:16:15,020
I think we've been

300
00:16:15,020 --> 00:16:17,270
writing a lot of code.
We haven't press play.

301
00:16:17,270 --> 00:16:19,160
It's always a good
practice to make

302
00:16:19,160 --> 00:16:20,525
sure that things
are still running.

303
00:16:20,525 --> 00:16:23,465
It seems that script
is still there.

304
00:16:23,465 --> 00:16:26,975
Let's see if we
can go down here.

305
00:16:26,975 --> 00:16:30,755
If you remember, our walker
was moving randomly.

306
00:16:30,755 --> 00:16:33,710
Let's test one of them.

307
00:16:33,710 --> 00:16:41,060
Move forward. For the
move forward function

308
00:16:41,060 --> 00:16:43,610
requires the direction.

309
00:16:43,610 --> 00:16:45,800
What is the variable
for direction?

310
00:16:45,800 --> 00:16:46,940
Let me find it so I can copy

311
00:16:46,940 --> 00:16:50,460
pasted in direction.
There we go.

312
00:16:53,340 --> 00:16:55,540
I'm going to get rid
of these slides.

313
00:16:55,540 --> 00:16:57,655
These are getting
confusing here.

314
00:16:57,655 --> 00:17:03,620
Let's just call this
the walker movement.

315
00:17:04,290 --> 00:17:07,310
If I move forward, let's

316
00:17:07,310 --> 00:17:09,590
see if that function is working,

317
00:17:09,590 --> 00:17:11,015
that seems to be working, fine.

318
00:17:11,015 --> 00:17:13,890
It actually is moving
towards the right.

319
00:17:15,790 --> 00:17:19,670
What if we actually
ask to rotate?

320
00:17:19,670 --> 00:17:20,960
I'm going to quickly go and copy

321
00:17:20,960 --> 00:17:22,520
paste the number and the
name of the function.

322
00:17:22,520 --> 00:17:24,540
I don't want to get it wrong.

323
00:17:25,240 --> 00:17:29,780
Sorry for the quick scrolling.

324
00:17:29,780 --> 00:17:32,450
In the walker movement,

325
00:17:32,450 --> 00:17:39,035
we can use our rotate
clockwise for 90 degrees.

326
00:17:39,035 --> 00:17:42,065
If we start by rotating in
90 degrees, then we move.

327
00:17:42,065 --> 00:17:46,490
The next frame, we
rotate and then we move.

328
00:17:46,490 --> 00:17:50,900
We will actually get the agent,

329
00:17:50,900 --> 00:17:55,680
technically should be
spinning in place constantly.

330
00:17:57,700 --> 00:17:59,960
I wonder if that was an error.

331
00:17:59,960 --> 00:18:02,070
Let's just double check that.

332
00:18:03,310 --> 00:18:06,395
Let's add a second
line for move forward.

333
00:18:06,395 --> 00:18:09,210
We rotate, we move two lines,

334
00:18:10,570 --> 00:18:15,560
so we're not getting
this condition here.

335
00:18:15,560 --> 00:18:17,495
Let's double check if there's
anything that we wrote

336
00:18:17,495 --> 00:18:23,100
wrong in our functions.

337
00:18:24,250 --> 00:18:27,530
We have the current
index in X+1,

338
00:18:27,530 --> 00:18:30,185
the current index in Y+1,

339
00:18:30,185 --> 00:18:33,960
minus onein X and
minus one in Y.

340
00:18:35,350 --> 00:18:39,620
Here, if the direction is
zero, if it's one is two.

341
00:18:39,620 --> 00:18:42,980
If it's two is three.
If it's three, is zero.

342
00:18:42,980 --> 00:18:45,815
We don't have a
direction value four,

343
00:18:45,815 --> 00:18:47,465
the value that should
have been a zero.

344
00:18:47,465 --> 00:18:49,460
We're going back
to the beginning.

345
00:18:49,460 --> 00:18:51,800
That was the problem
that we were facing.

346
00:18:51,800 --> 00:18:54,155
We could see the
behavior moving right

347
00:18:54,155 --> 00:18:56,420
and going down and going
left and going up,

348
00:18:56,420 --> 00:18:58,385
but it wouldn't come back

349
00:18:58,385 --> 00:19:02,180
to the original
first orientation.

350
00:19:02,180 --> 00:19:06,365
Let's go back to the
work. Let's see.

351
00:19:06,365 --> 00:19:08,600
You see that our agent right

352
00:19:08,600 --> 00:19:11,960
now moves in between
these four states.

353
00:19:11,960 --> 00:19:17,120
It keeps flipping. We actually

354
00:19:17,120 --> 00:19:21,005
can control its behavior
through this movement.

355
00:19:21,005 --> 00:19:24,125
We're going to leave this
first part of this video here.

356
00:19:24,125 --> 00:19:26,360
We actually have
functions for movement.

357
00:19:26,360 --> 00:19:27,890
We're going to start seeing how

358
00:19:27,890 --> 00:19:30,710
to leverage these function,

359
00:19:30,710 --> 00:19:34,385
these behaviors based on the
information of the grid.

360
00:19:34,385 --> 00:19:37,410
I'll see you in the next video.