2017-11-02 HW

posted Nov 2, 2017, 6:14 AM by Konstantinovich Samuel   [ updated Nov 2, 2017, 7:11 AM ]

Homework: Netlogo Video 19 (turtle-turtle interaction)

Remember:  

1.Your animation is due Wednesday morning 8am on the homework server, submit an nlogo file.
 
2. Your LABN04 is due Thursday morning 8am on the homework server, submit an nlogo file.

EXAM : Moved to Monday because of the schedule.


Goal: LABN04  Man-Eating-Cows!!!!! ( turtle variables and agent sets)


This is a multi Day lab. It will be due Thursday Morning, but you only have Today, Tomorrow and Tuesday to work on it in class. 

If you want to do it properly you should work on it at home and at the Dojo if you get stuck! This is a big assignment!


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 "cow" shaped 

1c. each cow should face any of these four directions randomly: 0 90 180 or 270; 

1d. make 10 blue "person" shaped turtles. 

1e. place the cows 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 cowMotion :  move forward 0.1 
3. A turtle context function peopleMotion : wiggle forward 0.1 and then turning randomly at most 10 degrees in either direction.

4. An observer context function go.

    -Make all cow shaped turtles run cowMotion 

    -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 cows that are on the same patch as people make the people die. (make an eatPeople procedure or something similar) 

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

3. Try to give each cow a different speed using a randomly assigned (set)  turtle variable called speed. This is better than a slider becasue all cows can move at different speeds if we wish. 
    When you create the cows in the setup, assign the speed a random number: .1  .2  or .4

3b. Modify cowMotion 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 cows eat people... you can make doctors heal injured people 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



SECTION III


New Variables:
1. There should be global variables accidentDeath and naturalDeath. These variables will act as a counters for the number of deaths that happened by getting eaten by a cow, or dying naturally. Clear-all will reset them to 0. Turtles dying will increase them.

2. Each turtle should have a variable age that determines how many times they have been alive when their motion command was called. This is just a counter that keeps track of how many times it has run the motion command, so you can increment it in peopleMotion / cowMotion.

New Widgets:

Make two sliders: startingPeople, startingCows

They control how many cows/people are created in the setup.


Make three 'monitor' widgets on your NetLogo interface. 

Display the 

    -accidentDeaths (Just put the name of the variable into the monitor.)

    -naturalDeaths 

    -number of people shaped turtles (count them!)



Additional cowMotion features:

When a cow is on the same patch as a person, it makes the person die right away AND adds 1 to the accidentDeath count.


Additional peopleMotion features: 
1. Add 1 to the turtle's age.

2. (birth) People have an 1% chance of hatching a new person. The child should turn 90 degrees to the left  so they split apart from the parent quickly. (see the hatch command)

3. (death) People that are over 100  ticks old have a chance to die every time you call the peopleMotion command. 
(aka: every time you call go / every frame / every tick , these all mean the same thing)

3a. This chance is equal to:   1% per year over 100.  This requires a little math, but you can do it! 
e.g.
age 100 or less never die naturally.
age 113 has a 13% chance of death.
age 200 has 100% chance of dying naturally.
This can be an expression, or you can tuck it away in another function to make your code readable!

3b. This type of death is a 'natural death' and should add 1 to the naturalDeath counter.
(Organize your code! Make two functions birthChance and deathChance to handle these complex parts of the peopleMotion )

Comments