Reputation: 197
I am doing a small university project. In which i have to maintain 2 states of turtles. 1. Disperse 2. Explore Disperse : In dispersion, when at the start all the turtles (20 turtles) are at 0,0 they should disperse from each other. Every turtle has a radius of 2 patches around it, no other turtle should be in that radius. All turtles should go far until they all attain this radius. then other behavior will be called i.e. Explore.
Explore: In explore , they have to explore the world and avoid different types of obstacles. When ever two turtles come close to each other above mentioned radius then state should be changed to disperse.
I have procedures for obstacle avoidance, and move-speed, and all other individual behaviors under Disperse and Explore. But i don't know how to join all this in one simulation.
Upvotes: 1
Views: 228
Reputation: 1295
You might want to take a look at Moore machine and Automata, NetLogo works great with those.
A Moore machine can be seen as a set of 5 elements that interact with each other, in this particular example the start state(S0
) would be Dispersing. In NetLogo you can use the word run that receives a string. You'd had to make a procedure that returns a string (say "explore"
) by checking the actual state of a turtle.
I made something like that a few months ago. We were trying to make a hunter-prey model for polar bears and seals (or wolves and sheeps) based on Moore Machines.
You can use the example of @Alan of course, I just skimmed through and I believe it was fine.
Here is my example based on Moore Machine. It's in spanish but the idea is the same.
Upvotes: 2
Reputation: 9610
It is unclear that you really need to maintain turtle state, since you will have to repeatedly check for other turtles in any case. But since you said you wanted that, you can use turtles-own
. For example:
turtles-own [state]
to setup
ca
crt 20
end
to go
ask turtles [set-state]
ask turtles [move]
end
to set-state ;;turtle proc
ifelse (any? other turtles in-radius 2) [
set state "disperse"
] [
set state "explore"
]
end
to move ;;turtle proc
if (not member? state ["disperse" "explore"]) [
error "unknown state"
]
if (state = "disperse") [
disperse
]
if (state = "explore") [
explore
]
end
to disperse ;;turtle proc
move-to one-of patch-set [neighbors] of neighbors
end
to explore
move-to one-of neighbors
end
Upvotes: 3