How to make two turtles in one patch both visible? - netlogo

I have two turtles - seller and buyer in one patch, and they have shape "face happy".
But on interface when I run setup if there are two turtles in one patch i can see only one of them.
my question is, how can i code it so that to see both of them. if its not possible at least to see in some patches one agent in others another one.
and here is my code:
ask sellers
[move-to one-of patches with [not any? turtles-here]]
ask buyers
[move-to one-of patches with [not any? buyers-here]]
ask buyers [if any? sellers-here [set shape "face happy"]]
ask buyers [if not any? sellers-here [set shape "face sad"]]
ask buyers [if any? sellers-here [set color 67]]
ask sellers [if any? buyers-here [set shape "face happy"]]
ask sellers [if not any? buyers-here [set shape "face sad"]]
ask sellers [if any? buyers-here [set color 137]]

First of all, note that you can actually tell if both are present from your face and color cues. If you want to see both, you will need to set transparent colors, or offset the locations, or both. E.g.,
ask buyers [
move-to one-of patches with [not any? buyers-here]
ifelse (any? sellers-here) [
set shape "face happy"
set color [255 0 0 125]
fd 0.45
][
set shape "face sad"
]
]

Assuming patches with two turtles at the center of patch:
to spread-out
ask patches with [count turtles-here = 2]
[ask one-of turtles-here [
fd .25
ask one-of other turtles-here [face myself fd -0.25]]]
end

Another option is to make one kind of turtle smaller than the other, and make sure that the smaller one is always on top. For example, if you use "circle" for shape for both buyers and sellers, you can set size 0.4 for sellers. Then either move sellers after you move buyers, or do something to cause each seller to be displayed after the buyer on the same patch is displayed. If you set a display property such as color, shape, or size for all sellers after all of the turtles have moved, that should cause the sellers to appear on top of the buyers.
Another option, if your turtles are smaller than patches, would be to use the patch color to convey information. For example, you could change the patch color whenever there are two turtles on the same patch. Or you could make sure that one kind of turtle is always on top (buyer, for example), and always set the patch color to a special value whenever there is a seller on the patch (even when there's no buyer present).

Related

How to ask turtles to stop if other turtles go over a certain patch-colour?

How can I tell a turtle to stop moving if there are other turtles going over a certain patch-color?
For example, I told 4 random patches to turn blue. I want a turtle only to be able to go over these blue patches if no other turtles are going over/are at these blue patches.
I already have this, but it does not seem to work:
if any? other turtles-on patches with [pcolor = blue]
[
set speed 0
]

How to kill turtles that are over patches in Netlogo?

to setup-lava
ask n-of lava patches [set pcolor orange]
ask men [die]
end
When I ask the men to die when they stand on a lava patch Netlogo gives me and error saying 'expected a number here, rather than a list or block'.
You haven't told us what lava is, but the error message suggests it is not a number. If you look in the NetLogo Dictionary, you will see that n-of must be followed by a number and then the agentset to tell NetLogo how many of the agentset to select.
Choice 1: assumes that lava-patches is a variable with a number in it (eg a slider on your interface)
to setup-lava
ask n-of lava-patches patches
[ set pcolor orange
ask men-here [die]
]
end
Choice 2: lava? is an attribute of patches that flags whether it is lava and that you have (somewhere else in your code) set that flag for lava patches
to setup-lava
ask patches with [lava?]
[ set pcolor orange
ask men-here [die]
]
end
Neither of these are tested

How can I move a turtle as close as possible to a certain patch?

I have a single blue patch and would like to move a turtle to the closest, empty patch to it. The only way I can think of doing this is using in-radius in a loop, increasing the radius size by one each time, but is there a better way?
globals [bluey]
to setup
ca
ask one-of patches [set pcolor blue set bluey self]
ask n-of 250 patches [sprout 1]
end
to-report nearest-empty [#patch]
report min-one-of
[other (patches with [not any? turtles-here])] of #patch
[distance #patch]
end
to test
setup
;the following fails if all patches occupied
;(can add a test for nobody)
ask nearest-empty bluey [set pcolor red]
end

NetLogo: Moving turtles towards patch color

Is it possible to have a turtle move towards a patch with a certain color?
i.e. have a turtle move towards red patch from blue patch?
sure enough
ask the turtles in question to
face one-of patches with [pcolor = red]
fd 1
although you should do some exception handling because if there is not a patch of that color you will get a
"FACE expected input to be an agent but got NOBODY instead. error
while turtle 0 running FACE called by Agent Monitor"
error
I do it something like this
let targ one-of patches with[pcolor = red]
if targ != nobody [set heading towards targ fd 1]
I hope that works for what you want.
Alternately as I was reminded in the comments.
If any? Patches with[ pcolor = red]
[set heading towards one-of patches with[ pcolor = red ] fd 1]
But as Seth says in the comments that computes the red patches twice which is costly.

NetLogo: set initial turtles number with empty neighbors around?

I ask patches sprout a number of turtles equal to slider initial-population on interface, now i wont that each turtle has neighbors around empty and that each patch contain one turtle. Below my wrong-code
to setup-turtles
set-default-shape turtles "circle"
ask n-of initial-population patches with [(pcolor = white - 1) and (not any? other turtles-here) and (not any? turtles-on neighbors)] [
sprout-normals 1 [
set color blue
set size 1
]
]
end
but no result neighbors empty foreach turtle..why?
I'm not sure that this is really what you are asking because the sentence "that each turtle has neighbors around empty and that each patch contain one turtle" is really hard to understand, but here is my guess:
You want turtles to appear only on patches where they will not have any neighbors. But it doesn't work because at the time you select your patches, every single patch fulfills the criteria (not any? other turtles-here) and (not any? turtles-on neighbors). As soon as you start sprouting turtles, that condition is not true for every patch anymore, but that fact is not taken into account by your code because you have already asked the patches to sprout turtles.
What you need to do is to check for the condition again each time you add a turtle. You can do that using repeat and then one-of instead of n-of:
repeat initial-population [
ask one-of patches with [(pcolor = white - 1) and (not any? other turtles-here) and (not any? turtles-on neighbors)] [
sprout-normals 1 [
set color blue
set size 1
]
]
]