How to remove all links from one turtle to an agentset in Netlogo

Viewed 385

I have this problem: I have a turtle dealing with an agentset of agents who all have a link with the specific turtle. At the end I want the turtle to remove all its links with the agents in the agentset but I do not find a way. Can someone help me? I report here the code that does not work. In particular the problematic line is "ask my-links [other-end = traitors] [die]"

to cooperate-with-friend
  set traitors friends with [cheater? = True]
  set loyals friends with [cheater? = False]
  ask traitors [set wealth wealth + 3]
  ask loyals [set wealth wealth + 2]
  set wealth wealth + count traitors * -3 + count loyals * 2
  ask my-links [other-end = traitors] [die]
end

NB: friends is an agentset grouping all turtles having a link to the turtle executing the command.

3 Answers

The way to modify Charles' approach to accommodate your tolerance variable is:

ask my-links with [member? other-end traitors]
[ if tolerance < random-float 1 [die]
]

Given that you are asking traitors to do something, I assume that traitors is an angentset. other-end, however, is an agent, so other-end = traitors is comparing an agent with an agentset. The two can never be equal. What you want to know is if the agent at the other end is a member of the traitors angentset. For that you can use member?.

ask my-links with [member? other-end traitors] [die]

Mmm.. Netlogo does not accept that line. It says that after member? expects a command.

In the meantime I solved like this. A bit twisted but it seems working:

let anger random-float 1
  repeat count traitors [
    let traitor one-of traitors
    if link-with traitor != nobody and tolerance < anger [
      ask link-with traitor [die]
    ]
  ]
Related