Netlogo Sprouting turtles at regular intervals - netlogo

I want to place turtles on each of the black patches(below Figure) at a specified step size:
Therefore if step size less more turtles will be created/sprouted and more step size will result in less turtles.
Code I use right now:
ask patches with [pcolor = black][sprout-dead-turtles wall-agents [set color red]]
This gives the following result:
Previous question asked on same lines:Netlogo Sprouting turtles spaced at less than one patch

Here:
to fill-wall [ d ]
set d precision d 1 ; make sure d is a multiple of 0.1
let n precision (d / 0.1) 0 ; interval at which to hatch
ask one-of possible-next-patches [
sprout 1 [
hatch 1
let i 0
let next-patch my-next-patch
while [ next-patch != nobody ] [
face next-patch
while [ patch-ahead 0.55 != nobody and [ pcolor ] of patch-ahead 0.55 = black ] [
fd 0.1
setxy precision xcor 1 precision ycor 1 ; avoid floating point imprecisions
set i i + 1
if i mod n = 0 [ hatch 1 ]
]
set next-patch my-next-patch
]
die
]
]
end
to-report possible-next-patches
let empty-black-patches patches with [ pcolor = black and not any? turtles-here ]
report empty-black-patches with [
count neighbors4 with [ member? self empty-black-patches ] = 1
]
end
to-report my-next-patch
report one-of possible-next-patches with [ member? self [ neighbors4 ] of myself ]
end
Here is how you would use it:
to setup
ca
; draw the background:
ask patches with [ abs pxcor != max-pxcor and abs pycor != max-pycor ] [ set pcolor grey ]
ask patches with [ pycor = max-pycor and abs pxcor <= 1 ] [ set pcolor white ]
set-default-shape turtles "circle 2"
fill-wall 0.3
end
Constraints:
d has to be a multiple of 0.1
world wrapping needs to be turned off

Related

expected input to be a number but got the TRUE/FALSE true instead

I want to write an evacuation with leader code in net-logo but i have this error (AND expected input to be a TRUE/FALSE but got the number 0 instead.)the error came from function (follow_leader). my project is that i evacuate an environment and evacuate it with the nearest leader from the crowd . the code is not perfect that because iam knew to netlogo .
this is my code
globals[ goal-x goal-y n number leader
percent_of_leader wall
window
door largecircle]
patches-own [path?
obstacle
goal]
turtles-own [direction
fast?
fear?
leader?
is-leader?
follower
other-nearby]
to setup
clear-all
set-default-shape turtles "person"
;create-turtles 50 [ set color yellow ]
;ask turtles [fd random 13 ]
drwa-walls
ask n-of population patches with [ pcolor = black]
[sprout 1
[ set color white
set size 0.9
set shape "person"
set leader? false
;set follower self
if xcor < 9 and ycor > 9 [set heading 0]
if xcor >= 9 and ycor >= -10[set heading -90]
if xcor > -12 and ycor < -10 [set heading 90]
if xcor <= -8 and ycor > -10 and ycor < 0 [set heading 180]
]]
choose-leaders
end
to choose-leaders
ask turtle 6
[
set leader? true
set color yellow
set size 1
set shape "default"
set leader self
set xcor 3
set ycor 10
set heading 0
]
end
to go
move-for
ask turtle 6[move-to-exit1
fd 1 ]
ask turtles with [shape = "person"][
ifelse (xcor < 9 and ycor > 9 ) [follow_leader] [move-to-exit1]
if xcor >= 9 and ycor >= -10 [move-to-exit2]
if xcor > -12 and ycor < -10 [move-to-exit3]
if xcor < -12 and ycor < -10 [move-to-exit3]
if xcor <= -8 and ycor > -10 and ycor < 0 [move-to-exit4]
;avoid obstcao
; avoid_obstacles
;ifelse [pcolor] of patch-ahead 1 = blue
; [ lt random-float 360 ] ;; We see a blue patch in front of us. Turn a random amount.
;[ fd 1 ] ;; Otherwise, it is safe to move forward.
; ifelse not is-patch? patch-ahead 3 or [ pcolor ] of patch-ahead 3 =
;blue or not is-patch? patch-ahead 2 or [ pcolor ] of patch-ahead 2 =
;blue or not is-patch? patch-ahead 1 or [ pcolor ] of patch-ahead 1 =
;blue
;[lt random-float 360 ]
;[fd 1]
; while [patch-ahead 1 = nobody]
;[
;lt random-float 360
;]
;ifelse [pcolor] of patch-ahead 1 = blue
; [ lt random-float 360 ] ;; We see a blue patch in front of us. Turn a random amount.
;[ fd 1 ]
; ifelse not is-patch? patch-ahead 3 or [ pcolor ] of patch-ahead 3 =
;white or not is-patch? patch-ahead 2 or [ pcolor ] of patch-ahead 2 =
;white or not is-patch? patch-ahead 1 or [ pcolor ] of patch-ahead 1 =
;white
; [lt random-float 360 ]
; [fd 1]
;ifelse not is-patch? patch-ahead 3 or [ pcolor ] of patch-ahead 3 =
;green or not is-patch? patch-ahead 2 or [ pcolor ] of patch-ahead 2 =
;green or not is-patch? patch-ahead 1 or [ pcolor ] of patch-ahead 1 =
;green
;[lt random-float 360]
; [fd 1]
]
reset-ticks
tick
end
to rt-random
while [patch-ahead 3 = nobody]
[
rt random 360
]
end
to avoide
ask turtles [
if [pcolor] of patch-ahead 1 = green
[lt random 360 fd 1]
]
end
to avoid_obstacles ;; all obstacles set as green patches
let i 1
while [[pcolor] of patch-ahead i != blue ]
[set i (i + 1) ]
if ([pcolor] of patch-ahead i = blue)
[
ifelse [pcolor] of patch-at-heading-and-distance (heading - 20) i + 1 = blue
[
ifelse [pcolor] of patch-at-heading-and-distance (heading + 20) i + 1 = blue
[
ifelse random 1 = 0
[ rt 360 ]
[ lt 360]
]
[ rt 360 ]
]
[lt 360]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;
to bounce
if [pcolor] of patch-at dx 8 = blue [
set heading (90)
]
if [pcolor] of patch-at 0 dy = blue [
set heading (-90)
]
end
;;;;;;;;;;;;;;;;;;;;;;;
to move-for
ask turtles with [shape = "person"][fd 1]
end
to drwa-walls
draw-exit1
draw-exit2
draw-exit3
draw-exit4
;rows x
ask patches with [pxcor <= 30 and pxcor >= 0 and pycor = -10]
[set pcolor blue]
ask patches with [pxcor >= -30 and pxcor <= 0 and pycor = 9]
[set pcolor blue]
;coilmn
;ask patches with [pycor <= 9 and pycor >= -10 and pxcor = 0]
;[set pcolor green]
;ask patches with [pycor <= 4 and pycor >= 0 and pxcor = 0]
;[set pcolor green]
;circle shape
ask patch -14 -9 [
set largecircle patches in-radius (2)
]
;set color of largecircle patches green
ask largecircle [
set pcolor green
]
ask patch 16 16 [
set largecircle patches in-radius (2)
]
;set color of largecircle patches green
ask largecircle [
set pcolor white
]
end
to draw-exit1
;exits at top of concourse area, where turtles will leave
set goal-x -1
set goal-y -30
ask patch goal-x goal-y [
sprout 1 [ set pcolor red
set shape "square"
]
]
end
to draw-exit2
set goal-x -1
set goal-y 30
ask patch goal-x goal-y [
sprout 1 [ set pcolor red
set shape "square"
]
]
end
to draw-exit3
set goal-x -30
set goal-y -6
ask patch goal-x goal-y [
sprout 1 [ set pcolor red
set shape "square"
]
]
end
to draw-exit4
set goal-x 30
set goal-y 4
ask patch goal-x goal-y [
sprout 1 [ set pcolor red
set shape "square"
]
]
end
;;;;;;;;;;;;;;;;;;;;;;exit goals;;
to move-to-exit1
facexy -1 30
end
to move-to-exit2
facexy 30 4
end
to move-to-exit3
facexy -1 -30
end
to move-to-exit4
facexy -30 -6
end
;;;;;;;;;;;;;;;;;;;;;;;;;;
;to follow-leader
;if not leader? ;; we only want to ask non-leaders
;[let nearby-leaders turtles with [leader? and distance myself < 3] ;; find nearby leaders
;if any? nearby-leaders ;; to avoid 'nobody'-error, check if there are any first
; [ set heading (towards min-one-of nearby-leaders [distance myself]) ]] ;; then face the one closest to myself
; end
;;;;;;;;;;;;;;;;;;;;;;;;;;
to follow_leader
let nearby-leaders turtles with [is-leader? and distance myself < 10] ;; nearby leaders
if any? nearby-leaders[
face min-one-of nearby-leaders [distance myself]
fd 0.5]
end
In the future, please only provide relevant code. For NetLogo, that is usually the procedure that throws the error (or doesn't work correctly etc) and whichever procedure calls it.
In your case, this is the procedure you mentioned:
to follow_leader
let nearby-leaders turtles with [is-leader? and distance myself < 10]
if any? nearby-leaders[
face min-one-of nearby-leaders [distance myself]
fd 0.5]
end
So the and that is throwing the error must be [is-leader? and distance myself < 10] (also, please state which line if you know it). My guess would be that you haven't initialised the variable is-leader? so it is 0 (the default value) instead of either true or false.
If this is the problem, wherever you creates turtles, initialise with set is-leader? false

how to solve "no such plot" error while plotting in netlogo?

I am new to netlogo and facing the following error while plotting the mean of properties associated with patches:
no such plot: " patch 0 0"
error while patch 0 0 running SET-CURRENT-PLOT
called by procedure GO
called by Button 'go'
But patch 0 0 clearly exists and is predefined in the code as follows:
'globals [ k ] ; interaction constant
patches-own [ a b c d' e' ] ; state variables of properties
; a is the Proportion and variety of Blend of land use
; b is the Land uses with supportiveness for complimentary activities
; c is the Vehicular and Pedestrian Intensity
; d is the Intensity of Nodes in urban web
; e' is the Frequency of Enforced Vigilance
to setup
clear-all
set k initial-k
setup-patches
reset-ticks
end
to setup-patches
ask patches [ set pcolor yellow ] ; defines the patches as built up in an area
; to define road patches (horizontal)
ask patches [ if pycor = 0 [ set pcolor grey ] ]
ask patches [ if pxcor = 0 [ set pcolor grey ] ]
ask patches [if pycor = 9 [ set pcolor grey ] ]
ask patches [ if (pycor = 6) and (pxcor < -4 )[ set pcolor grey ] ]
ask patches [ if (pycor = 3) and (pxcor < -4 ) [ set pcolor grey ] ]
ask patches [ if (pycor = 4) and (pxcor > 3 ) [ set pcolor grey ] ]
ask patches [ if (pycor = -6) and (pxcor > 7 ) [ set pcolor grey ] ]
; to define road patches (vertical)
ask patches [ if (pycor > 0) and (pxcor = -10 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 0) and (pxcor = -5 ) [ set pcolor grey ] ]
ask patches [ if (pycor < 0) and (pxcor = -7 ) [ set pcolor grey ] ]
ask patches [ if (pycor < 0) and (pxcor = -3 ) [ set pcolor grey ] ]
ask patches [ if (pycor < -3) and (pxcor = 4 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 3) and (pxcor = 4 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 0) and (pxcor = 7 ) [ set pcolor grey ] ]
; to define nodes as patches
ask patches [ if pxcor = 0 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -3 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -7 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = 4 and pycor = 4 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 4 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = 4 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = 0 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 6 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 3 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 6 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 3 [ set pcolor red ] ]
; to set intial values of properties for patches
ask patches with [pcolor = yellow] [ set a random-float 0.9] ; initial a
ask patches with [pcolor = yellow] [ set b random-float 0.9] ; initial b
ask patches with [pcolor = grey] [ set c random-float 0.9] ; initial c
ask patches with [pcolor = red] [ set d' random-float 0.9] ; initial d'
ask patches with [pcolor = grey] [ set e' random-float 0.9] ; initial e'
end
to go
tick
if ticks >= 52 [ stop ]
ask patches with [pcolor = yellow]
[
let fc [c] of one-of patches with [pcolor = grey] ; reports c of any one
grey patch of neighbours
let fe' [e'] of one-of patches with [pcolor = grey] ; reports e' of any one grey patch of neighbours
let fd' [d'] of one-of patches with [pcolor = red] ; reports d' of any one red patch of neighbours
if a < 0.1 [ set a 0.1
if a > 0.9 [ set a 0.9 ] ]
if b < 0.9 [ set b b + (k * a) + (k * fc) + (k * fd')
if b > 0.9 [ set b 0.9 ] ]
if b > 0.1 [ set b b - (k * fe')
if b < 0.1 [ set b 0.1 ] ]
]
ask patch 0 0
[ let fa [a] of one-of patches with [pcolor = yellow]
let fb [b] of one-of patches with [pcolor = yellow]
let fc [c] of one-of patches with [pcolor = grey]
let fe' [e'] of one-of patches with [pcolor = grey]
let eeep (fa + fb + fc + d' + 1 / fe') / 5
let deep (1 / fa + 1 / fb + 1 / fc + 1 / d' + fe') / 5
output-print eeep
output-print deep
set-current-plot " patch 0 0"
set-current-plot-pen "eeep"
plot eeep
set-current-plot-pen "deep"
plot deep
]
end'
I have been trying to solve this for quite sometime and will be grateful for any help.
Thank you!
The patch named patch 0 0 exists. However, that does not mean that the plot named " patch 0 0" exists. You have simply mistyped the name of the plot (perhaps you have the incorrect number of spaces).
I suggest you rename your plot to something that doesn't look like a patch identifier to reduce confusion. Try something like "plot-0-0", renaming both on the interface in the plot dialogue, and also in the code.

Color progression issue in netlogo

I have three different turtles: red, white, and green. I am trying to get these turtles to couple up (like people in relationships) and then uncouple. While a red turtle is coupled with a green or white turtle I want the patch color to sometimes randomly change colors, but for some reason the patch color color progression is not working.
to go
ask turtles
[ if coupled? = true
[ set couple-length couple-length + 1 ] ]
ask turtles
[ if coupled? = false
[ move ] ]
ask turtles
[ if coupled? = false and shape = "person righty" and (random-float 10.0 < coupling-tendency)
[ couple ]
let potential-intervener one-of (turtles-on neighbors) with [ green-dotter? = true]
if (coupled? = true and potential-intervener != nobody and "person righty" = true)
[ifelse (random-float 10.0 < resting-tendency)
[;;decides to stay
ask potential-intervener [move-to patch-here] ;; this is possibly what is causing the lack of intervention?
; does not intervene, start the color progression
ifelse (random-float 10.0 < intervening-tendency)
[;; intervenes
uncouple
]
[set couple-length couple-length + 1 ;; increments the couple length by 1
if (couple-length = 2)
[
ask patch-here [set pcolor yellow]
ask patch-at -1 0 [set pcolor yellow] ]
if (couple-length = 4)
[
ask patch-here [set pcolor orange]
ask (patch-at -1 0) [set pcolor orange] ]
if (couple-length = 6)
[
ask patch-here [set pcolor red]
ask (patch-at -1 0) [set pcolor red] ] ]
]
[
;;decides to move
ask potential-intervener [move]
set couple-length couple-length + 1 ;; increments the couple length by 1
if (couple-length = 2)
[
ask patch-here [set pcolor yellow]
ask patch-at -1 0 [set pcolor yellow] ]
if (couple-length = 4)
[
ask patch-here [set pcolor orange]
ask (patch-at -1 0) [set pcolor orange] ]
if (couple-length = 6)
[
ask patch-here [set pcolor red]
ask (patch-at -1 0) [set pcolor red] ] ]
]
; will green dotter intervene?
ifelse (random-float 10.0 < intervening-tendency)
[;; intervenes
uncouple
]
[;; does not intervene, start the color progression
set couple-length couple-length + 1 ;; increments the couple length by 1
if (couple-length = 2)
[
ask patch-here [set pcolor yellow]
ask patch-at -1 0 [set pcolor yellow] ]
if (couple-length = 4)
[
ask patch-here [set pcolor orange]
ask (patch-at -1 0) [set pcolor orange] ]
if (couple-length = 6)
[
ask patch-here [set pcolor red]
ask (patch-at -1 0) [set pcolor red] ] ]
]
check-sliders
tick
end
For one thing, your line if (coupled? = true and potential-intervener != nobody and "person righty" = true) is inside a command block that is only reached through if coupled? = false and shape = "person righty" and (random-float 10.0 < coupling-tendency). That is, it doesn't get reached because coupled? would need to be both true and false. Better formatting would make this immediately clear. I have reformatted the top part of your code so you can see this:
to go
ask turtles
[ ifelse coupled?
[ set couple-length couple-length + 1 ] ]
[ move
if shape = "person righty" and (random-float 10.0 < coupling-tendency)
[ couple ]
let potential-intervener one-of (turtles-on neighbors) with [ green-dotter?]
if (coupled? and potential-intervener != nobody and "person righty")
[ ifelse (random-float 10.0 < resting-tendency)
[;;decides to stay
ask potential-intervener [move-to patch-here]
A couple of other notes. You don't need to say if coupled? = true, it is sufficient to say if coupled?. Since you have the same colouring code three times, it would be better to have it only once as a separate procedure and call it from the three locations, so it is much easier to change.

NetLogo, How can I make the agent move is a specific area and then colour the area while it moving without stucking?

the problem
In this code I try to make the agent to move in the yellow area which is = 47, and to colour the patches to be "red", but the problem is that the agent stuck in the red coloured area.
I want the agent to move and to colour until all the patches become red, it is like cleaning.
Please guys, I need help please....
;;leftcheck and rightcheck has been declared in globals
if (behaviour = "RCleaner")
[
ifelse any? patches in-cone 2 10 with [pcolor = 47]
[ fd random-float 0.03 ]
[
rt 2
ifelse any? patches in-cone 2 10 with [pcolor = 47]
[ set rightcheck true ] [ set rightcheck false ]
lt 2
ifelse any? patches in-cone 2 10 with [pcolor = 47]
[ set leftcheck true ] [ set leftcheck false ]
rt 2
if leftcheck [ lt 1 ]
if rightcheck [ rt 1 ]
fd 0.01
]
set heading heading + random 1 - random 1
ask patch-here [ set pcolor red]
]

Avoid visited patch netlogo

Sir i am working on a project and time to time i use to post questions here related to that problem. I have created a simulation scenario i which turtles (robots) move around in the space and also each robot keep track of its visited patches. On the movement if patch-ahead 1 is visited patch then i need to turn the robot to 45 degree left and check again for patch-ahead until it checks all 8 neighbors if any one of the 8 is UN-visited then it should move to that patch and continue its exploration. But if all 8 are visited then it should move to patch which is in front of current heading after checking the all 8 neighbors no matter it is visited.
Here is the piece of code i am using.
breed [robots robot ]
robots-own[ state memory ]
patches-own [ is-obstacle? ]
to setup
__clear-all-and-reset-ticks
create-robots num [
set memory (list patch-here)
]
draw-obstacles
ask patches [if pxcor = 0 and pycor = 0 [ set pcolor black ]]
end
to draw-obstacles
ask patches with [ pxcor mod 6 = 0 and pycor mod 6 = 0 ] [set pcolor red set is-obstacle? true]
; set pcolor red
ask patches [ ifelse pcolor = red [ set is-obstacle? true ][ set is-obstacle? false ] ]
ask patches with [ count neighbors != 8 ] [ set pcolor red set is-obstacle? true ]
end
to make-obstacle
if mouse-down?
[ ask-concurrent patches
[ if ((abs (pxcor - mouse-xcor)) < 1) and ((abs (pycor - mouse-ycor)) < 1)
[set pcolor red]]
]
end
to remove-obs
if mouse-down?
[ ask-concurrent patches
[ if ((abs (pxcor - mouse-xcor)) < 1) and ((abs (pycor - mouse-ycor)) < 1)
[set pcolor black]]
]
end
to go
ask patches [if ( pcolor = red )[set is-obstacle? true]]
ask patches [if ( pcolor = black )[set is-obstacle? false]]
ask-concurrent robots ; wanderers instructions
[
rt random-float rate-of-random-turn
lt (rate-of-random-turn / 2)
set-state
move-robots
]
tick
end
to move-robots ;;turtle proc
if (not member? state ["disperse" "explore"]) [
error "Unknown state"
]
if (state = "disperse") [
disperse
]
if (state = "explore") [
explore
]
end
to set-state ;;turtle proc
ifelse (any? other turtles in-radius 1) [
set state "disperse"
] [
set state "explore"
]
end
to disperse ;;turtle proc
avoid-obstacle
move1
; move-to one-of patch-set [neighbors] of neighbors
end
to explore
move
;search-open-room
avoid-obstacle
;move-to one-of neighbors
end
to move
fd speed
set memory lput patch-here memory
if ( (member? patch-ahead 1 memory) or ([is-obstacle?] of patch-ahead 1 ) )
[ lt random 45
]
end
to move1
fd speed
end
to avoid-obstacle
set memory lput patch-here memory
if ([is-obstacle?] of patch-ahead 1 )
[
ifelse [is-obstacle?] of patch-at-heading-and-distance (heading - 5) 1
[
ifelse [is-obstacle?] of patch-at-heading-and-distance (heading + 5) 1
[
ifelse random 1 = 0
[ rt 40 ]
[ lt 40 ]
]
[ rt 60 ]
]
[lt 60]
]
end
to search-open-room
ask robots[
ifelse ([is-obstacle?] of patches in-cone 2 150 )
[ rt 45 ] [ move ]
]
end
But in the move procedure i am just able to lt random 45. How to change it according to above mentioned scenario. I tried many with while loop and repeat statement but code does not seems to be working for me.
You could do it using while or repeat, but I think this a case where recursion works well.
The idea is to have a procedure that keeps on calling itself until the desired state is achieved:
to turn-until-free [ n ]
let target ifelse-value (patch-ahead 1 = patch-here)
[ patch-ahead 2 ]
[ patch-ahead 1 ]
let seen? member? target memory
let obstacle? [ is-obstacle? ] of target
if-else n < 8
[ if seen? or obstacle? [ lt 45 turn-until-free n + 1 ] ]
[ if obstacle? [ lt 45 turn-until-free n + 1 ] ]
end
The n parameter represents the number of calls that we've already made to the procedure (or, in other words, the number of neighbors that we've checked so far). When you call the procedure for the first time, you start with n = 0:
to move
turn-until-free 0
fd 1
set memory lput patch-here memory
ask patch-here [ set pcolor black + 2 ] ; just to show what's visited
end
A couple of things that were not part of your original specification:
It can happen that patch-ahead 1 is the same patch that the robot is already on. A patch has sides of length 1, but its diagonal is a bit longer (√2). So if a robot is in the bottom left corner, for example, and facing towards the top right, patch-ahead 1 = patch-here will be true. In these cases, we look a bit further and set the target to patch-ahead 2.
It can happen that, after checking all 8 neighbors, you end up facing an obstacle. If that's the case, you need to keep on turning until you're clear of the obstacle. And as a matter of fact, doing this takes care of obstacle avoidance nicely, and you might be able to get rid of the avoid-obstacle procedure in your code.
Edit:
Here is the code needed (in addition to the two procedures above) for a fully working example:
breed [ robots robot ]
robots-own [ memory ]
patches-own [ is-obstacle? ]
to setup
ca
ask patches [ set is-obstacle? false ]
ask patches with [ pxcor mod 6 = 0 and pycor mod 6 = 0 ] [
set is-obstacle? true
set pcolor red
]
ask n-of 5 patches with [ not is-obstacle? ] [
sprout-robots 1 [ set memory [] ]
]
reset-ticks
end
to go
ask robots [ move ]
tick
end
If you are having trouble with runtime errors or other unwanted behavior, I suggest you start from this and add back whatever else you had in your simulation one piece at a time. Then, you can see exactly where the problem comes from.
I also changed if-else n < 7 for if-else n < 8 in the turn-until-free procedure above. This way, the robot comes back to its original heading if all neighbors are explored instead of turning a bit right. This avoids going in circles once the whole territory is explored.