-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_shake.nlogo
37 lines (34 loc) · 945 Bytes
/
random_shake.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
;; this model gives the turtles the possibility to sense the other's value and, according to that value, make their own move.
turtles-own [value]
to setup
clear-all
set-default-shape turtles "circle"
create-turtles 30
[ setxy random-xcor random-ycor
set color red
set size 2
set value random 10 ]
create-turtles 30
[ setxy random-xcor random-ycor
set color blue
set size 2
set value random 10 ]
end
to go
ask turtles with [color = red]
[ let neighbor one-of turtles in-radius 5 with [color = red]
ifelse value > [value] of neighbor
[ set heading 270 ]
[ set heading 0 ]
forward 1 + random-float 1
right random 10 - random 5
]
ask turtles with [color = blue]
[ let neighbor one-of turtles in-radius 5 with [color = blue]
ifelse value > [value] of neighbor
[ set heading 90 ]
[ set heading 180 ]
forward 1 + random-float 1
right random 5 - random 10
]
end