Reputation: 77
I am relatively new to NetLogo and have been trying to figure this out for quite some time. I have a search path algorithm that determines the optimal path for each turtle (ship) in my model, storing each path as a separate list of patches. The goal is to have the turtles traverse along the list of patches while having the tick counter increase each step the turtles take (i.e. a tick every time all the turtles move from one patch to the next) - until it reaches the destination. Seems pretty simple but for some reason I can't seem to figure out the correct way to use the context of 'tick'.
Here's an example of my code corresponding to the movement portion (once the lists of paths have already been generated).
to move
tick
ask-concurrent ships
[
while [length current-path != 0]
[
face first current-path
move-to first current-path
set current-path remove-item 0 current-path
wait 0.08
]
]
end
Currently the tick counter only ticks once for the entire simulation. Can anyone help me code this in a different way in order to have the ticks increase each time the turtles (collectively) move from patch to patch? Any help would be greatly appreciated.
Here is the portion of code where move is being called
to find-shortest-path-to-destination
place-turtles
label-destination
foreach sort ships
[ ask ?
[
set path find-a-path current-waypoint target-waypoint
set optimal-path path
set current-path path
]
]
move
end
Upvotes: 2
Views: 1158
Reputation: 3806
I would change your code to the following and put move inside of a repeat block. Essentially, everyone moves 1 path unit at a time and then move is called again,which then calls the next tick-event to occur
to move
tick
ask-concurrent ships with [length current-path != 0]
[
face first current-path
move-to first current-path
set current-path remove-item 0 current-path
wait 0.08
]
end
to go
while [any? ships with [length current-path != 0]] [move]
end
Upvotes: 3