Lecture: 12-04-2012

posted Dec 4, 2012, 6:24 AM by Samuel Konstantinovich   [ updated Dec 4, 2012, 12:59 PM ]
Homework: You should have all of the tutorials done. There is a test Friday.

Do now:
  How can you change the cars/people demo that you wrote this weekend to have the cars draw a road (paint the patches gray) as they move?
  How can you change the people so that they move .2 when they are on a black patch, and move 1 when they are on a gray patch?

Goal: agentsets

####
an agentset is a sub-group of agents. That can be turtles, or patches, or even links. You already know where to use a set of agents, because turtles is an agent set with ALL turltes. Here are two instances where you already use agentsets:

ask turtles [fd 1]
ask patches [set pcolor white]

So we are allowed to  :   ask AgentSet [commandblock]

but an agentset can be a more complicated statement like:

turtles with [color = red]
patches with [xcor > ycor ]
turtles with [ shape = "car" and color = yellow]

turtles with [  BOOLEAN ]    
or
patches with [ boolean ]

####NEW COMMAND
We can also check if there are any turtles in an agent set:

any? agentset    is true if there is 1 or more agents in the set.

if any? turtles with [color = white]  [ ...DO_SOMETHING_FOR_THE_IF....] 

####NEW COMMAND
We can check how many are in an agentset with the count command:

count agentset

if count turtles with [pcolor = white] > 10  [ ...DO_SOMETHING_FOR_THE_IF....] 
 
this would make something happen when you have more than 10 turtles. 

####GLOBAL AND TURTLE variables.
use the globals or turtles-own commands to create variables that can be used by your programs... more on this in the lab tomorrow.

####NEW WIDGET
MONITORS can display a reporter function or a global variable. 

make a monitor that has a reporter like these:  
count turtles
or
count turtles with [color = red]


####Overview of New things:
Agent set related commands:
with
count
any?

Widgets:
Monitor
Comments