Question

In this model all it does is turtle will find a seat(red patch for available and yellow for taken). And once the seats are all occupied it all will stop.

Now how to make some of the turtles move again? Like if it is seated it will move again and try go another place or it will go out.

breed [kids kid]
breed [adults adult]
breed [oldies old]    
kids-own [step]    
adults-own [step]    
oldies-own [step]
turtles-own [seated?]

to setup

  __clear-all-and-reset-ticks

  ask patches [setup-world]
  ask patches with [pcolor = red ][set plabel count turtles-here]
  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]

  ask oldies[

    set color blue
    set size 1                                    
    setxy -10 0
    set heading random-float 45
    rt 45 - random-float 90]
end
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

   if count patches
    with [pcolor = yellow and any? other turtles-here] = 10
    [stop]

   ask kids with [seated? = 0][

rt random 10
fd 2

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

        ]     

      ]

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


          ]
     ]

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

          ] 
  ]
tick  
end
Was it helpful?

Solution

Just the way you asked non-seated turtles by ask ... with [Seated? = 0] you can ask others by ask ... with [Seated? = 1]

However, I will suspect that they will go in a loop, because they are close to the bench ans bench is empty, so as soon as they stand up they will sit on the same spot again. Maybe you can have a memory [] which stores last few moves and if there is a seated position, say in last 10 items it will choose not to sit. I am not sure what are your requirements, this is just an example.

      ask adults with [seated? = 1]
          [
  ; Stand up set seated? = 0
  ; go around         
          ]

       ask kids with [seated? = 1]
          [
  ; Stand up set seated? = 0
  ; go around         
           ]

       ask oldies with [seated? = 1]
          [
    ; Stand up set seated? = 0
    ; go around
         ]

Update:

I have changed your code, its not much different from your code, but it has memory function to make sure turtles move around after leaving a bench and are not going to sit on same bench again and to some degree avoid walls (you need to improve the avoiding since step size is different for each agent):

   breed [kids kid]
breed [adults adult]
breed [oldies old]
Globals [out-of-boundry]    
turtles-own [seated? memory step]
to setup
  clear-all 
  reset-ticks
  ask patches [setup-world]
  ask patches with [pcolor = red ][set plabel count turtles-here]
  set out-of-boundry patches with [ pycor > 10 or pxcor < -10 or pxcor > 10 or pycor < -10 or pcolor = brown]
  set-default-shape turtles "person"
  create-kids 5 [
    set memory [] 
    set seated? false
    set color green
    set size 1              
    setxy -10 0
    set heading random-float 90
    rt 45 - random-float 90
    set step 2
  ]
  create-adults 5 [
    set memory [] 
    set seated? false
    set color orange
    set size 1                                    
    setxy -10 0
    set heading random-float 45
    rt 45 - random-float 90
    set step 1.5
  ] 
  create-oldies 5 [
    set memory [] 
    set seated? false 
    set step 1
    set color blue
    set size 1                                    
    setxy -10 0
    set heading random-float 45
    rt 45 - random-float 90
  ]
end
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

  if count patches with [pcolor = yellow and any? other turtles-here] = 10 [stop]

  ask turtles [
    set memory lput Seated? memory
    restrict-memory
    ifelse seated?
    [stand-up ]
    [ move-in-the-brown-area step
      sit]

]
tick  
end






to move-in-the-brown-area [step-size]

  ifelse not member? patch-ahead step-size out-of-boundry [

    fd step-size
    rt random 10

  ]
  [ face one-of patches with [pcolor = white]
    fd step-size

  ]

  If  member? patch-here out-of-boundry[ 
    let target patch -10 0 
    face target 
    fd step-size]

end

to restrict-memory  
  ;assume your memory-limit is 5
  let memory-limit 5
  if length memory >= memory-limit
  [ set memory but-first memory ]
end


to stand-up 
  if seated? 
  [ set seated? false
    set pcolor red
    fd 1
  ] 




end

to sit
  if pcolor = red and not any? other turtles-here with [not member? true memory][
    move-to patch-here
    set seated? true
    set pcolor yellow
  ]
end

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top