2017-11-10 LAB/HW

posted Nov 10, 2017, 6:12 AM by Konstantinovich Samuel   [ updated Nov 10, 2017, 6:32 AM ]
GOAL: Ask the bright patches to spread their own color in two different ways...


Do now:

On paper:
Write a function that reports an agentset of all turtles that are:
1. anywhere in the range of ALL red colors (the entire row of red)
AND
2. facing one of the cardinal directions (North/South/East/West)

Getting the properties of other agents:

[PROPERTY ] of AGENT   gives a value from that agent.
[ PROPERTY ] of myself  Is a special usage with a keyword myself. is how any agent tells other agents their property when you are asking them something.

e.g.
[age] of turtle 0
[size] of turtle 5
[pcolor] of patch 0 0
[pcolor] of one-of patches

You can do this using one-of, but you need to make sure there is at least one:

show [xcor] of one-of turtles with [color = red] ;this can crash!!!!

if any? AGENTSET
  [ 
DOSOMETHINGWITH: [property] of one-of AGENTSET
  ]


if any? turtles with [color = red][
   show [xcor] of one-of turtles with [color = red]
   ;set var [xcor] of one-of turtles with [color = red]
]



Final command that involves getting values:  myself
When a patch or turtle asks an agentset, that agentset can look at the ask-er's properties!!!!

;turtle context
ask SOMEONE
[
set xcor  (  [xcor] of myself  )  ;parenthesis for clarity    
                   ;xcor of the turtle that asked
]


You can use this in a command:
;patch context
ask neighbors [
    set pcolor [pcolor] of myself 
                    ;pcolor of the asking patch!





classwork:
HERE IS SOME STARTING CODE:


to setup
  ca
  ;1. Make a single random patch   red + 3   
  ;2. AFTER YOU TEST YOUR GO: modify this to make several patches random colors that end in 8
end

to go1
ask patches with [ isBright ] [ 
    spreadColor
]
end

to go2
ask patches [ 
    if isBright  
    [ spreadColor ] 
]
end

;patch context
to spreadColor
    ;ask non-bright neighbors to become your color or a slightly darker color.
end

;Let us define bright patches as having a color that ends in a number higher than 2. 
;patch context
to-report isBright
 report true 
 ;replace with a boolean that is true when the patch has a color ending in a number higher than 2
end

Comments