How do I stop my turtles from stacking up on NetLogo? -
how stop turtles stacking on netlogo?
i need turtles move, not on top of each other , stop piling up.
i tried following code:
to go ask turtles [ let empty-patches neighbors [not any? turtles-here] if (breed = ricos) [ face one-of patches [ price = 1000 ] if any? empty-patches [ fd 1 ] ] if (breed = pobres) [ face one-of patches [ price = 1000 ] if any? empty-patches [ fd 1 ] ] if (breed = medias)[ if any? empty-patches [ face one-of patches [ price = 1000 ] fd 1] ] ] end move-to-empty-one-of [locations] move-to one-of locations while [any? other turtles-here] [ move-to one-of locations ] end
but still piling up.
welcome stack overflow! helpful provide minimal complete verifiable example of code reproducible- increase chance useful answer.
if have set turtles breeds(breed [ ricos rico ]
), can ask ricos [ ...
do call move-to-empty-one-of [locations]
procedure somewhere? not called in example code, , procedure, might turtles stacking, not running.
one note- code says like:
- empty patches neighbor patches without turtles
- face 1 of patches price 1000
- if there empty patches, move forward 1
the problem neighbors
includes 8 empty cells surrounding current turtle. so, when if any? empty-patches [ ...
, there @ least 1 empty patch, turtle can move forward. here alternative approach might work you:
breed [ ricos rico ] patches-own [ price ] setup ca reset-ticks ask n-of 20 patches [ set price 1000 set pcolor grey + 2 ] create-ricos 20 [ set color random 3 + 63 setxy random-xcor random-ycor ] end go ask ricos [ ifelse [price] of patch-here != 1000 or any? other turtles-here [ let target min-one-of patches [ price = 1000 , not any? turtles-here ] [ distance myself] face target fd 1 ] [ move-to patch-here ] ] tick end
this works having ricos (in example) check if @ patch price
not equal 1000 or @ patch other turtles present. if are, face nearest patch price = 1000
, no turtle on patch. then, move toward patch. if turtle beats them there, re-evaluate , face new patch fulfills conditions.
Comments
Post a Comment