'Is there a way to check for turtles in a n patch radius of a turtle?
I want to make a drive-thru simulator where the cars automatically leave some space in between them and the car in front of them. Right now I am able to make sure that they don't move right next to each other by checking to see if the neighboring patches have another car on them. The trouble is, this still lets them overlap a little bit. How can I use NetLogo to make sure that if another car is in a car's 4 patch radius, the car doesn't move?
I want my cars to move east, then south, then east, then north, and then disappear. For this reason, my code looks like this thus far:
to move
ask turtles
[
if pycor > 12 and pxcor < -10 [
set heading 90 ; set the starting heading
if not any? turtles-on neighbors
[
if not (count turtles-on patches with [pxcor = -10] > 5) or pxcor != -14 [forward 1]
]
]
if pycor > -11 and count turtles-on patches with [pxcor < -8] < 13
[
if (pxcor = -10 and pycor < 15) or (pxcor = -14)
[
set heading 180 ; start moving downwards
if not any? turtles-on neighbors
[
if not (count turtles-on patches with [pycor = -11] > 5) or pycor != -8 [forward 1]
if num-dto = 2
[
if count turtles-on patches with [pxcor = -10] > count turtles-on patches with [pxcor = -14] and pxcor = -10
[
set heading 270
forward 4
set heading 180
]
]
]
]
]
if pycor = -11 and pxcor < 13 [
set heading 90 ; start moving to the right
if not any? turtles-on neighbors
[
if not (count turtles-on patches with [pxcor = 13] > 5) or pxcor != 12 [forward 1]
]
]
if pxcor = 13 and pycor < 12 [
; start moving up
if not any? turtles-on neighbors [set heading 0 forward 1]
]
;if pxcor > 12 and pycor > 11 [die]
]
end
I would really like it if there was a cleaner way to do this. Thanks for your help, I am very new to programming in NetLogo.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
