dimanche 3 janvier 2021

How to get a breed to share energy with another breed when linked?

I am trying to create a model of cooperation with two breeds - 'cooperators' and 'un-cooperators'. My aim is to make it so that the cooperators will give some amount of energy to the un-cooperators if they are linked. Thus far, I have made it so that cooperators will link with un-cooperators, however from here I am stuck on how to make it so that the cooperators can share energy with the un-cooperators. I would also like to make it so that if the two breeds roam x amount of patches away from each other the link will break and they will link with another turtle. Any help would be appreciated. I will post my code below.

turtles-own [ energy ] 

breed [ cooperators cooperator ] 
breed [ uncooperators uncooperator ]




to setup 
  ca
  ask patches [
    set pcolor green
  ]
  create-uncooperators num-uncooperators [
    setxy random-xcor random-ycor
    set color red
    set energy random 100
  ]
  set-default-shape turtles "person"
  create-cooperators num-cooperators [
    setxy random-xcor random-ycor
    set color yellow
    set energy random 100
  ]
  reset-ticks
end

to go 
  if not any? turtles [ stop ] 
  ask cooperators [
    set energy energy - 1
    move
    communicate
    cooperate
    break-link
  ]
  ask uncooperators [
    set energy energy - 1
    move 
  ]
  tick
end

to move
  lt 50
  rt 50
  fd 1
end

to communicate
  if count my-links < 1 [
   create-link-to one-of uncooperators in-radius linking-radius
  ]
end

to break-link
end

to cooperate
end

Aucun commentaire:

Enregistrer un commentaire