Reputation: 630
I have two breeds and I would like to stack them in groups of 10 per patch, each breed separately, in the setup procedure. I have tried simple expressions as below, but they don't seem to work. Any ideas on how to arrange this?
ask breed1
[
if count breed1 patch-here < 10 and count breed2 patch-here = 0
[move-to patch-here]
]
ask breed2
[
if count breed2 patch-here < 10 and count breed1 patch-here = 0
[move-to patch-here]
]
UPDATE:
How about this code that should supposedly work, but still does not do what I want. Thanks Seth for pointing out at Model Library sample codes. It works partially, it does some concentration of turtles, but there are still patches with mixed populations of breeds. I suspect in the go procedure or with some kind of loop it would probably work, but in the setup procedure it does not achieve what it should.
to concentrate
ask breed1
[
let like-patches patches with [ any? breed1-here and not any? breed2-here]
if any? like-patches
[if count breed1-here < 10
[let target one-of like-patches
face target
move-to target ] ]
]
ask breed2
[
let like-patches patches with [ any? breed2-here and not any? breed1-here]
if any? like-patches
[if count breed2-here < 10
[let target one-of like-patches
face target
move-to target ]]
]
This simple line of code seems to work partially, provided I create a grid of patches with each of the breeds, so they are separated spatially from the beginning:
ask breed1
[
if count breed1-here > 10
[move-to one-of patches with [count breed1-here >= 1]]
]
ask breed2
[
if count breed2-here > 10
[move-to one-of patches with [count breed2-here >= 1]]
]
Upvotes: 2
Views: 828
Reputation: 630
It was much simpler, than I thought!
patches-own [patchc]
to setup
clear-all
ask patches [set patchc false]
ask n-of 30 patches [ sprout 10 [set breed breed1] set patchc true]
ask n-of 30 patches with [patchc = false][ sprout 10 [set breed breed2] ]
end
Upvotes: 1
Reputation: 30453
You seem to have in mind that patch-here
will somehow refer to all the different possible patches you might want the turtle to stand on? But it doesn't; it only refers to the single patch the turtle is currently standing on. So move-to patch-here
doesn't accomplish anything (except move the turtle to the center point of the patch it's already on).
You need to add some code that actually tries out different candidate patches.
I'd suggest looking at One Turtle Per Patch Example, in the Code Example section of the Models Library. It shows different possible methods for arranging turtles one per patch. Then, take one of those methods and generalize it to solve your slightly more complex problem.
UPDATE:
Your new code is definitely closer to a solution. But it has a logic flaw.
You write:
let like-patches patches with [ any? breed1-here and not any? breed2-here]
But what if there are no such patches? There easily might not be any. In that case, the turtle will stay where it is.
You need to come up with some logic that guarantees that the turtles will find new homes. (How would you do it if you were arranging the turtles yourself, by hand?)
Upvotes: 1