12-04-2013 LAB

posted Dec 3, 2013, 9:06 PM by Samuel Konstantinovich   [ updated Dec 3, 2013, 9:06 PM ]
There is a lab, and some concepts you can reference if you have trouble with the lab. It would be really dumb to totally ignore the concepts and skip to the lab, because you WILL have trouble if you don't read up on it first. 

HOMEWORK: Finish the lab.

Feel free to read about the lab, discuss, and work on the lab with a partner. 

Concept 1: Talking to the turtles that are on the same patch as you:

turtles-here is the agent set of all turtles located on the same patch as the turtle that uses it. This can be used in turtle context, and it DOES INCLUDE YOURSELF unless you specify otherwise:
ask turtles-here [ commands ]

ask turtles-here [set size 3] ;everyone including myself 

OR you can reduce the agentset more using 'with'

ask turtles-here with [ boolean ] [commands]

ask turtles-here with [color = yellow] [commands]

OPTIONAL: ask other turtles-here [set size 3] ;this is how you exclude yourself from the turtles-here command. the other command removes yourself from the agentset, and it is optional for now. 

Concept 2: Random % chance

To make a boolean true 37% of the time you would say:   random 100 < 37

You can use this in an if statement like this:
if random 100 < 50 [fd 2]
;50% of the time move forward 2

or like this:
if random 100 < N [commands]
;N % of the time, do the commands

Concept 3:
The N from the last concept could be a variable OR REPORTER FUNCTION like this:

if random 100 < REPORTER [commands]

Concept 4:  Variables (from before)
Turtle variables are local to the turtle. Look up the turtles-own command.
Global variables are shared by everyone. Look up the globals command.

You can give a variable a specific value with set like:
set size 6
set color red

OR increase/decrease like this:
set heading heading + 1
set size size - .5

LAB: Cars and Pedestrians
1. Start with your basic cars and people model 

to setup
  crt 5 
    set shape "car" 
    set color red 
    set xcor (- abs random-xcor)
    set heading random 4 * 90
  crt 10
    set shape "person"
    set color blue
    set xcor abs random-xcor
  ask turtles 
    set ycor random-ycor
    set size 2

to go
  ask turtles with [shape = "person"] [peopleMotion]
  ask turtles with [shape = "car"] [carMotion]
  wait 1 / 30

to carMotion
  fd 1

to peopleMotion  
  fd .3
  rt random 30
  lt random 30

2. Now make the cars paint the gray roads like yesterday. Do this by setting the pcolor to gray every time it moves. Decide which function you should put the command in...

3. All turtles should have a variable deathTimer.

4. There should be global variables accidentDeath and naturalDeath. These will act as counters for the number of deaths that happen. We will use them in monitors.

Additional Car Behavior:
5. When a car is on the same patch as a person, it makes the person die right away. This will add 1 to the accidentDeath count. (concept 4) 

New Reporter function:
6. deathRate is a reporter function that reports 10 when there are more than 150 people, or it reports 6 otherwise. 

New Person Behavior:
7-DeathTimer logic:
 People should initialize their deathTimer to -1 when they are created.

Inside of the CRT 10 in your setup: set deathTimer -1
You don't have to do this in hatch because they copy the -1 from the parent

 People with a deathTimer that is > 0 reduce their timer by 1 and reduce their size by .1  every time they move. 
 People with a deathTimer that is = 0 should increases naturalDeath by 1, then die.
 People have a 'deatRate' % chance (either 10 or 6) of starting to die. When they start to  die, they turn red, and set their deathTimer to 20.  (concept 3, use the deathrate function as your percent)

8-Hatch Behavior:
 NON-Dying people have an 8% chance of hatching a child. 
    The child should turn 90 degrees to the left  so they split apart from the parent quickly.
(remember dying people are red and have a death counter > -1) (concept 2)

New Widgets:
9. Make a monitor for the number of naturalDeaths, and one for the number of accidentDeaths. Just put the name of the variable into the monitor, there is nothing fancy here.
10. Make a plot for the number of people. Count the number of people (not all turtles) on the plot. 
Look at sample models with graphs to see how they do this. 

You need to use the following commands for a plot:
inside of setup after you clear-all write the command: reset-ticks
inside the go at the end write the command: tick