1
00:00:09,002 --> 00:00:13,261
So we have our model set up, the turtles
are there,
2
00:00:13,261 --> 00:00:16,039
but we haven't written the 'go' code at
all
3
00:00:16,039 --> 00:00:21,303
in order to get the model up and running
in terms of the model actions.
4
00:00:21,303 --> 00:00:26,527
So we're going to start that. We already
have a stub here for 'to go',
5
00:00:26,527 --> 00:00:30,227
and we're just going to do something very
simple,
6
00:00:30,227 --> 00:00:36,717
we going to ask the turtles, if the color
is blue, then act cowardly:
7
00:00:36,717 --> 00:00:50,277
'if (color = blue) [ act-cowardly ]'
8
00:00:50,277 --> 00:00:53,618
because that's what we set it to up in the
setup routine.
9
00:00:53,618 --> 00:00:57,483
And if the color is red, then act bravely;
10
00:00:57,483 --> 00:01:03,619
'if (color = red) [ act-bravely ]'
11
00:01:03,619 --> 00:01:12,676
'act-cowardly' and 'act-bravely' are not
built in NetLogo commands
12
00:01:12,676 --> 00:01:18,964
so when we check it's going to say
'Nothing named ACT-COWARDLY has been defined'
13
00:01:18,964 --> 00:01:21,214
so the next thing we have to do...
14
00:01:21,214 --> 00:01:25,040
oops - almost forgot - we need to add a
'tick' at the end of our 'go'
15
00:01:25,040 --> 00:01:28,513
that tells NetLogo that we're done with
that iteration of the 'go' loop
16
00:01:28,513 --> 00:01:30,811
and it's time to go on to the next one.
17
00:01:30,811 --> 00:01:40,840
What we need to do now is define
'act-cowardly' and 'act-bravely'.
18
00:01:40,840 --> 00:01:45,412
Actually, at this point the model will
run, it's just not going to do anything
19
00:01:45,412 --> 00:01:48,499
as we haven't put anything in these
procedure commands.
20
00:01:48,499 --> 00:01:55,054
So when we hit 'go' you'll see the ticks
run but nothing else happens.
21
00:01:55,054 --> 00:02:00,025
So now we need to define 'act-bravely'
and 'act-cowardly',
22
00:02:00,025 --> 00:02:06,139
Let's start with 'act-bravely' because
that one's a little bit easier.
23
00:02:06,139 --> 00:02:15,480
So what does it mean to act bravely
from the modelling perspective?
24
00:02:15,480 --> 00:02:25,527
'Acting bravely' means to move toward the
mid-point of your friend and your enemy.
25
00:02:25,527 --> 00:02:30,595
One way to think about it is to imagine an
invisible line...
26
00:02:30,595 --> 00:02:33,022
connecting your friend to your enemy,
27
00:02:33,022 --> 00:02:36,672
and you're going to move to the middle of
that line.
28
00:02:36,672 --> 00:02:41,163
The original rules aren't very clear as to
exactly the middle of that line
29
00:02:41,163 --> 00:02:45,230
but the middle makes sense because that
way even as other people move...
30
00:02:45,230 --> 00:02:49,197
you're likely to be there in the middle.
31
00:02:49,197 --> 00:02:55,082
So how can we do this? We can use the
'facexy' command we looked at last time,
32
00:02:55,082 --> 00:03:00,035
and we can say let's take the x coordinate
of our friend
33
00:03:00,035 --> 00:03:05,883
and add it to the x coordinate of our
enemy, and then divide it by two:
34
00:03:05,883 --> 00:03:09,679
'facexy ([xcor] of friend + [xcor] of enemy) / 2'
35
00:03:09,679 --> 00:03:17,074
and that's going to tell us the x value that's
half way between my friend and my enemy.
36
00:03:17,074 --> 00:03:23,287
because whatever those two x coordinates
are, if I average them I get the mid point.
37
00:03:23,287 --> 00:03:33,727
Then we're going to also at the same time
set the y coordinate to the mid point:
38
00:03:33,727 --> 00:03:53,080
'([ycor] of friend + [ycor] of enemy) / 2'
39
00:03:53,080 --> 00:03:57,727
And then we'll add a move forward:
'fd 0.1'
40
00:03:57,727 --> 00:04:03,383
we could do 'forward 1' but that makes the
animation jerky
41
00:04:03,383 --> 00:04:07,185
so we'll just have it move a little bit
slower.
42
00:04:07,185 --> 00:04:09,057
So that's what it means to act bravely,
43
00:04:09,057 --> 00:04:12,993
and now if you look back at the code and
trace it through
44
00:04:12,993 --> 00:04:17,242
if we have the system set up for 'heroes'
that should work already.
45
00:04:17,242 --> 00:04:20,631
So let's go back over to the interface,
hit 'setup', hit 'go'...
46
00:04:20,631 --> 00:04:23,522
and sure enough you see some action
going on.
47
00:04:23,522 --> 00:04:26,437
So we've written the 'act-bravely', we've
written the 'setup',
48
00:04:26,437 --> 00:04:29,158
and now we need to write the
'act-cowardly' command.
49
00:04:29,158 --> 00:04:31,113
So what does this look like?
50
00:04:31,113 --> 00:04:36,782
Cowardly action has the focal agent move
in such a way...
51
00:04:36,782 --> 00:04:39,941
that the friend is between them and the
enemy.
52
00:04:39,941 --> 00:04:41,876
So one way we could think of this is...
53
00:04:41,876 --> 00:04:45,589
we figure out how far away the friend is
away from the enemy,
54
00:04:45,589 --> 00:04:50,240
and then project a point on the other side
of the friend...
55
00:04:50,240 --> 00:04:54,846
that is the point we're going to try and
aim to move towards.
56
00:04:54,846 --> 00:05:02,165
So we're going to move away from the enemy
on the other side of the friend.
57
00:05:02,165 --> 00:05:05,755
We can use this 'facexy' command again,
58
00:05:05,755 --> 00:05:11,148
and the first thing we need to figure out
is where is our friend located...
59
00:05:11,148 --> 00:05:13,770
because we need to move to the other side
of them,
60
00:05:13,770 --> 00:05:18,040
and then we're going to move in such a
way that we're going to move past them...
61
00:05:18,040 --> 00:05:20,522
the distance they are away from the enemy,
62
00:05:20,522 --> 00:05:28,200
So to do that we can take the x coordinate
of the friend,
63
00:05:28,200 --> 00:05:33,046
and subtract off the x coordinate of the
enemy:
64
00:05:33,046 --> 00:05:37,248
'facexy [xcor] of friend + ([xcor] of friend - [xcor] of enemy )'
65
00:05:37,248 --> 00:05:43,065
and this should give us a position on the
other side of the friend.
66
00:05:43,065 --> 00:05:45,994
And then we can do the same thing for the
y coordinate:
67
00:05:45,994 --> 00:05:59,366
'[ycor] of friend + ([ycor] of friend - [ycor] of enemy)'
68
00:05:59,366 --> 00:06:03,893
And once we've done that we just need to
do the 'fd 0.1'
69
00:06:03,893 --> 00:06:07,962
so that we actually move in that direction,
not just face in that direction.
70
00:06:07,962 --> 00:06:16,616
Now we should have all the code we need
up and running to get our model working.
71
00:06:16,616 --> 00:06:19,675
So now we can ask the question,
72
00:06:19,675 --> 00:06:24,029
what is the emergent property when we run
the 'heroes' code,
73
00:06:24,029 --> 00:06:27,553
as opposed to the emergent property when
when we run the 'cowards' code?
74
00:06:27,553 --> 00:06:30,200
So, we hit 'setup' and we select 'heroes',
75
00:06:30,200 --> 00:06:35,524
and as you can see the point quickly
collapses to the middle of the space.
76
00:06:35,524 --> 00:06:42,097
If we select 'cowards' instead, then we
get very different action...
77
00:06:42,097 --> 00:06:46,241
we get this action where everyone is
spread out all over the place.
78
00:06:46,241 --> 00:06:53,627
In fact, this is in a world where we have
wrapping turned on,
79
00:06:53,627 --> 00:06:56,318
so everyone's moving everywhere.
80
00:06:56,318 --> 00:06:59,897
If we go in 'Model Settings' and we turn
wrapping off,
81
00:06:59,897 --> 00:07:04,892
which would be more like the game being
played in a bounded room,
82
00:07:04,892 --> 00:07:07,921
then we get another different, interesting
behaviour,
83
00:07:07,921 --> 00:07:11,115
everyone moves to the edges of the room.
84
00:07:11,115 --> 00:07:12,761
So why is this happening?
85
00:07:12,761 --> 00:07:15,991
If you think about it a little bit, in the
'cowards' case...
86
00:07:15,991 --> 00:07:19,028
you're trying to move as far away as
possible,
87
00:07:19,028 --> 00:07:21,628
and everyone's trying to move as far away
as possible,
88
00:07:21,628 --> 00:07:24,444
so they're moving farther and farther away
from each other,
89
00:07:24,444 --> 00:07:27,665
and as a result they eventually hit the
borders of the room
90
00:07:27,665 --> 00:07:30,070
which is as far as they can get.
91
00:07:30,070 --> 00:07:34,136
In the 'heroes' case, everyone is trying
to move between someone and someone else
92
00:07:34,136 --> 00:07:38,301
and so as everyone tries to do that they
move closer and closer to each other
93
00:07:38,301 --> 00:07:41,073
until they collapse into a ball in the
middle of the room.
94
00:07:41,073 --> 00:07:44,899
So that's the basic idea of the 'Heroes
and Cowards' model.
95
00:07:44,899 --> 00:07:49,642
In the next set of talks, we're going to
talk a bit about extending it,
96
00:07:49,642 --> 00:07:52,116
about some of the things that this model
teaches us,
97
00:07:52,116 --> 00:07:54,502
and about how to document the model.
98
00:07:54,502 --> 00:07:57,564
But at this point you've now created one
of your first models...
99
00:07:57,564 --> 00:08:00,053
so congratulations!