Frage

I'm very new to NetLogo and have what I hope to be a simple enough problem. I have two breeds created [ redteam redsoldier] & [blueteam bluesoldier] what I'm trying to do is make the different breeds spawn in specific patches. So red team can only randomly spawn in one of half (red territory) of the window and the blue team randomly spawns in the other (blue territory), however after trying multiple if and while statements and other things, the turtles only spawn in the center of the screen.

Any ideas?

globals [
red-patches
blue-patches 
]

;; note patches could not be set to only green as this partly clashed with soldiers     uniform

breed [ redteam redsoldier]
breed [ blueteam bluesoldier]

to setup
clear-all
setup-turtles
setup-patches
reset-ticks
end

to setup-turtles
create-redteam 10
 [
   set shape "person soldier" ;;need to import person soldier shape!
   setxy random-pxcor random-pycor
   set size 1.5
 ]

create-blueteam 10
 [
   set shape "person soldier" 
   setxy random-pxcor random-pycor
   set size 1.5
 ]
 end

to setup-patches
;; create red territory
set red-patches patches with [pycor < 0]
ask red-patches [ set pcolor green - 3 ]

;; create blue territory
set blue-patches patches with [pycor > 0]
ask blue-patches [ set pcolor green - 2 ]  
end
War es hilfreich?

Lösung

A simple way to do this is to use sprout.

Here is a new version of setup-turtles (that needs to be called after setup-patches):

to setup-turtles
  ask n-of 10 red-patches [
    sprout-redteam 1 [
      set shape "person soldier"
      set size 1.5
    ]
  ]
  ask n-of 10 blue-patches [
    sprout-blueteam 1 [
      set shape "person soldier"
      set size 1.5
    ]
  ]
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top