Avoid patch with netlogo turtle

Can anyone help me with this. I am trying to simulate a situation in which a turtle will accidentally sit on a bench (red patch), and if the bench is busy, she will find another. 1 turtle: 1 patch

breed [kids kid]

breed [adults adult]

breed [oldies old]

kids-own [step]

adults-own [step]

oldies-own [step]

to setup

  __clear-all-and-reset-ticks

  ask patches [setup-world]

  set-default-shape turtles "person"

  create-kids number-of-kids 

  create-adults number-of-adults 

  create-oldies number-of-oldies

  ask kids[

    set color green
    set size 1              
    setxy -10 0
    set heading random-float 90
    rt 45 - random-float 90]

  ask adults[

    set color orange
    set size 1                                    
    setxy -10 0
    set heading random-float 45
    rt 45 - random-float 90]



to setup-world

  set pcolor white

   if ( pxcor = 10 ) and ( pycor < 10 and pycor > -11 ) [ set pcolor brown ]

   if ( pxcor = -10 ) and ( pycor < 10 and pycor > 1 ) [ set pcolor brown ]

   if ( pxcor = -10 ) and ( pycor < -1 and pycor > -11 ) [ set pcolor brown ]

   if ( pycor = 10 ) and ( pxcor < 11 and pxcor > -11 ) [ set pcolor brown ]

   if ( pycor = -10 ) and ( pxcor < 10 and pxcor > -11 ) [ set pcolor brown ]


   if ( pxcor = 8 ) and ( pycor < 8 and pycor > 2 ) [ set pcolor red ]

   if ( pxcor = 8 ) and ( pycor < -2 and pycor > -8 ) [ set pcolor red ]

end


to go

   ask kids[

    if pcolor = red and not any? other turtles-here[
      move-to patch-here
      stop]
    fd 1

    ifelse pcolor = red and any? other turtles-here
      [rt random 90]
      [fd 1]



  ]



  ask adults[

    if pcolor = red and not any? other turtles-here[
      move-to patch-here
      stop]
    fd 1

    ifelse pcolor = red and any? other turtles-here
      [rt random 90]
      [fd 1]



  ]







  tick



end
+4
source share
1 answer

you already did most of the coding correctly, I checked your code and it works fine except for your second condition in your go function for children and adults.

One way to do the same is to add a turtle, such as a sitting one? Variable and make it false during initialization and make it true if the turtle is sitting on the bench. And just ask turtles with false seated? look for another bench.

   turtles-own [seated?]

      ask kids with [not seated? ][


rt random 10
fd 1

        if pcolor = red and not any? other turtles-here [
          move-to patch-here
          set seated? true]


      ]



      ask adults with [not seated?]
      [
    rt random 10
    fd 1
        if pcolor = red and not any? other turtles-here[
          move-to patch-here
          set seated? true]
     ]

, pacth,

ask patches with [pcolor = red ][set plabel count turtles-here]
+3

All Articles