posted Nov 17, 2017, 6:10 AM by Konstantinovich Samuel

ALL Work today is on paper. DO NOT log into the computers.

You should be able to articulate the following: (Write your answers on paper, discuss with neighbors as needed)

1-How do you make an agentset complete a task before any of them start a different task?
    Write the code to turn all patches green, and after that completes, turn all patches blue.
2-How does this concept relate to cellular automata?
3-How do you organize your code in cellular automata so that you do not encounter problems due to changes in properties of an agent?

Goal: Modular design of Conway's game of life.
Groups of 3:

Write Conway's game of life on paper. 
-Start with the go procedure. 
-In your go, call other procedure(s) that do whatever you want!  Use names that accurately describe what the procedure does.
-If any procedure that you used does not exist, write the procedure you called next. (If your go calls 2 procedures, write both of them in the same manner)
-label the context of each procedure you write

Artificial restrictions:
    1. You are always permitted to add let statements to create local variables and make your code more readable. The restrictions do not limit this.
    2. Each if/ifelse/ask statement can contain a SINGLE command inside each command block. This can be a call to any procedure either built-in or user created.
    3. The every command is not needed for work on paper, but can be added on the computer to smooth the animation.
    4. Each of your procedures can contain one of the following:    
       -A single ask statement
       -Two ask statements
       -An if/else statement
       -Two if statements


to go ;observer context
 ask turtles [ do-turtle-stuff ] ;this is a single procedure inside the []

since do-turtle-stuff does not exist, You must write that next.

to do-turtle-stuff  ;turtle context
    ifelse isHappy ;procedure 1 (this could have been a boolean expression too)
    [dance] ;procedure 2
    [wiggle] ;procedure 3

Now you must write all new procedures (isHappy/dance/wiggle) before you write the newer procedures that they will call.

2017-11-16 Conway HW

posted Nov 16, 2017, 6:35 AM by Konstantinovich Samuel   [ updated Nov 16, 2017, 9:37 AM ]

Conway Update  

1. Set your max pxcor and pycor to 60, set patch size to 4.

2. Add a chooser widget. This should select between "conway" and "rug" mode.

3. Conway: (same as yesterday)
go run the rule: B3 / S23
setup: random alive/dead

4. Rug: 
go run the rule: B234/ S_  (no numbers means no live patch survives.)
setup: a 2x2 square of alive in the middle.

5. Submit on the homework server slot by tomorrow 8am.

6. Fill out research project groups:


posted Nov 15, 2017, 6:20 AM by Konstantinovich Samuel   [ updated Nov 15, 2017, 9:15 AM ]

Goal: Cellular Automata

If you think about your code using big ideas and write functions to do those ideas, you will meet with more success.

Most of your cellular automata can be written in the following way using 'big ideas':

  EVERYONE  pickYourNextColor  

  EVERYONE  changeToNextColor   

Notice you are NOT storing a count, you are deciding on your color and storing the intended color you wish to change to! This prevents many kinds of problems!

PickYourNextColor will be different for different automata, but the separation of deciding what you want to be, and the changing into that new state must be clear.

LabN08  Conway's game of life: 
(this is a 2 day lab/hw,  we will continue tomorrow and address any issues you have!)


Patches are either Alive or Dead
Each type of patch exhibits different behavior. This is a variation on what you have done already with voting. 

Dead (pcolor is black)
    Dead patches sometimes stay dead, and sometimes are re-born.

Alive  (pcolor is ... NOT black, this allows any colors to be used!)
    Alive patches sometimes stay alive, and sometimes die.

Since you do not want random bits of code to just compare colors all the time, this is a good time to try to figure out how to write more meaningful comparisons!
How can you write code that uses:
isAlive     or    isDead        instead of comparing the pcolor?

You must be careful not to allow a patch to die and then to be reborn at the same time! 
In order to do this, do not change color right away, instead, make a variable to store the "nextColor" so that you can make sure everyone bases their next state on the current state. 

Similar to before, you calculate all patches first, then you change later:
ask patches [ calculate next color ]
ask all patches [ change to next color]

How do we store the next state?  (the state in this case is the color, there are many states that an object can be in)
Each patch needs to remmber what color it wants to be. How can you accomplish this?

How do we calculate the next state? We use different rules for each cellular automata:
Birth Survival  notation:
3B/23S is notation that means:

Dead cells 3B:    When a dead cell sees 3 living neighbors it will want to be born (otherwise stay dead)
Living cells  23S:  When a living cell sees 2 or 3 living neighbors the cell wants to stay alive (otherwise die)

Each cell should only do ONE of these. The easiest way of doing this is to have each patch decide what it wants to be next turn. After that completes you should have each patch change to that color. 

Here are some other rules:

Make slider:

Make Buttons:
* Setup
    -clear the world. Fill the world with some living patches (Use the percent-alive slider for the % you want to be alive)
* Go
    -Run your Conway model rules, calculating the next state and changing state.

To help test your code, allow yourself to paint living patches manually:
Make a forever observer button called paint, and have it call this function:

* Paint button (forever button, only have 1 forever button active at one time!)

to paint
  if mouse-down? and mouse-inside?
    ask patch mouse-xcor mouse-ycor
      set pcolor lime

Try painting a glider!

Where X is alive: 





You can save the patches and load them later! We can discuss this tomorrow.


posted Nov 14, 2017, 6:25 AM by Konstantinovich Samuel

-Pair Up
-Submit Color Spreading Lab
-Go Over leftover lab questions

Tomorrow: Conways Game of Life.

2017-11-13 HW

posted Nov 13, 2017, 5:58 AM by Konstantinovich Samuel

Model Library Assignment: 
Weighted as 30 points (a tad more than half a test) 
Due Monday 2017-11-20: The 1 page summary
Followed by a 3-minute presentation of EACH group over the weeks to follow.

You will pair up with another student of your choice. I may modify some pairs if I see cause to do so. You have until tomorrow 2016/11/17 to choose a partner. Tomorrow all people with no partner can have a discussion so that all members of the class are paired up. You do not have to sit next to your partner, you do not get class time for this. You will be required to collaborate outside of class.

Research:  Choose a model from the NetLogo models library.
You may not choose a game.
You may not choose a "code sample".
I will review which models were chosen in class tomorrow so that we do not have duplicates.

You should choose a simulation of something you find interesting because you will be learning about that particular model by looking at the documentation tab, and the code tab. (You can experiment by modifying the code if you like) 

Please ask questions about the specifications BEFORE the weekend. 

-You must explain how the model works - Big ideas mainly. (Be prepared to answer questions from me or the class.)
-You must closely examine at least two large ideas that we haven't learned in class.
-You may highlight any code that you thought was particularly elegant, or that helped you understand an idea.

1. Submit a summary of findings: 1 page typed + any diagrams. This is to be submitted on Monday. This includes much of what will be in the presentation. 
I will then call random groups to present, 2 per day until we are done.

2. Presentation : 3-4 minutes. 
Your presentation should NOT be you and your partner reading the summary. 

I will cut you off at 4 minutes unless you speak to me ahead of time. 
-Both members must speak for approximately half of the time. (Switch who is controlling the program)
-Give an overview of how the model works. 
    --First, give a very short demo of WHAT it does. One person should be talking, the other should be demonstrating the model.     
    --Explain the big ideas and any new features that were not gone over in class.
    --Give some details about the core features and how they are implemented. 
-DO NOT SHOW CODE. The goal is not to go over the code line by line.
-You should DO A PRACTICE PRESENTATION, and TIME YOURSELF over the weekend (use skype or whatever) so that you are prepared.

2017-11-10 LAB/HW

posted Nov 10, 2017, 6:12 AM by Konstantinovich Samuel   [ updated Nov 10, 2017, 6:32 AM ]

GOAL: Ask the bright patches to spread their own color in two different ways...

Do now:

On paper:
Write a function that reports an agentset of all turtles that are:
1. anywhere in the range of ALL red colors (the entire row of red)
2. facing one of the cardinal directions (North/South/East/West)

Getting the properties of other agents:

[PROPERTY ] of AGENT   gives a value from that agent.
[ PROPERTY ] of myself  Is a special usage with a keyword myself. is how any agent tells other agents their property when you are asking them something.

[age] of turtle 0
[size] of turtle 5
[pcolor] of patch 0 0
[pcolor] of one-of patches

You can do this using one-of, but you need to make sure there is at least one:

show [xcor] of one-of turtles with [color = red] ;this can crash!!!!

if any? AGENTSET
DOSOMETHINGWITH: [property] of one-of AGENTSET

if any? turtles with [color = red][
   show [xcor] of one-of turtles with [color = red]
   ;set var [xcor] of one-of turtles with [color = red]

Final command that involves getting values:  myself
When a patch or turtle asks an agentset, that agentset can look at the ask-er's properties!!!!

;turtle context
set xcor  (  [xcor] of myself  )  ;parenthesis for clarity    
                   ;xcor of the turtle that asked

You can use this in a command:
;patch context
ask neighbors [
    set pcolor [pcolor] of myself 
                    ;pcolor of the asking patch!


to setup
  ;1. Make a single random patch   red + 3   
  ;2. AFTER YOU TEST YOUR GO: modify this to make several patches random colors that end in 8

to go1
ask patches with [ isBright ] [ 

to go2
ask patches [ 
    if isBright  
    [ spreadColor ] 

;patch context
to spreadColor
    ;ask non-bright neighbors to become your color or a slightly darker color.

;Let us define bright patches as having a color that ends in a number higher than 2. 
;patch context
to-report isBright
 report true 
 ;replace with a boolean that is true when the patch has a color ending in a number higher than 2

2017-11-09 LAB05

posted Nov 9, 2017, 6:09 AM by Konstantinovich Samuel   [ updated Nov 10, 2017, 5:57 AM ]

Local Variables:

We use local variables because:

-we need to remember a number but only need it inside the current function

-we want to avoid repeating a complex calculation multiple times

-it is cleaner in our code to put a complex expression in a simple variable name:

-You want to remember a single random value, to use in multiple places:

This code is VERY hard to read, it also recounts the same agentset 3 times: 

if count turtles with [ abs pxcor + abs pycor > 20 ] < 10
   [ function1]
if count turtles with [ abs pxcor + abs pycor > 20 ] >= 10 and count turtles with [ abs pxcor + abs pycor > 20 ] < 100
  [ function2]

There is a repeating complicated calculation being made, that makes the rest of the code more difficult to read. We can replace this with a local variable to make it much more clear:
let badTurtles count turtles with [ abs pxcor + abs pycor > 20 ]
if badTurtles < 10
   [ function1]
if badTurtles >= 10 and badTurtles < 100
  [ function2]

You can also store random values, to use them in multiple places:

;3 code blocks have an equal chance of being run:
let n random 3
if n = 0 [ CODEBLOCK1 ]
if n = 1 [ CODEBLOCK2 ]
if n = 2 [ CODEBLOCK3 ]

;as long as the codeblocks do not change n, this will only trigger

;one of the 3 codeblocks!

This does not require ifelse, and it lets you run ANY kind of code, including report.

If you ONLY want pick VALUES randomly, you do not need to do this:

one-of [ 1 2 3 4] 

one-of [ red green blue]


both of these pick a random value from the brackets. 

BUT you could not run code this way

Goal: Patches can vote! 

Do Now: Log in, open NetLogo + lecture notes page.

Patches have two useful functions:



Check them out in the dictionary.

LabN05 Voting 

(submit in hw server by Monday 8am) 

You only get 1 lab period today however

Phase I - 2 color voting


All patches choose a color randomly to start. 

1. They then look at their 8 neighbors, and see how many red/blue neighbors they have. 

After everyone completes step 1:

2 Every patch decides if their neighbors are a majority of one color and if they are they change to that color.

The problem you will have: You will not finish 1 before starting 2. This means that some people are counting the new color instead of the original. This affects results unpredictably!

TWO WAYS of asking agents to do TWO THINGS:


ask patches[

Each patch runs BOTH A and B, before the next one starts. 

Halfway through half of the patches will have run A and B, the other half would have run NEITHER.


ask patches[  A ]

ask patches [  B ]

ALL patches run A. Then all patches run B.

Halfway through, all patches would have run A, and NONE would have run B.


Add monitors for each color so you can see approximately what percent wins in the end!


Assign each patch a pcolor of red or blue randomly.

Before you write more:

Patches must own some variables for this lab. They need to keep track of how many of their neighbors are a specific pcolor.

Go:  (make a forever button)

1. Make every patch to look at how many red/blue neighbors they have. They need to remember this number for later.

2. After everyone counts, make every patch to change their color if there is a *majority. They should stay the same if there is a tie. ( simple majority, 5 or more of one color.)

You must make sure step 1 completes before you start step 2. 

Separate these actions, because you don't want to count the UPDATED colors of neighbors, you want to count the ORIGINAL colors before the changes happen!

Phase II - 3 color voting

-Make a new monitor for green patches.

-Make a new button setup-3way : 

    Make the patches red, blue, green randomly.

-Make a button go-3way :  (make a forever button)

   If there is a majority of any one color ( 5 or more of any color ) then change to that color.

2017-11-08 LAB

posted Nov 8, 2017, 6:05 AM by Konstantinovich Samuel   [ updated Nov 8, 2017, 10:33 AM ]

lab Patches:

Now: Make 4 monitors that count the number of:
    -white patches
    -black patches
    -red patches
    -green patches

The reporters will change based on which button is pressed:

Change the world to have max x and y of 49.
Reduce your patch size to 4.

Make 5 buttons (and 4 corresponding procedures + any helper procedures)
1. RandomFourColors
Write a function that causes each patch to select a color randomly. They can only choose between: red, green , black, white

2. Stripes
-Write a function that changes the patches into three vertical stripes of colors red/white/green each taking 1/3 of the screen. (Calculate this value, so you can change your screen size)

3. Horizontal Stripes
-Write a function that changes the patches into single patch wide stripes of white/black/red/green. They must occur in that sequence:  

but it doesn't matter where the sequence starts at the top of the screen.

4. Checkers
-Write a function that changes the world into a black/white checkerboard of patches. Each patch is 1 checker space.

5 BigChecker - Challenge problem - try it in class but you don't have to finish it.
-Make a different version of checkers: Each checker space is a 2x2 set of patches!

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)


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. 


(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. 


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


(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 


;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


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.)


    -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! 
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 )

2017-11-01 HW

posted Nov 1, 2017, 6:38 AM by Konstantinovich Samuel   [ updated Nov 2, 2017, 7:09 AM ]

Goal: Go over lab + answer any remaining questions.

Do Now: 
Change Seats 

-How many ways to draw a grid?
    -patches centers are integers
    -basic ideas
    -fewest commands
-How many ways to make a rectangle of patches a specific color. 
    turtles as painters
-How many ways to make a border of patches?
    -if vs agentset
    -better booleans

Homework Due Wednesday 8am hw server ANIMATION:
Create a NetLogo animation. Your goal is to use all of your NetLogo skills to create an animation.
-You should try to use ALL of the NetLogo features we have learned so far!
-You must start with an empty NetLogo file and add everything yourself. 
-You may use random, but do not just make a bit mess of random things, your goal is to demonstrate you can accomplish your goals. 
-Have the turtles do a dance, make a rainbow, geometric patterns, or whatever you like. 
-Do not change the speed slider.
-Do not use large numbers or try to glitch the turtles into making odd patterns. 

1-10 of 43