2015-12-07 HW

posted Dec 7, 2015, 4:55 AM by Samuel Konstantinovich   [ updated Dec 7, 2015, 5:24 AM ]
Goal Agent Sets

Homework:
Netlogo Videos 17,18
http://bert.stuy.edu/pbrooks/videos/NetlogoTutorial/NetlogoTutorial.py
You can be quizzed on this.

DO NOW:
1. Log in
2. Open a terminal, use the following command twice to open a second window:
netlogo &
netlogo &

Be careful not to close that terminal, or BOTH netlogo windows will close.

3. In one of the two netlogo windows, OPEN YOUR TREE LAB
4. Turn monitor off. 

Definitions - (ignoring links)
Agent: A turtle, patch.
Agent Set: A group of turtles, or a group of patches.

Agent Sets you know:
turtles - the set of all turtles
patches - the set of all patches

Agent set you don't know:
turtles-here - the set of all turtles on the same patch as the agent (either turtle or patch) that executes the command (including itself if called by a turtle)

Basic Agentset Commands:
ask AGENTSET [ commandBlock ]
e.g.
ask turtles [ wiggle ]
ask turtles [ stamp die ]

count AGENTSET
e.g.
display count turtles
ask turtles [ set label count turtles ]

Filtering an agent set:  These commands specify which agents in an agent set you are talking about:

one-of AGENTSET      ;  gives you a randomly chosen agent from the agentset 
e.g.
ask one-of turtles [die]   ; one-of turtles   is an agentset with exactly one turtle

AGENTSET with [ boolean reporter ]  ; gets the agents from the agentset, that match the boolean.
e.g.
ask turtles with [color = red] [die]   ; turtles with [color = red]    is an agentset with some turtles... but it could be empty!
ask turtles with [ xcor > 0] [set color red]

Test if there is at least one agent:
any?  AGENTSET     ;this reports true when there is at least 1 agent in the set.
e.g.
if any? turtles with [color = red] 
[ ask turtles with [color = red]  [die]

Advanced filters (we will discuss later dont worry for now)
max-one-of 
min-one-of 
in-cone 
in-radius


Mini Lab:
Setup Button - call a setup function that:
    Creates 200 turtles scattered randomly on the screen.
    Sets the size randomly to 1,2 or 3.
    Sets the heading to 0,90,180, or 270  (how can you do this with the random command? Talk to your neighbors if you aren't sure. hint - how many choices are there? What are they multiples of?)

On the command center, try to ask different turtles to do things:
-Double the size of all turtles on the right half of the world. 
-Kill all red turtles

Make a forever go button that calls a go function that:
-size 1 turtles go forward .1
-size 2 turtles go backwards .1
-size 3 turtles spin in circles (turn right 5)

 
Comments