user2359494
user2359494

Reputation: 733

NetLogo - selecting agent from agentset

I have a model of male and female animals interacting, with males competing with each other for access to females. When a dispersing male challenges a resident male (i.e., male-to-challenge) and loses, I’d like to have the dispersing male ‘remember’ who he lost to. I accomplish this with set dominant-males (turtle-set dominant-males male-to-challenge) at the end of the procedure. Then at the beginning of the procedure in the next time step, the dispersing male won't challenge the same dominant-male again. I thought that would be easy enough with:

      ; identify those males owning nearby females:
      let owner-males-of-nearby-fem turtle-set [males-in-my-territory] of breeding-females with [member? self (owned-nearby-females)] 
      ; identify those males who have not been challenged before:
     let unchallenged-males owner-males-of-nearby-fem with [not member? self dominant-males]
      ; select one of the unchallenged males to challenge:
      let male-to-challenge one-of unchallenged-males

However, I often find that the unchallenged-males are the same ones that had been challenged before and won (i.e., dominant-males), even though those males should not have been selected in the first place. I use print statements to verify this and included a simple error message using the following:

      if [self] of unchallenged-males = [self] of dominant-males
      [
       user-message "this is wrong!" 
      ]

I thought this would be easy but I've been stumped most of the day on this. Any help would be really appreciated.

Upvotes: 1

Views: 511

Answers (1)

Alan
Alan

Reputation: 9620

You are testing against dominant-males of owner-males-of-nearby-fem instead of the challenger. Try changing dominant-males to [dominant-males] of myself.

Upvotes: 1

Related Questions