2015-12-08 LabN04 + HW

posted Dec 8, 2015, 4:47 AM by Samuel Konstantinovich   [ updated Dec 8, 2015, 8:42 PM ]
Homework: Netlogo Video 19 (turtle turtle interaction)


Goal: LABN04  ( turtle variables and agent sets)

Read each section ENTIRELY before starting.

Discuss the section with your neighbors before starting. 


SECTION I 

(Most of you should be able to do this part in less than 10 minutes)
1. An observer context function setup that:
1a. clears the world
1b. makes 5 turtles  that are red and "car" shaped 
1c. each cars should face any of these four directions randomly: 0 90 180 or 270; 
1d. make 10 blue "person" shaped turtles. 
1e. place the cars on the left half of the screen at random, and the people on the right side of the screen at random. 

2. A turtle context functions carMotion :  move forward 0.1 
3. A turtle context function peopleMotion : wiggle forward .01 and then turning at most 10 degrees in either direction.

4. An observer context function go.
    -Make all car shaped turtles run carMotion 
    -Make all people shaped turtles run peopleMotion
    -There should be an every command INSIDE your go around the entire body of the function. This will make the program run smoothly at a reasonable speed. Generally the delay should be anywhere between 1.0 / 24.0 and  1.0 / 60.0.

5. Make Buttons for setup/go. Make go a forever button. 


IN THE FUTURE: 

I will not ask you to put an every inside of your go. I will expect it to be there. 





SECTION II

(Read all of the notes below the questions, this is new stuff!)
Now improve the model:  


1. Make cars that are on the same patch as pedestrians make the pedestrians die. 

2. Make the cars have a 2% chance every time they run the car motion command to: reverse their direction 180 degrees. 

3. Try to give each car a different speed using a randomly assigned (set)  turtle variable speed, rather than a slider. When you create the cars in the setup, assign the speed a random number: .1  .2  or .4
3b. Modify carMotion to utilize this new speed property.

Concept 1: What can you do when a turtle can detect other turtles on the same patch?!?  You can make cars hit pedestrians... you can make doctors heal injured pedestrians and many other things!!!

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 or patch context, and it DOES INCLUDE THE AGENT THAT CALLS IT (if the agent is a turtle) 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 the with command

ask turtles-here with [ boolean ] [commands]
ask turtles-here with [color = yellow] [set size 3]


Also the other command removes yourself from the agentset:
ask other turtles-here [set size 3]     ;this excludes the turtle performing the ask from the turtles-here command. 


Concept 2:  Not as obvious as I had originally expected, you can make something happen randomly, by giving it a Random % chance to do something. 

To make a boolean true 57% of the time you would say:   random 100 < 57
To make a boolean true 33% of the time you would say:   random 100 < 33       OR:    random 3 = 0      (if you wanted 33.3333%)

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 2.5:  

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

if random 100 < calculateProbability a b       
[ do stuff in here ]   

; where calculateProbability takes 2 arguments, and reports a number from 0-100 inclusive


Concept 3:  You can give turtles more properties, like an individual speed, or individual health, or individual scores. 

Variables (from the video)
Turtle variables are local to the turtle. Look up the turtles-own command. 
This would have values like an individual person's name, age, height etc.

Global variables are shared by everyone. Look up the globals command.
This would have values like the world population limit, the speed limit everyone follows or other things that EVERYONE share. (Science/Math constants are global variables)

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
Comments