I would like to create random walks for n different person (n=10 to be handled with a slider in the GUI) where each person can move left, right, up, down (500 steps max (to be handled by a slider in the GUI and should stop if he reaches back the origin).
I would then like to display these metrics:
- step distribution per person: left, right, up, down
- Euclidean distance per person:
- Average step distribution: left, right, up, down (of all persons combined)
- average Euclidean distance (of all persons combined)
- variance and standard deviations of distances and steps among people
- output to csv: personID, stepsleft, stepsright, stepsup, stepsdown, Euclideandistance
I tried to start with this draft code but nothing seems to work so far.
'''
breed [persons person]
to setup
clear-all
setup-persons
reset-ticks
end
to setup-persons
create-persons Num-persons
set xcor 0
set ycor 0
set shape "person"
set color green
end
to moveright
set heading 90
fd 1
end
to moveleft
set heading 270
fd 1
end
to moveup
set heading 0
fd 1
end
to movedown
set heading 180
fd 1
end
to move-persons
ask persons [
; Randomly choose a direction to move
let direction random 4
; Move the turtle according to the chosen direction and update step counts
if direction = 0 [
moveright
set moveright [moveright + 1]
]
if direction = 1 [
moveleft
set moveleft moveleft + 1
]
if direction = 2 [
moveup
set moveup moveup + 1
]
if direction = 3 [
movedown
set movedown movedown + 1
]
]
tick
end
to go
move-persons
tick
if ( ticks > 1000) or (count persons with [color = red] < 1) [stop]
end
”’