1
00:00:05,421 --> 00:00:07,121
Hi, welcome to this new video.

2
00:00:07,121 --> 00:00:12,569
We are going to continue working on
our ecosystem simulation project.

3
00:00:12,569 --> 00:00:17,941
This is the third video, so
by all means start in the first two.

4
00:00:17,941 --> 00:00:23,016
And we're going to start talking about how
we can drive the behavior of this agent or

5
00:00:23,016 --> 00:00:26,314
this entity,
where we're calling the herbivore.

6
00:00:26,314 --> 00:00:31,220
And we have looked at several
kind of styles of behaviors.

7
00:00:31,220 --> 00:00:35,795
In the case of the particle, the forces
in the environment would actually dictate

8
00:00:35,795 --> 00:00:37,533
the behavior of the particle.

9
00:00:37,533 --> 00:00:41,905
We've looked also at state machines
in the past as systems that

10
00:00:41,905 --> 00:00:45,876
we can actually transition
between a handful of states.

11
00:00:45,876 --> 00:00:48,209
So the concept of a state
machine is very powerful, and

12
00:00:48,209 --> 00:00:50,711
we could certainly write
an airbar using a state machine.

13
00:00:50,711 --> 00:00:55,388
But I thought it would be interesting to
expand upon the different data structures

14
00:00:55,388 --> 00:00:59,482
and the different kind of behavioral
algorithms that we can use right?

15
00:00:59,482 --> 00:01:05,036
So we're going to introduce the notion
of a decision tree in this project.

16
00:01:05,036 --> 00:01:07,232
So let's discuss what is a decision tree,
right?

17
00:01:07,232 --> 00:01:12,846
A decision tree would be a flowchart-like
structure that has certain hierarchy,

18
00:01:12,846 --> 00:01:13,413
right?

19
00:01:13,413 --> 00:01:18,402
And we're going to construct a new class
called the node that is going to have

20
00:01:18,402 --> 00:01:22,561
two types of representation,
one is going to be a condition,

21
00:01:22,561 --> 00:01:27,072
right, that might lead towards
a yes node and a no node, right?

22
00:01:27,072 --> 00:01:31,374
And the terminal nodes, which we're
going to call the leaves are going to be

23
00:01:31,374 --> 00:01:34,827
action, they're going to
execute certain code, right?

24
00:01:34,827 --> 00:01:40,240
So, the condition nodes might only be like
a gate between moving down the flowchart,

25
00:01:40,240 --> 00:01:45,351
but until we eventually get to a point
where we can actually execute an action,,

26
00:01:45,351 --> 00:01:45,895
right?

27
00:01:45,895 --> 00:01:49,422
All of them are going to be
part of a classical node,

28
00:01:49,422 --> 00:01:54,154
but we're going to be calling
the topmost node, the root node, and

29
00:01:54,154 --> 00:01:58,220
we're going to have maybe that
being the node evaluated.

30
00:01:58,220 --> 00:02:02,816
And as we move through the tree structure
and answering these questions, yes or

31
00:02:02,816 --> 00:02:07,756
no, we're going to be moving down towards
general nodes, which are condition nodes,

32
00:02:07,756 --> 00:02:11,954
and finally the leaves which
are the terminal nodes of our tree, right?

33
00:02:11,954 --> 00:02:16,110
So how would we implement
that in the herbivore, right?

34
00:02:16,110 --> 00:02:19,768
So let's think of, this is actually
what we're going to write,

35
00:02:19,768 --> 00:02:23,358
it's a very simple tree-like,
but it's very expandable,

36
00:02:23,358 --> 00:02:28,141
it's something that you can really scale
to be a much more complex brain, right?

37
00:02:28,141 --> 00:02:28,941
If you think of it,

38
00:02:28,941 --> 00:02:32,042
what we're modeling at this point is
the brain of the herbivore, right?

39
00:02:32,042 --> 00:02:35,137
So the herbivore will start asking,
am I awake?

40
00:02:35,137 --> 00:02:37,826
And if no, meaning it's sleeping,

41
00:02:37,826 --> 00:02:42,601
it's going to continue resting for
executing the resting action,

42
00:02:42,601 --> 00:02:47,482
which potentially will reach to
a point where it wakes up, right?

43
00:02:47,482 --> 00:02:52,120
But if it's in fact awake, yes then
it's going to ask another question,

44
00:02:52,120 --> 00:02:53,520
am I hungry, right?

45
00:02:53,520 --> 00:02:58,037
And if the answer is yes, the behavior
is going to be seeking food, right?

46
00:02:58,037 --> 00:03:02,540
If the answer is no, we're going to move
to a random or wander around, right?

47
00:03:02,540 --> 00:03:06,763
So we're going to be structuring these
behaviors within this decision tree.

48
00:03:06,763 --> 00:03:10,630
And as you can see, we're going to
transition between what is the current

49
00:03:10,630 --> 00:03:12,510
note being evaluated from awake.

50
00:03:12,510 --> 00:03:17,046
If I'm awake, yes, move down to hungry,
and finally to like maybe I'm not hungry,

51
00:03:17,046 --> 00:03:19,633
and then I'll start wandering around,
right?

52
00:03:19,633 --> 00:03:23,098
So in this video we're
going to construct or

53
00:03:23,098 --> 00:03:27,366
write the kind of foundation
of the decision tree.

54
00:03:27,366 --> 00:03:31,481
And later we're going to be spending a bit
of time writing the wander function,

55
00:03:31,481 --> 00:03:35,291
the seek food function, each one of
the kind of actions specifically.

56
00:03:35,291 --> 00:03:40,286
So we're going to break it down gradually,
right?

57
00:03:40,286 --> 00:03:45,137
So let's jump into processing and see how
we can actually write this node class and

58
00:03:45,137 --> 00:03:48,317
implement this structure
that we're drawing here.

59
00:03:48,317 --> 00:03:54,541
So I'm continuing with the code
that we left from last video,

60
00:03:54,541 --> 00:04:00,652
so we have this kind of ongrowing
population of herbivores.

61
00:04:00,652 --> 00:04:05,506
One of the things that you might remember,
we didn't write the move function,

62
00:04:05,506 --> 00:04:07,762
we will come back to this in a minute.

63
00:04:07,762 --> 00:04:11,782
But basically what we
want to do is start kind

64
00:04:11,782 --> 00:04:16,357
of think about this herbivore's brain,
right?

65
00:04:16,357 --> 00:04:21,284
So let's just create a new tab and
we're going to call this node, and

66
00:04:21,284 --> 00:04:25,689
this node it's not going to be
a class that we can see, right?

67
00:04:25,689 --> 00:04:30,530
Until now we actually [INAUDIBLE]
spoiled that most of the classes that we

68
00:04:30,530 --> 00:04:33,929
create are kind of very visible classes,
right?

69
00:04:33,929 --> 00:04:38,766
But right now let's think that we're
going to be doing a class that

70
00:04:38,766 --> 00:04:44,154
represents some internal way of
thinking for this herbivore, right?

71
00:04:44,154 --> 00:04:49,086
So we're going to call it the class node,
and

72
00:04:49,086 --> 00:04:53,482
let's define it with a constructor.

73
00:04:53,482 --> 00:04:56,849
And here because I want
it to be quite flexible,

74
00:04:56,849 --> 00:05:01,660
a node could be a condition or action,
I'm not going to require that.

75
00:05:01,660 --> 00:05:03,933
The construction is going to have
a lot of flexibility, right?

76
00:05:03,933 --> 00:05:07,648
We're going to give some
default values to elements, so

77
00:05:07,648 --> 00:05:12,493
let's do something like a name,
which is going to be optional, and it's

78
00:05:12,493 --> 00:05:17,693
going to be optional because I'm going to
be giving the default of none, right?

79
00:05:17,693 --> 00:05:19,817
So if I don't provide a name, that name,

80
00:05:19,817 --> 00:05:23,466
it's already kind of having some
information there that's something

81
00:05:23,466 --> 00:05:27,082
that we can do to actually make
constructors very flexible in Python.

82
00:05:27,082 --> 00:05:31,375
So action it's going to be known as well,

83
00:05:33,279 --> 00:05:38,117
Yes node That's also going to be known.

84
00:05:38,117 --> 00:05:41,253
And I'll explain to you in a minute
what we're doing here, right?

85
00:05:41,253 --> 00:05:48,254
So no node, it's going to be null, so
all of them are going to be empty.

86
00:05:53,849 --> 00:05:59,313
A little bit

87
00:05:59,313 --> 00:06:07,514
the screen here so

88
00:06:15,333 --> 00:06:15,965
There we go.

89
00:06:15,965 --> 00:06:20,631
If you feel like this is actually too
long and you want to just break it apart,

90
00:06:20,631 --> 00:06:21,680
you can do this.

91
00:06:21,680 --> 00:06:27,175
And it might be better for
us to do so like this here as well.

92
00:06:39,730 --> 00:06:40,949
We don't need an indentation here.

93
00:06:40,949 --> 00:06:45,542
It's just to make visible all
the different things that

94
00:06:45,542 --> 00:06:48,288
the constructor is trying to do.

95
00:06:48,288 --> 00:06:53,097
So let's just copy-paste
some of these variables now.

96
00:06:53,097 --> 00:06:59,396
So self.name equals name and

97
00:06:59,396 --> 00:07:06,681
self.action equals action.

98
00:07:06,681 --> 00:07:10,608
Self.yes node equals yes node.

99
00:07:18,527 --> 00:07:21,077
So I'm going to finish writing this and

100
00:07:21,077 --> 00:07:26,273
we can spend a bit of time understanding
what really is going on here right?

101
00:07:32,658 --> 00:07:36,133
So I want to have enough
flexibility to debug

102
00:07:36,133 --> 00:07:41,065
to visualize the name of the node
in which I'm currently at.

103
00:07:41,065 --> 00:07:43,393
So the name is actually
completely unnecessary.

104
00:07:43,393 --> 00:07:47,538
But it's going to be useful as
we're flowing through the nodes and

105
00:07:47,538 --> 00:07:52,678
we can give nodes a name and see like show
me which node you're currently in and

106
00:07:52,678 --> 00:07:57,434
it's going to tell us You're in node one,
or you're in the root node or

107
00:07:57,434 --> 00:07:59,460
you're in the leaf one right?

108
00:07:59,460 --> 00:08:01,767
So That might be useful,

109
00:08:01,767 --> 00:08:05,169
come handy to understand what is
the current node being active.

110
00:08:06,709 --> 00:08:08,611
So in each one of these cases,

111
00:08:08,611 --> 00:08:12,884
this is basically the data that we
actually need within each node.

112
00:08:12,884 --> 00:08:17,010
And we're going to be using
that in the herbivore to

113
00:08:17,010 --> 00:08:20,525
construct the decision tree, right?

114
00:08:20,525 --> 00:08:24,364
So the action,
we're going to give it a string, a name,

115
00:08:24,364 --> 00:08:29,379
something like wander, right,
seek food, right, or rest, right?

116
00:08:29,379 --> 00:08:34,142
And this is going to be a string variable.

117
00:08:34,142 --> 00:08:38,237
The condition node here is going to be,
am I hungry?

118
00:08:38,237 --> 00:08:39,100
It's a question, right?

119
00:08:39,100 --> 00:08:46,351
It's going to be a type of condition,
or am I awake, am I checking for, right?

120
00:08:46,351 --> 00:08:49,045
This condition will take
us into two nodes, right?

121
00:08:49,045 --> 00:08:54,603
So as much as this is a node object,
it will have reference to other two nodes,

122
00:08:54,603 --> 00:08:59,403
the yes no and the not no, sorry,
yes node and the no node, right?

123
00:08:59,403 --> 00:09:02,711
So that's what is actually
creating the tree,

124
00:09:02,711 --> 00:09:07,189
is that some nodes will have
references to other nodes, right?

125
00:09:07,189 --> 00:09:11,602
So these will all come together
as we start putting the tree,

126
00:09:11,602 --> 00:09:13,625
we start writing the tree.

127
00:09:13,625 --> 00:09:16,293
So finally, the condition variable might

128
00:09:16,293 --> 00:09:21,195
be that the herbivore might have already
a variable such as is hungry, right?

129
00:09:21,195 --> 00:09:25,417
And we're going to create
variables specifically to be

130
00:09:25,417 --> 00:09:30,198
able to see how the node controls
a condition such as hunger,

131
00:09:30,198 --> 00:09:34,203
hunger level and
things like that sort, right?

132
00:09:34,203 --> 00:09:36,467
So this is going to be our node.

133
00:09:36,467 --> 00:09:40,683
Let's just try to build a decision
tree with this in mind, right?

134
00:09:40,683 --> 00:09:43,580
So the first thing I like to do in
the herbivore is just create some

135
00:09:43,580 --> 00:09:44,555
variables, right?

136
00:09:44,555 --> 00:09:48,507
So I'm going to create a self.isAwake,

137
00:09:48,507 --> 00:09:53,937
which is going to be a Boolean,
and it's going to be True.

138
00:09:53,937 --> 00:09:57,116
So it's going to start awake, right?

139
00:09:57,116 --> 00:10:03,058
self.isHungry, And

140
00:10:03,058 --> 00:10:07,358
that's going to be false, right?

141
00:10:07,358 --> 00:10:14,053
So, great, we have two variables that we
are considering part of our conditions.

142
00:10:14,053 --> 00:10:19,404
And now between the run and the display,

143
00:10:19,404 --> 00:10:24,128
but it could be anywhere, really,

144
00:10:24,128 --> 00:10:32,329
let's just first write
the build_decision_tree system.

145
00:10:32,329 --> 00:10:37,747
So in order to kind of start
building the decision tree,

146
00:10:37,747 --> 00:10:40,644
we're going to need to import.

147
00:10:44,899 --> 00:10:48,519
We're going to import the node
class that we just created.

148
00:10:48,519 --> 00:10:50,402
And let's define a leaf node first,

149
00:10:50,402 --> 00:10:53,926
because we're going to start from
the bottom up, as some of the further

150
00:10:53,926 --> 00:10:57,893
nodes might need to make references to
some of these previous nodes, right?

151
00:10:57,893 --> 00:11:01,619
So we're going to say the leaf node 1,
it's going to be a node.

152
00:11:03,719 --> 00:11:05,807
And here we need to provide the data.

153
00:11:05,807 --> 00:11:09,832
Let's just spell out what we're saying.

154
00:11:09,832 --> 00:11:14,104
We're going to say name = l1, so

155
00:11:14,104 --> 00:11:19,008
it's going to refer to the leaf 1, and

156
00:11:19,008 --> 00:11:24,086
it's going to have an action = wonder,

157
00:11:26,080 --> 00:11:27,935
Right?

158
00:11:27,935 --> 00:11:31,398
And that's it, we've created a node
in our decision tree, right?

159
00:11:31,398 --> 00:11:35,802
We're manually constructing
this decision tree.

160
00:11:35,802 --> 00:11:37,901
Do we need to provide more information?

161
00:11:37,901 --> 00:11:39,750
No, because in the constructor,

162
00:11:39,750 --> 00:11:43,846
these are not mandatory fields because
they actually have a default value.

163
00:11:43,846 --> 00:11:49,247
We are assuming that all of them
are complete with the non-variable, right?

164
00:11:49,247 --> 00:11:53,219
So when the information that we're
actually going to be giving is only

165
00:11:53,219 --> 00:11:57,773
the name, which again is optional, but
only in this case, the action node.

166
00:11:57,773 --> 00:12:01,039
So a leaf node in this case is
going to be an action node.

167
00:12:01,039 --> 00:12:08,197
So let's just copy paste
this to do three nodes.

168
00:12:08,197 --> 00:12:14,311
So we're going to call leaf2 and
leaf3, and then leaf2 and

169
00:12:14,311 --> 00:12:19,211
leaf3 are going to be,
in this case, Seek food.

170
00:12:21,628 --> 00:12:24,397
And in this case, Rest, right?

171
00:12:24,397 --> 00:12:28,207
So these are the three actions
that we are considering.

172
00:12:28,207 --> 00:12:31,417
Let's create a node, 1,

173
00:12:31,417 --> 00:12:37,418
which is going to be name n1,
just to remember that,

174
00:12:37,418 --> 00:12:42,595
some kind of short name
that we can remember.

175
00:12:42,595 --> 00:12:43,935
And this is going to be a condition node.

176
00:12:43,935 --> 00:12:50,213
So it's going to be a condition,
and this is a string, is hungry.

177
00:12:54,950 --> 00:12:59,842
And some of these might be unnecessary,
but we're going to just try to make it

178
00:12:59,842 --> 00:13:04,358
in such a way that it becomes a little
bit more didactic, hopefully.

179
00:13:04,358 --> 00:13:09,113
So if the condition is hungry, yesNode.

180
00:13:09,113 --> 00:13:14,819
So the yesNode will be seek food,
right, so leaf2.

181
00:13:14,819 --> 00:13:18,773
So let's say that leaf2 is
going to be the condition, right?

182
00:13:18,773 --> 00:13:22,259
If I'm hungry, I'm going to go to
the seek food, which is an action, right?

183
00:13:23,439 --> 00:13:29,265
And if noNode,
I'm going to say if I'm not hungry,

184
00:13:29,265 --> 00:13:33,148
I'm going to go to l1, or leaf1,

185
00:13:33,148 --> 00:13:39,135
which is going to be the action
of wandering, right?

186
00:13:39,135 --> 00:13:44,308
And finally, we're going to say
that the condition_variable,

187
00:13:44,308 --> 00:13:50,263
and again, sorry, I'm going to have to
break it down into lines to be more.

188
00:13:57,822 --> 00:14:05,130
And I don't know if this helps, but I
don't want to be scrolling out of screen.

189
00:14:05,130 --> 00:14:12,093
So the variable that we're going to be
adding here is the isHungry variable.

190
00:14:12,093 --> 00:14:15,644
So self.isHungry, right?

191
00:14:15,644 --> 00:14:20,050
Because that's a variable that
we have now internally to

192
00:14:20,050 --> 00:14:24,107
the herbivore to evaluate this condition,
right?

193
00:14:24,107 --> 00:14:28,211
That's the node 1, and
we finally have the root, right?

194
00:14:28,211 --> 00:14:32,960
So here we revise the diagram that
we drew about this tree structure.

195
00:14:32,960 --> 00:14:36,570
It has a root,
it has a node1 that branches,

196
00:14:36,570 --> 00:14:42,556
the root kind of goes into node1 or
directly into the action rest, right?

197
00:14:42,556 --> 00:14:44,719
Because the root is also a condition node,
so let's write it.

198
00:14:44,719 --> 00:14:50,750
So node with the name equals to root,

199
00:14:50,750 --> 00:14:57,269
and the condition, Is Awake.

200
00:15:05,511 --> 00:15:09,811
There we go, is Awake, yesNode.

201
00:15:09,811 --> 00:15:16,570
So if I'm awake,
I'm going to go into the node1, right?

202
00:15:16,570 --> 00:15:23,322
If I'm not awake, I'm going to continue
performing the action of resting.

203
00:15:23,322 --> 00:15:28,902
So noNode will be the leaf3, right?

204
00:15:28,902 --> 00:15:32,159
noNode will be leaf3.

205
00:15:32,159 --> 00:15:37,585
So let's just break it down as we've
done with the previous one as well.

206
00:15:40,838 --> 00:15:43,247
And there's a condition variable here,
too.

207
00:15:49,494 --> 00:15:53,413
So if we look at what we wrote here,

208
00:15:53,413 --> 00:15:57,345
the condition variable isAwake,

209
00:15:59,595 --> 00:16:03,269
The variable that we're going to be using
to kind of evaluate this condition, right?

210
00:16:03,269 --> 00:16:10,797
So at this point we could return root,
right?

211
00:16:10,797 --> 00:16:14,346
So this function,
whenever we execute this function,

212
00:16:14,346 --> 00:16:19,005
let's just double check that we're
not running into errors, right?

213
00:16:19,005 --> 00:16:25,614
So I'm going to, let's call it once,

214
00:16:25,614 --> 00:16:33,931
we could say up here, self.current_node,

215
00:16:33,931 --> 00:16:40,130
self.build_decision_tree.

216
00:16:40,130 --> 00:16:45,813
Oops, So

217
00:16:45,813 --> 00:16:48,581
we're going to create a variable
called the current_node.

218
00:16:48,581 --> 00:16:51,031
If you remember,
there's one node being active and

219
00:16:51,031 --> 00:16:53,826
we're going to construct the whole
tree and start at the top.

220
00:16:53,826 --> 00:16:59,665
The root node is going to be the node that
has all these kind of branching paths,

221
00:16:59,665 --> 00:17:05,139
that this one takes us to the node 1 and
this one will take us to leaf1 and

222
00:17:05,139 --> 00:17:11,006
2, right, but depending on the internal
state of the herbivore, right?

223
00:17:11,006 --> 00:17:15,860
So like at this point we're not executing
any actions, so we shouldn't see any

224
00:17:15,860 --> 00:17:21,525
changes, but we really want to check if
the code is actually creating any errors.

225
00:17:21,525 --> 00:17:27,545
So we're not running into errors,
again, we're not seeing any motion.

226
00:17:28,645 --> 00:17:33,034
This is not the entire story,
the decision tree,

227
00:17:33,034 --> 00:17:39,514
now that it's been constructed, right,
it needs the second part of it,

228
00:17:39,514 --> 00:17:44,131
which is running based on
the current node, right?

229
00:17:44,131 --> 00:17:48,335
We're going to write a function called

230
00:17:48,335 --> 00:17:53,225
let's update_current_node, right?

231
00:17:54,605 --> 00:17:59,412
And here's the part where we would say,
are you a condition or

232
00:17:59,412 --> 00:18:01,597
are you an action, right?

233
00:18:01,597 --> 00:18:02,773
This is kind of the question.

234
00:18:02,773 --> 00:18:07,629
If you're a condition,
evaluate if your current state,

235
00:18:07,629 --> 00:18:10,809
it's true or false, your variable.

236
00:18:10,809 --> 00:18:14,333
And based on that dictate if you
move to the next node, right?

237
00:18:14,333 --> 00:18:16,539
And if you're an action,
we're going to print a statement.

238
00:18:16,539 --> 00:18:19,983
It's like the animal is currently,
or the herbivore is currently

239
00:18:19,983 --> 00:18:23,547
performing a wonder state or
seeking, depending on the variable.

240
00:18:23,547 --> 00:18:25,947
So let's just write it as we go.

241
00:18:25,947 --> 00:18:28,721
So we're going to start
with an if statement.

242
00:18:28,721 --> 00:18:32,674
Here we're going to say if

243
00:18:32,674 --> 00:18:38,411
the self.current_node right?

244
00:18:38,411 --> 00:18:42,115
So because we want to be evaluating
the current_node, right?

245
00:18:42,115 --> 00:18:49,334
Make sure that we spell it correctly if
the current_node has an internal variable,

246
00:18:49,334 --> 00:18:54,327
so conditional variable,
condition variable, right?

247
00:18:54,327 --> 00:18:57,251
Notice that not all nodes have
a conditional variable, right?

248
00:18:57,251 --> 00:19:00,555
Only the conditional nodes These
two have a conditional variable.

249
00:19:00,555 --> 00:19:03,300
The other ones have a none, right?

250
00:19:03,300 --> 00:19:08,114
So we're going to say if it's not none,
right,

251
00:19:08,114 --> 00:19:12,931
knowing that that defines
a node as a condition

252
00:19:12,931 --> 00:19:16,646
node having a condition variable.

253
00:19:16,646 --> 00:19:23,579
Sorry, I put two dots here,
we will do something, right?

254
00:19:23,579 --> 00:19:27,382
And we could say else or elif here,

255
00:19:32,594 --> 00:19:40,900
If the current_node.action is not none,

256
00:19:40,900 --> 00:19:45,842
something else happens.

257
00:19:45,842 --> 00:19:52,125
So here, this is an action node and
this is a condition node.

258
00:19:55,570 --> 00:20:02,398
Right, simple enough at this point,
we could say a print line.

259
00:20:08,261 --> 00:20:11,864
We could print the action.

260
00:20:11,864 --> 00:20:18,599
We could just say, Print that action.

261
00:20:18,599 --> 00:20:24,536
The action, as we can see, it's a string,
so it would be Wonder, Seek Food, right?

262
00:20:24,536 --> 00:20:28,059
So that's good enough, but in their
condition the condition is a little bit

263
00:20:28,059 --> 00:20:31,903
more complex because it needs to be able
to kind of navigate towards the next node.

264
00:20:31,903 --> 00:20:38,356
It's kind of like sequentially moves
to the next node and the next node.

265
00:20:38,356 --> 00:20:43,611
So let's just say that if that current
variable that we're evaluating,

266
00:20:43,611 --> 00:20:49,304
right, we're first asking, do you have
that conditional variable, right?

267
00:20:49,304 --> 00:20:51,725
And if you have that, let's evaluate that.

268
00:20:51,725 --> 00:20:53,856
Is that true or false, right?

269
00:20:53,856 --> 00:20:59,263
If it's true, the self.current_node,

270
00:20:59,263 --> 00:21:03,654
let's just copy paste that again.

271
00:21:03,654 --> 00:21:09,272
If it's true, the current_node will
become the yesnode of that node.

272
00:21:15,517 --> 00:21:21,728
Right, so we know that that node has
a yesnode, so that's if it's true, else,

273
00:21:24,875 --> 00:21:30,119
We're going to go down the ladder

274
00:21:30,119 --> 00:21:35,311
towards the nonode, right?

275
00:21:35,311 --> 00:21:39,463
So that's it, basically it's a simple
kind of like flowchart, right?

276
00:21:39,463 --> 00:21:44,449
We're saying if you have a condition
means that your condition node,

277
00:21:44,449 --> 00:21:46,236
is that condition true?

278
00:21:46,236 --> 00:21:48,800
Yes, well,
then you are the next current_node.

279
00:21:48,800 --> 00:21:53,094
So the next time around we're going to
evaluate the next node, and it's going to

280
00:21:53,094 --> 00:21:57,874
keep on doing this kind of branching path
structure until it reaches an action node.

281
00:21:57,874 --> 00:22:01,147
And when it reaches an action node,
it will perform the action, right?

282
00:22:01,147 --> 00:22:05,971
We're going to discuss how actions can
potentially trigger a return to a previous

283
00:22:05,971 --> 00:22:10,867
node or a return to the root, depending
on how we want to implement the behavior,

284
00:22:10,867 --> 00:22:11,373
right?

285
00:22:11,373 --> 00:22:17,467
So let's see, just to conclude,
it's already getting a bit long.

286
00:22:17,467 --> 00:22:22,750
So let's just add this

287
00:22:22,750 --> 00:22:32,308
function to our, To our run.

288
00:22:32,308 --> 00:22:36,568
So, meaning that we are executing this
function because we basically have

289
00:22:36,568 --> 00:22:37,592
a decision tree.

290
00:22:37,592 --> 00:22:43,444
Notice that the decision tree we
build it at the beginning once, and

291
00:22:43,444 --> 00:22:50,233
now with the current node, it's going to
be used in the update current, right?

292
00:22:50,233 --> 00:22:52,587
We're having an error here.

293
00:22:52,587 --> 00:23:00,368
I think this is just the spelling
here is not instead of int not.

294
00:23:00,368 --> 00:23:06,054
Let's see, right, so
you see we are getting

295
00:23:06,054 --> 00:23:12,805
now here in the console
the print of Wander, right?

296
00:23:12,805 --> 00:23:14,237
Why are we getting Wander?

297
00:23:14,237 --> 00:23:21,650
Because we are saying awake state
true Is Hungry false, right?

298
00:23:21,650 --> 00:23:28,101
I think that if we would put this
to true as a default state for

299
00:23:28,101 --> 00:23:34,053
the herbivores,
we would get the behavior Seek Food.

300
00:23:34,053 --> 00:23:38,545
So the leaf which we end up with
based on these current variables

301
00:23:38,545 --> 00:23:42,274
navigating through the chart
as we have laid it out,

302
00:23:42,274 --> 00:23:46,622
if you are hungry, you're going to
end up in a seek food state.

303
00:23:46,622 --> 00:23:51,364
If you are not,
you're going to be wandering, right?

304
00:23:51,364 --> 00:23:53,053
So those are the two main functions.

305
00:23:53,053 --> 00:23:57,474
We have a decision tree in place,
so now we can actually start

306
00:23:57,474 --> 00:24:02,084
executing some of those actions and
working on that behavior.

307
00:24:02,084 --> 00:24:02,985
So I'll see you in the next video.