avoiding patch that has turtle netlogo

Viewed 3787

Can anyone help me with this. I'am trying to simulate a situation wherein the turtle will randomly sit on a bench (red patch) and if the bench is occupied it will find another one. 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
1 Answers
Related