[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:



>Thank you for the help in answering my question about hatching turtles.
>
>Now I am having trouble changing the patch colors.
>
>If a patch is surrounded by four yellow patches, I want to change the patch 
>to yellow.  I have found commands about diffusing, but this does not seem to 
>be appropriate.  Would I have to create variables for the patches?
>
>Thank you for all of your help,
>Elizabeth
>
>
If you know which patches you would like to check, you wouldn't need any 
patch variables, but to be general, we could do this:

patches-own [count pc-var]

setpc-var not pc = yellow
nsum pc-var count
if count = 4 [setpc yellow]

Here's how it works:

We create two patch variables, count and pc-var. count is used to count 
how many neighboring patches are yellow, pc-var is used to evaluate a 
predicate over all of the patches.

setpc-var not pc = yellow

if your color is yellow, set pc-var to false (1), else set it to true 
(0). (We do the opposite, because we want to count them up, and false is 
1, not 0.

nsum pc-var count

count up all of your neighboring patches' value of pc-var and put it into 
your count. 

if count = 4 [setpc yellow]

if exaclty 4 of your neighbors were pc = yellow, then set yourself to 
yellow. 

;---------------

This kind of program is one of those StarLogo idioms that are used very 
often to accomplish neighbor predicate calculations.

Andy 


Andrew Begel
Dept. of Computer Science
UC Berkeley