To create fixed number turtles each with separate headings on fixed ycor and equidistant xcor - netlogo

I want to create 4 turtles on fixed pycor (like pycor = 10) and even spacing xcor over that pycor; and also I want to make the headings of each turtles separate from other. The display is like
............. O ............. O .............. O ........... O ............
(heading 45) (heading 90) (heading 230) (heading 180)
O is the turtle here. My code is as below.
ask n-of 4 patches with [ pcolor = 18 and pycor = 10 ] [
sprout-turtles 1 [
set shape "default"
set color blue
set size 2
set heading one-of [90 270]
]
]
With this code turtles are created but many time with same heading, sometimes on same patch, sometimes neighboring patch as shown below
..........OOO...................O or .........OO..........O.........O...
but this i don't want. Should i have to use Create turtles four times separately specifying xcor, ycor and heading? Actually i don't want to use it four times. Please any suggestion and help? Thanks a lot.

Since the only thing you are taking from the patch to the turtle, you may as well just use create-turtles instead of sprout-turtles and then put them where you want. Typically, sprout is used when the particular patch meets relevant conditions - such as having lots of resources. Also, since you want specific values, using one-of or n-of will not work because they randomly select.
Instead you want something more like this (not tested):
let gap 15 ; spacing between turtles
let directions [45 90 230 180] ; heading values
let ii 0 ; counter / index
repeat 4
[ create-turtles 1
[ setxy (0 + ii * gap) 10
set shape "default"
set color blue
set size 2
set heading item ii directions
]
set ii ii + 1
]

Related

NetLogo Battle Simulation: Placing soldiers in between specific coordinates?

I'm new to NetLogo and I'm unsure of how to place 300 spartans in a narrow row. Let's say an area of 2x5 patches, turtles overlapping one another. I have tried using sprout, this achieved the specific coordinate requirements but the turtles are only one per patch.. Here is some code I have.
ask patches with [pxcor > 0 and pycor > -2 and pycor < 2]
[ sprout 1 [ set color red ] ]
or
to setup-spartans
create-spartans 300
set-default-shape turtles "person"
ask spartans
[ setxy random-xcor -3 ;; makes only a single row and goes across entire screen
;; (I need it to be in a specific area)
set heading 180
set color red ]
end
How about something like this?
create-spartans 300 [
set xcor -2 + random-float 5
set ycor -1 + random-float 2
]

Turtles hatch when crossing a line

I want my turtles to hatch (= make one more turtle) when they cross a specific line. I have tried the command ifelse?, and I can get it to work on a simple model, when my turtles randomly wanders: If they move to a patch on the left side (xcor < 0) they die, if they make a move to a patch with xcor > 0 they hatch 1.
But I want the proces to be linked to witch patch they come from. If they stand on a patch with xcor < 0 and moves to another patch with xcor < 0 they shall die - but if they change xcor from negative to positive - they should multiply (= hatch 1).
My problem is: Is it possible to write a code-string that "remembers" the turtles position one tick before and use it to either let the turtle die og multiply?
{
to setup
clear-all
create-turtles 20
ask turtles [set size 2
set heading random 45 ;; turtle is now facing northeast
setxy random-xcor random-ycor
set color white
set shape "person"]
end
to go
ask turtles
[ rt random 360 ; turns in a random direction
fd 4 ;; all turtles move forward one step
rt random 180 ;; ...and turn a random amount
fd 4
lt random 180
]
ask turtles
[ifelse pxcor > 0
[hatch random 2]
[die]]
end }
You can use a turtle variable to give each turtle a memory.
turtles-own
[
old-xcor
]
Just before the turtle moves, assign ‘xcor‘ to that variable.
To move-turtle
Set old-xcor xcor
< Your movement code >
if old-xcor < 0
[ Ifelse xcor < 0
[ Die ]
[ Hatch 1 ]
]
End

How to change from Random placement of turtles to fixed placement

Grasses (green leaf) are randomly placed across the world with setxy random-xcor random-ycor. What I want is for its position to be fixed (e.g., every leaf will be placed 10 units apart per line). Can anyone helped me how to alter my setxy, or is there any other way. Thank you very much
Maybe the mod modulus operator will do the trick for you. For example:
to setup
ca
resize-world 0 50 0 50
ask patches with [ pxcor mod 10 = 0 and pycor mod 10 = 0 ] [
sprout 1 [
set shape "leaf"
set color green
]
]
reset-ticks
end

How can I clump my turtles at random points in my model?

In my model I want to be able to clump my agents but have the location of this clumping to change.
At the moment I can get them to clump using
setxy random 4 random 4
but that is located around the origin of the simulation space. How can I vary this so they clump at a different point for each model run?
Thanks
I like using asking patches to do this sort of thing but you could just change your code to.
The set the clump by hand method
let clump-X random-pxcor
let clump-Y random-pycor
crt 100 ;; or however many you want to make the create-turtles in your code
[
...
setxy (random 4 + clump-X) (random 4 + clump-Y)
]
The patch and sprout method
ask one-of patches
[
sprout 100
[
set xcor xcor + random 4
set ycor ycor + random 4
]
]

NetLogo: creation of lattice/grid resources world without using turtles?

I would like to create a "gridded" world of resources, in specific distance from the central patch and keep distances equal between these patches. Due to calculation demand, I prefer not to use turtles to create this patchy world. I expect to create something like this:
Equally, I would like to define distance between patches as a slider tool. I was wandering to use turtle lattice walk and then turn patches to different color, but is there any way how to do that without turtles ? Thanks for any suggestions !
My not totally working exemple:
to setup
clear-all
ask patches [set pcolor green]
foreach [5 10 15] [
repeat 9 [
make-red-patch ?
]
]
reset-ticks
end
to make-red-patch [dist]
crt 1 [
fd dist
rt 90
while [pcolor = red] [
bk dist
rt 90
fd 2 * dist
]
set pcolor red
die
]
end
I am not exactly sure what you need, first you mentioned you don't want to use turtles and in your own answer you have problem with the patch without a turtle.
There might be another way to approach this question:
to setup
clear-all
ask patches with [pxcor mod Grid = 0 and pycor mod Grid = 0] [set pcolor red]
end
And these are examples with different Grid size:
After more detailed search I found my answer here: http://netlogo-users.18673.x6.nabble.com/Setting-up-agents-in-a-grid-formation-td4864083.html
They consider to distribute turtles, not patches and then attribute patches turtles' qualities.
Here is the code:
to setup
clear-all
create-turtles 1
[ let $n 0 ; actual number of turtles on this patch
let $s 0 ; current number of turtles on a side of square pattern - 1
set heading 0
ask patch-here [set pcolor red]
repeat 16 ; number of needed turtles
[ hatch 1 jump Grid ; make one turtle and move
set $n $n + 1 ; increment count of curent side
ask patch-here [set pcolor red]
if $n > $s ; if side finished...
[
right 90 set $n 0 ; turn and reset count
ask patch-here [set pcolor red]
; if headed up or down, increment side count
if heading mod 180 = 0 [ set $s $s + 1
]
]
]
die
]
end
which produce:
I still don't know how to deal with 1 patch without turtle (bottom right corner), but this exemple helped me a lot ! :)