1

I'm working on a Simulation of a Stadion. I have created several rows with pcolor = 35. Now I need my number of turtles to spawn on the patches with pcolor = 35, but nowhere else. They also need to spawn randomly on those patches. My code for this problem looks like this:

to seat-people

set color green

setxy int random-xcor int random-ycor

if (pcolor = 35) [seat-people]

if any? other turtles-here [seat-people]

end

The turtles are green, spawn randomly and there is only one turtle per patch; but they won't spawn on patches with pcolor = 35 but everywhere! How do I do that?

I've seen a code with if (pcolor > 35) [seat-people], but I already have many other pcolors < and > than 35.

Pimgd
  • 5,983
  • 1
  • 30
  • 45
finjou
  • 21
  • 2
  • 5

2 Answers2

2

try with this. where N is the number of turtle you want to sprout and sprout 1 is the procedure to sprout 1 turtle which you can modify as you want.

ask n-of N patches with [pcolor = 35 and not any? other turtles-here][sprout 1]
drstein
  • 1,113
  • 1
  • 10
  • 24
  • If I replace N with the slider for the number of turtles, what is the sprout 1 for? I used your code and not a single turtle appeared. – finjou Nov 10 '14 at 07:12
  • I tested my code and it's working. if you replace N with a number (let's say 20) what you are doing is: ask to 20 patches (chosen with a certain condition) to sprout 1 turtle on it. So 20 turtles in total. Now reading again your question I don't get if you want turtles spawned on green or on other colors. My code sprout turtles on green, if I understood wrong you just have to replace '= 35' with '!= 35' – drstein Nov 10 '14 at 13:48
  • It works now, I had to change some parts of my own code for it to work, but it works! Thank you. :-) – finjou Nov 16 '14 at 19:10
2

I think you are looking for the 'not equal' operator !=

 Ask n-of 20 patches with [pcolor != 35][sprout 1]
King-Ink
  • 2,096
  • 12
  • 18
  • I don't know if I can use n-of 20 patches, since the number of patches shouldn't affect the simulation, but I tried your code and a combination of yours and mine and it didn't work. When I replace = 35 with != 35, the screen goes black and turtles seem to randomly run around as if not able to be placed. – finjou Nov 10 '14 at 07:15
  • In addition, if I say "ask patches with [pcolor = 35] [sprout 1] then every single patch with pcolor 35 sprouts a turtle which results in about 600 turtles spawning. And if I use !=35, then EVERY patch spawns a turtle and the screen is full of turtles. :-D – finjou Nov 10 '14 at 07:44
  • There seems to be a language barrier. – King-Ink Nov 10 '14 at 09:11