Pcolor of Patches in cone?

16 views
Skip to first unread message

Souzan Karsha

unread,
Nov 23, 2022, 1:26:22 PM11/23/22
to netlogo-users
Hello all 

How can I ask a turtle to check the pcolor of all patches in its cone? 

Ask residents [
If [ pcolor] of patches in-cone 12 360 = red [ do something ] ]

But it is not working 

Thanks, 


Souzan 

Charles Staelin

unread,
Nov 23, 2022, 3:20:53 PM11/23/22
to netlogo-users
The problem you are encountering in your code is that 
[pcolor] of patches in-cone 12 360 
returns a list of the colors of all the patches in the cone and you cannot simply check to see if a list is equal to a single value.  What you want to do is to see if every element of the list is equal to "red".  There are several ways to do this, but I prefer to use reduce.
reduce [[k n] -> k AND n = red] (fput TRUE [pcolor] of patches in-cone 12 360)]
will give you true if all the elements of the list are red, and false otherwise.

Another approach is to count the number of non-red elements in the list by filtering out all the red values, leaving only the non-red ones, and then checking the length of the resulting list.
length filter [n -> n != red] [pcolor] of patches in-cone 12 360
will be zero if all the elements of the list are red, and non-zero otherwise.

Hope this helps,
Charles

Charles Staelin

unread,
Nov 23, 2022, 4:15:59 PM11/23/22
to Souzan Karsha, netlogo-users
But how does that check if they are all red?  Perhaps you see if any are not red?
if NOT any? patches in-cone 12 360 with [pcolor != red]

-------------------------------
Charles P. Staelin
Professor Emeritus of Economics
Smith College
Northampton, MA 01063


On Wed, Nov 23, 2022 at 3:24 PM Souzan Karsha <souzan...@gmail.com> wrote:
Thanks for your response! 
I did use the below command and it worked as well
If any? Patches in- cone  12 360  [ ] 

🙏🏻🙏🏻🙏🏻

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/e71867c7-363d-460c-8ad4-4c03411975b7n%40googlegroups.com.

James Steiner

unread,
Nov 23, 2022, 7:56:22 PM11/23/22
to Souzan Karsha, netlogo-users
First, I think (in-cone 12 360 ) is a full circle, so is more simply done (in-radius 12) ... 

Next ...

Let visible ( patches in-.... )

;; At least one red
if any? (visible with [ pcolor = red ]) 

;; All are red
if not any? (visible with [ not (pcolor = red ) ]) [ ..... ]

;; Exactly N red
If N = count (visible with [ pcolor = red ]) [ ..... ]

;; At least 25% red
Let total# count visible
Let red# count (visible with [ pcolor = red ])
If (red# / total# * 100) >= 25 [ ..,.. ]


Let us know if you have a different need.

-- James








--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.

Jim Lyons

unread,
Nov 24, 2022, 8:25:45 AM11/24/22
to ja...@turtlezero.com, Souzan Karsha, netlogo-users

On Nov 23, 2022, at 7:56 PM, James Steiner <ja...@turtlezero.com> wrote:


;; All are red
if not any? (visible with [ not (pcolor = red ) ]) [ ..... ]


Or the handy

if all? visible [pcolor = red] […]

8^)

Jim

Souzan Karsha

unread,
Nov 24, 2022, 4:25:38 PM11/24/22
to Charles Staelin, netlogo-users
Thanks for your response! 
I did use the below command and it worked as well
If any? Patches in- cone  12 360  [ ] 

🙏🏻🙏🏻🙏🏻
On Wed, Nov 23, 2022 at 1:20 PM Charles Staelin <csta...@smith.edu> wrote:
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.

James Steiner

unread,
Nov 24, 2022, 10:30:36 PM11/24/22
to Jim Lyons, Souzan Karsha, netlogo-users
Oh wow, either I completely forgot about "all?" or it was added while I wasn't paying attention!

I assume the former, though I wish for the latter.

Souzan Karsha

unread,
Nov 25, 2022, 2:14:12 PM11/25/22
to ja...@turtlezero.com, Jim Lyons, netlogo-users
No worries! I got the right one!

Thanks all!
Reply all
Reply to author
Forward
0 new messages