Search code examples
countdownnetlogo

turtles "sleeping" for half a day


I have a group of turtles, monkeys in my model, who are supposed to be moving for half a day and sleeping for the other half. When they are moving they eat fruit and gain energy from that, they also lose energy when they move, if they have -10 of energy they starve (they start with 100 of energy) I am assuming a tick is a day. What happens now is that after I added the move and sleep states, they all starve after only one tick or two and I can't figure out why. I think the problem is with the count-down or ticks... Part of the code below. Thanks a lot!

to move 
  ask monkeys [
  move-monkeys
   set count-down count-down - 1   
   if count-down <= 0
   [set state task sleep
    set count-down 0.5 + 0.5 
   ] 
  ]

 end

to sleep 
   ask monkeys [
  set count-down count-down - 1
  set label count-down
  if count-down <= 0 
  [set state task move 
   set label ""
     set count-down 0.5 + 0.5 
  ] 
  ]
 end 
to move-monkeys

  ask monkeys [

     set best-patch patches with-max [calories] in-radius 3

    right random 360 fd 1

     set energy energy - 10 ;; monkeys lose energy when they move. 

    if is-patch? best-patch 
     [ ifelse patch-here = best-patch   
[eat-fruit] 

 [evaluate]]


  if energy < 10
      [output-print "starve"
      set nostarve nostarve + 1
      die] 

    ]


          end 

Solution

  • also posted on Netlogo user group - code there.

    In your model it sounds like you are getting monkeys to move around between ticks. So for each cycle a monkey moves for say 12 hours. you will not see all of this though, unless you ask monkeys to update the display - which might be helpful while you fault find. Only use a few monkeys if you do though.

    A few of things i can see

    1) Why do you need a sleep and a move cycle? Are they regaining energy while sleeping? If not, just ask them to move for 12 of the 24 hours and don't do anything else otherwise. When they stop they reset the count to 12 or how every many hours they move for. Something like

    ask monkeys
    [
    ifelse my-time >=0  
    [move
    set my-time my-time - 1]
    [set my-time 12]                   -sets my-time 12 and stops whats it's doing
    ]
    

    2) You ask them to look for them best patch, but then you get them to move randomly. Do you want them to move to the best patch? If so use move-to one-of best patches.