Set energy to go down as my turtle breeds begin moving faster and set a limit to how large a turtle can grow

55 Views Asked by At

Currently the sharks and fish continue growing in size and speed what I'm attempting to do is have the energy for the fish and sharks go down more as they continue to move faster as as demonstrated with forward energy over 7 I'm also attempting to set a limit on the size the sharks and fish can reach

To go
  update-plots
  tick
   ask sharks[
    set Btimer (Btimer - 1)
    forward Energy / 7
    right random 80
    left random 80
      ask fishes[die]
      set Energy (Energy + 7) ;this essentially controls speed making it so it will go faster if enough energy is collected
       set size size + 0.1 ; this makes it so the sharks will continue growing and I'm not sure how to set a limit to the size they can grow to be
    ]
    set Energy (Energy - 1)
    if (Energy <= 0)[                                    
      die
    ]
    if any? sharks-on patch-ahead 0 and Btimer <= 0[  
      ask sharks-on patch-ahead 0 [
        set Btimer (Btimer + 400 - random 200)
        set Energy (Energy - 50)
      ]
       hatch 10 [                                         
      ]
    ]
  ]
end
1

There are 1 best solutions below

0
On

The basic problem appears to be that you increase speed every tick but don't have any code to stop growth. Here is one way to do it - you just have a test to see if the shark is fully grown:

to go
  update-plots
  tick
  ask sharks
  [ set Btimer (Btimer - 1)
    forward Energy / 7
    right random 80
    left random 80
    ask fishes [ die ]
    if energy <= max-energy      ; here is where you set the condition
    [ set Energy (Energy + 7) ; also increases speed
      set size size + 0.1
    ]
  ]
  ask sharks                       ; There must be an ask here, otherwise error message
  [ set Energy (Energy - 1)
    if (Energy <= 0) [ die ]
    if any? sharks-on patch-ahead 0 and Btimer <= 0
    [ ask sharks-on patch-ahead 0
      [ set Btimer (Btimer + 400 - random 200)
        set Energy (Energy - 50)
      ]
      hatch 10 [ ]
    ]
  ]
end

But this is primarily a design issue - what are you trying to represent with stopping the growth? Is it that the shark has become an adult, in which case a condition like the one I have inserted is the right approach.

Or is it that you expect growth to stop naturally for some other reason? For example, you might be thinking that the shark will stop growing because it runs out of food. However, the growth happens whether there is food or not. If you wanted the growth to happen only if there is food (fish) where the shark is, then you would do something like this:

to go
  ....
  ask sharks with [any? fishes-here]  ; restrict to sharks with food
  [ set Btimer (Btimer - 1)
    forward Energy / 7
    right random 80
    left random 80
    ask fishes-here [ die ]          ; since they are shark food
    set Energy (Energy + 7)          ; max not required, grows if food available
    set size size + 0.1
  ]
  ....
end

Just a general comment, agent-based models are hard to debug because the complex interactions between agents, environment and behaviour means that it is not always clear which bit of the code is causing a problem, and the logic can be difficult. The best way to deal with this is to code in smaller pieces - just add the minimum change and make that work before writing anything else. For example, the way you have the code written, all fishes die immediately. That is a different problem. If you write only one piece at a time, then you only ever have one problem and you know what is causing it.