turtles in pattern and avoid two turtles/one patch problem

263 views
Skip to first unread message

rbsoc...@gmail.com

unread,
Mar 15, 2022, 10:28:24 AM3/15/22
to netlogo-users

I need to set 10 turtles in two horizontal/parallel rows.  My code so far is:

set xcor -4 + random 8

set ycor one-of [-2 2]

Also want to avoid two turtles on same patch.  So inserted:

move-to one-of patches with [not any? turtles-here]

But the above command blows up the row structure.  How can I alter/replace this command so the turtle stays on the ycor but moves on the xcor if it encounters another turtle on the same patch?

Thanks, RB

Michael Tamillow

unread,
Mar 15, 2022, 11:23:09 AM3/15/22
to rbsoc...@gmail.com, netlogo-users
What happens if there are 10 turtles on one patch? Or if there is a turtle between 4 patches and all patches are covered by turtles already.

This sounds like a problem where you are reallocating turtles, and I don't think it is as easy as just saying "get off my patch". Have you ever played musical chairs? Where is the open seat? It might be all the way on the other side...

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/b5e9a3f4-4219-4d1b-86c2-2bbd3db4cd30n%40googlegroups.com.

rbsoc...@gmail.com

unread,
Mar 15, 2022, 12:40:23 PM3/15/22
to netlogo-users
Let me try to clarify because this answer does not connect with my question.  I want two rows with 0-10 turtles in each row.  Their y position is fixed at -2 or 2.  Their x position is random between -4 and 4 with only one turtle per patch.
RB

James Steiner

unread,
Mar 15, 2022, 5:56:07 PM3/15/22
to rbsoc...@gmail.com, netlogo-users
You can  identify the patches, and create the turtles directly. 

Ask patches with [ abs pxcor = 2 and abs pycor <= 4 ]
[ sprout-turtles 1 
   [ ….
    ]
]
 
If you want only some of the patches to have a turtle, you can use the N-OF function to select a specific number of patches, or you can add 

And random 100 < whatever

To the WITH so that only some of the patches make turtles. 

~~James


James Steiner

unread,
Mar 15, 2022, 8:32:32 PM3/15/22
to rbsoc...@gmail.com, netlogo-users
Your “move-to” would have worked, if you had not included ALL the patches, you need to tell NetLogo exactly what to do. It did not know that you meant the turtles should move to only a few of the patches. 



--

rbsoc...@gmail.com

unread,
Mar 16, 2022, 8:24:09 AM3/16/22
to netlogo-users
Thanks JS.  Will try new sprout approach or rescue the old move-to strategy.
RB
Reply all
Reply to author
Forward
0 new messages