user2359494
user2359494

Reputation: 733

NetLogo - growing territory

I'm trying to expand animal territories such that the neighboring patches surrounding an animal's existing territory are assessed by some criteria (i.e., food quality and if other animal's territory is there) and then added to the total size at each time step. Using the following post as a template (http://netlogo-users.18673.x6.nabble.com/What-is-more-efficient-to-acquire-patches-by-expanding-search-radius-or-moving-td5003711.html) I was able to have animals assess the neighbors around their individual location and determine if the neighbors were taken by anybody (i.e., just TRUE/FALSE not identity of the animal with the territory) and move into a grid cell with the highest "quality" that was not taken. Instead I'd like for the animal to assess it's entire territory and expand to any grid cell that fits the criteria. Also, I'd like to have the animal identity assigned to patches that fall within its territory so that, for example, an animal can not go into the territory of a dominant animal but can of a subordinate. I tried to utilize the flood fill idea but could not quite get it right. Any suggestions or help would be great. Below is what I have so far.

breed [animals]

animals-own [ orig territory food status]  ; turtle's original patch, patch-set of territory, status (higher number more dominant) of the animal to other competitors (is not incorporated currently)
patches-own [ taken? hsi]  ; true if patch is in territory of a turtle 


to setup  
  clear-all
  ask patches [ set taken? false 
                set hsi random 5 
                set pcolor scale-color (black) hsi 1 4] 
  let $colors [red pink yellow blue orange brown gray violet sky lime] 
  ask n-of 10 patches 
  [ sprout-animals 1
    [ set orig patch-here  
      set territory patch-set orig 
      set status random 4
      set color item who $colors  
      set pcolor color 
    ] 
    set taken? true 
  ] 
    reset-ticks 
end 

to go 
  if all? animals [food >= 150] [ stop ] 
  if ticks = 50 [ stop ]
  ask animals [ expand ]
  tick 
end 

to expand 
  if food < 150
  [ 
     let $p neighbors of [territory] with ([not taken?] and [hsi > 2])  ; expects agentset but territory is a patch-set
     set territory (patch-set territory $p) 
     set pcolor [pcolor] of myself
     set food sum [hsi] of territory
    ] 
end

Upvotes: 1

Views: 326

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

It seems sensible to me that as you suggest, each patch should know whose territory it is part of. So instead of patches-own [taken?] where taken? is true or false, I would suggest patches-own [owner].

In your setup procedure, you do ask patches [ set owner nobody ], and then when a turtle takes ownership of a patch, it sets that patch's owner to itself. So in your setup procedure you'd add set owner self (to change the owner of the patch is standing on) and in your expand procedure, do ask $p [ set owner myself ].

You'll have to be careful to keep the territory information stored in the turtles in sync with the owner information stored in the patches, but assuming you get that right, then problems such as "an animal can not go into the territory of a dominant animal" become easy because when an animal is considering stepping into a patch, it can trivially see who that patch's owner is, with code such as:

let target patch-ahead 1
let defender [owner] of target
if not is-turtle? owner or [status] of owner < status [
  ...
]

Upvotes: 1

Related Questions