2017-10-31

posted Oct 30, 2017, 9:03 PM by Konstantinovich Samuel   [ updated Oct 31, 2017, 7:59 AM ]
Goal: Give in to your hatred (for ugly netlogo models) !

Reminder: Exam Friday.

Revisiting:
 any?   - Right now, it is generally used in if / ifelse statements. There are some other uses... like in a while loop. 

When you use one-of  on an empty agentset you get NOBODY. This is bad... 

To properly guard against NOBODY when selecting a single agent use any? in the following way:
if any? AGENTSET
[
       ask one-of AGENTSET [ stuff ]
]

To properly guard against NOBODY when selecting MULTIPLE agents, use count in the following way:
if count AGENTSET > x
[
    ask n-of x AGENTSET [ stuff ]
]


any? is also used when deciding how to act:

if any? other turtles-here
[
    ;stuff
]

Creating turtles in turtle context: (any set of turtles can run this)
hatch n  - create n turtles and copy all of your properties to the turtle except the who number.
hatch n [ command-block ] - create n turtles and copy all of your properties to the turtle except the who number. THEN make each turtle created run the command block.
e.g.

hatch 1 [ 
    rt 90 
    fd .5
    set color white
]


Creating turtles in  patch context: (any set of patches can run this)
sprout n  - create n turtles and copy the pxcorpycor into the turtle's xcor , ycor.
sprout n [ command-block ] - create n turtles and copy the pxcorpycor into the turtle's xcor , ycor. THEN make each turtle created run the command block.
e.g.

sprout 1 [ 
    set heading 0
    fd .5
    rt 90
    fd 1
]



LAB:



Try the following activities in a default world. (Make a new netlogo file!)
0. Make a draw-grid procedure. It should draw a white border around each patch. Use turtles and pen-down to do this. 
    This will help you see patches and count how wide things are!.
1. Make a green 9x7 (9 in the x-direction) rectangle of patches centered around patch 3 4. (Patch color makes up the rectangle!)
2. Make a yellow 1 patch wide border around the whole world. 
3. Spawn 30 red "cow" shaped turtles randomly in the green area of the world.
4. Create 20 blue "person" shaped turtles randomly on the black patches.
5. Have cow shaped turtles wiggle at speed 0.1, but when they stand on a black patch, they move backward 0.1.
   (Wiggle should turn before moving, this makes it so the backward 0.1 is like an undo.)
6. Have people shaped turtles wiggle at speed 0.2, but when they step on the yellow border they move backward 0.2.
7. Think of several behaviors that you could implement when cows and persons are on the same patch. Make a list. Rank them from easy to hard!


By Monday:
Make a netlogo animation. 



Comments