Lecture Notes

Lecture:: 01-16-2013 (Last post)

posted Jan 16, 2013, 7:19 AM by Samuel Konstantinovich   [ updated Jan 16, 2013, 8:17 AM ]

Final Exam On Tuesday from 12:00 - 1:00
Arrive EARLY for the exam. If you are late, you do not get extra time. (If there is a massive subway delay that is most unfortunate for you.)
Room assignments
Period 3: room 333
Period 4: room 339
Period 6: room 431
Period 7: room 437
Period 10: room 525

Check your grades on the homework server. NOW, not after classes end. The last assignment titled "scheme" is blank for everyone, don't worry about that. 

Lecture:: 01-14-2013

posted Jan 14, 2013, 6:01 AM by Samuel Konstantinovich   [ updated Jan 14, 2013, 6:01 AM ]

A maz(ing) solver

1 Decide on what the start/end points of your path should be.

2 Decide which patches you cannot travel on. e.g. walls or pits are certain colors.

3 Set your starting point to a 'distance variable' of 0. We will use plabel for this to make it easier to see what is happening. All other plabels will default to "" (the empty string)

4 You need to make a function to calculate the total distance from start to end, and every patch in between.

   4a calculate by spreading: Every patch with a numerical distance variable should spread the distance to its neighbors (or neighbors 4) When you spread, you should increment the number so that each step is 1 unit farther. 

   4b You should make spread recursive, when should you not spread? The stopping condition matters!

5 You want to trace the path from the end back to the start, by painting the patches a specific color. You can use another variable instead of pcolor (so you don't mess up the world) but we will use pcolor so we can see what is going on. 

   5a The "solve" command should ask the ending patch to trace a path
   5b The trace command would then find the smallest neighboring distance and change that to blue, and call the trace command on that path.
   5c When should you stop calling trace?

By making the calculation and the tracing recursive, you can run this in the span of one go. This means you can re-calculate a path every go command if you want to. 

Lecture:: 01-10-13

posted Jan 9, 2013, 1:58 PM by Samuel Konstantinovich   [ updated Jan 9, 2013, 1:58 PM ]

PRACTICE FINALS are posted on the Introduction to Computer Science Section of the website. (On the left menu bar)

Grade Related Things:
There will be no quiz on the project. Instead the project will just be weighted as a test + quiz.
The added documentation I added to the project will justify this modification. 

Other commands:
other: a command which removes 'myself' from an agentset.
zombie can ask the closest ZOMBIE to die. But if you ask the closest 'same breed as yourself' to die, that is probably going to be you! When you minimize distance to yourself, you are the closest unless you are talking about another breed.

other agentset   will return the agentset with the agent that calls the command removed from the agent set. 

a player can kill their strongest other opponent (if he was the strongest he does not want to kill himself):
ask max-one-of other players [score] [die]  

a zombie can ask the closest OTHER zombie to do '...' :
ask min-one-of other zombies [distance myself] [ ... ]

Lecture:: 01-08-2013

posted Jan 8, 2013, 6:24 AM by Samuel Konstantinovich   [ updated Jan 16, 2013, 8:20 AM ]

Final Project Schedule:

1/8 - Final Project Time + Short lecture regarding Zombies / Monsters
1/9  - Final Project Time 
1/10 - Final Project Time 
1/11 - Exam
1/14 - Maze Solver
1/15-1/18 Final Project Time * There may be 1 or 2 short lectures 

1/21 at 11:59 Project Due. Since you have working copies every day, I will deduct 20% of your grade every day late. Submit a 'zip' or 'rar' of all of your working copies along with your data files. If you don't know how to 'zip' or 'rar' files together use google/youtube to learn. (it is really useful)

Don't submit late. Submit your latest working copy ON TIME.

Final Project Methodology:

-Decide on one or two features you want to add first and try to get them to work.
-Levels or maps are not required (at first) to get your characters moving and working (partially)
-You should start with one or two level/map and test most functionality before working on multiple levels. (remember: Multiple maps are not as important as working characters)
-If there is a mathematical challenge to overcome, feel free to get outside help.
-When you have turtles move, remember everyone moves a little bit each time the go command triggers: Each Human,Zombie,bullet,etc moves one step in the go command, The bullet may move faster (take a bigger step) and then check if it collides each time it moves. [DO NOT: Make any single turtle move until something happens (like make a bullet move until it hits something, or make a turtle move in a pattern) or every OTHER turtle will wait for it to finish this motion.]

1. You are to keep a daily "working copy" for every day in class and every weekend you work on the code. If you already wrote something, that is your starting version. 
Save each version with the date. Please use the date: 09 10 etc in your filename. e.g.  Zippy09, Zippy10,Zippy11... Zippy19 etc.

Assuming you combine your work in class, or at the end of a weekend you must have at least these 8 versions submitted:
09, 10, 13, 15, 16, 17, 18, 21 (final version)

You may create more versions, including versions on more dates or multiple versions on the same day such as 13a, 13b.

You will keep EVERY working version, and submit all of them together. Include all the versions of the nlogo files in the same folder, so they can use the same data files. DO NOT save each version in a different folder!

2. You are required to spend at least 30 minutes every night working on this code in addition to class time and at least 1 hour on weekends.  You have 8 school days (4 hours) + 2 weekends of at least 1 hour each: That gives you 6 hours X 2 people  = 12 hours of coding time MINIMUM. Coding time does NOT include making shapes. Turtle shapes are purely for show and are not a "requirement". If you want to make shapes it is because you want it to look cool, and that is encouraged, but please don't confuse "making shapes" with "coding time." However: The code that makes the shapes change or makes animation using multiple shapes DOES count

3. Class time: 8 days, lets say 30 minutes a day of combining code and coming up with how to proceed. Your time is best spent trying to put together what you worked on the night before, and fix problems you cannot solve on your own, with your group or even other groups that may be able to help. 

4. You must fill out the documentation tab with:
- COMPLETE instructions
- BUG list (EVERY version should have this to log what is wrong)
- Citations: You must cite and give credit to anyone that helps you or outside sources used. There is no MLA or any style of citation when talking about other people's netlogo code or projects, just explain who helped you or what you used as reference. When using other people's code as reference, that means you use it to figure out HOW to write yours, not use their code. 

5. You should maintain a "changes" document, to list any functional changes you made. (I don't care if you changed the colors or the images) 
-If you add or remove features, list it here. 
-If you remove a features, you should include the code that you removed OR a reference to which working version has the code.

Jan 9th:
-player breed
-player controls. 

Jan 10th:
-monster creation and movement
-player ability to interact with monster

Jan 11th:
- monster AI

Jan 12th
Design Change: 
-monsters to stay in place
-Monster AI (see version 10)

6. You are to document who writes what parts of the code as comments. If you both worked on something in class together, give an approximate % of how much each person contributed.  EVERY FUNCTION requires a comment as to who wrote it, or how much each person wrote.


;worked on this in class together 50/50
to foo
  ask patches [foostuff]
  ask turtles [otherFooStuff]

;Bob wrote at home
to foostuff

;Dave wrote at home, then we fixed it a little in class together
to otherFooStuff
;added this part in class:

Lecture:: 01-07-2013

posted Jan 7, 2013, 6:17 AM by Samuel Konstantinovich   [ updated Jan 8, 2013, 10:31 AM ]

Ack Monsters! Activity (for this activity, sliders will be denoted with the bold and underscores e.g. num_people

You will learn to make breeds behave in different ways depending on their state. Like with a corpse person vs a tired person.

There are two breeds: monsters and towers.


Create num_towers towers, and num_monsters monsters.
The towers should be white, and "house" shaped. 
The monsters should be gray, and you can import a "monster" shape from the turtle shape editor. 
All turtles should be size 2 and placed randomly on the world. 

Every time the program runs go:
Tower behavior: all towers rotate by rotate_speed degrees, and project a cone of light (yellow patches) This cone is tower_angle degrees wide, and tower_radius long.  

Monster behavior:
Monsters on a yellow patch turn "scared" 
Monsters on a black patch turn "angry"
You may want a variable to keep track of the state. Only monsters need this variable.
*Optionally make the monsters have different shapes for angry and scared states.*

Angry monsters:
 Fade* to color 2.
 Wiggle at a speed of .3 and random angle of 30. This makes the monster travel across the screen like a normal wiggle. 

Scared monsters:
  Fade* to color 8.
  Wiggle at a speed of .1 and random angle of 360. This makes the monster wiggle in place like they are scared. 

*:When I say fade that means the monster changes its color by 0.25 towards that color every time so that the color changes slowly.

Lecture:: 01-04-2013

posted Jan 4, 2013, 6:20 AM by Samuel Konstantinovich   [ updated Jan 4, 2013, 6:36 AM ]

Note: Submit your scheme portion of the vacation homework on the homework server tonight. 

Zombies vs Humans II : revenge of the zombies (complete over the weekend if you don't finish in class)

Swap code with your partners. You must implement several new features using their code as a starting point. 

New Features

5: Humans also need a shape for “tiredPerson” that is just a hunched over person. When their stamina is 5 or less, set their shape to “tiredPerson” otherwise set their shape back to “person”. This shows you when people are tired visually.

6. Zombies have a zombie_vision_angle (make it a slider from 1 to 360, default to 100) and should now use in-cone instead of in radius. Look up the in-cone command in the dictionary!

7: Humans now have a corpseTimer variable. Humans with a CorpseTimer of 0 behave normally(they do peoplestuff). Humans with a corpseTimer other than 0 do corpseStuff instead.


change shape to “corpse”

decrease corpseTimer by 1

when the timer reaches 0, make a zombie and die (or change into a zombie).

8. Zombies now have new features:

When there is a human with a corpseTimer of 0 on the same patch as the zombie, the zombie will set ONE of those human's corpse_timer to 20.

When there is a human with a corpseTimer other than 0 on the same patch the will run an eat command instead of chasing/shambling.

The eat command just changes the zombie's label to “Brains!”. The zombies should reset their labels to “” (empty string) when they are not eating, so this clears away.

Lecture:: 01-03-2013

posted Jan 2, 2013, 10:33 AM by Samuel Konstantinovich   [ updated Jan 3, 2013, 6:19 AM ]

Important: Make sure you show me your colors/edge detection labs from before break. Have it open before you call me over. Have it open in a SECOND netlogo window while you do your work. (If you don't know how to open a second window, ask someone)

Zombies vs Humans

1. Overview:

-You will work on this today. Do not work with you partner on this project, if you want help, please ask someone else. After tomorrow you will be required to swap your file with your partner, and add new features to your partner's code. This means you should be writing things in a readable and clear way (no crazy variable names or poor spacing/newlines)

2. Zombie Behavior:

-When there is a human in a radius of zombie_vision_radius (make a slider), the Zombies chase after the closest human at a speed of 1. Otherwise they shamble. Shamble is a slow wiggle (.3 speed). 

-When a zombie catches a person (the person is on the same patch as the zombie) the person dies, and a new zombie is created it should look like the other zombies. 

3. Human Behavior

-People run away from zombies that are closer than human_vision_radius (make a slider) units away. Humans that are not running just wiggle (speed .5). When a person is running they move at speed 1.5. 

-People can only run if they have some stamina left, otherwise they just wiggle. People start with maximum_stamina (make a slider). Their stamina decreases by 2 every time they are running, but when they wiggle, they gain 1 stamina (but no more than max_stamina.

4. Miscellaneous:

- Make Sliders for starting_zombies ( 1-20), starting_humans (1-100)

- Make Slider for maximum_stamina

- Make Sliders for zombie_vision_radius, and human_vision_radius

- Make Monitors for : the number of zombies and the number of humans

- Your project should run at an appropriate speed. 

- Zombies are all green, humans are all orange.

- Optionally make a custom shape “zombie” in the shapes editor (spend NO MORE THAN 2 minutes on this) Make sure you duplicate the “person” shape instead of just editing it, or you will lose the person shape.

Lecture:: 01-02-2013

posted Jan 2, 2013, 5:28 AM by Samuel Konstantinovich   [ updated Jan 3, 2013, 5:31 AM ]

Exam: Next Friday: Breeds and Turtle/Turtle + Turtle/Patch interaction.


Today we will talk about breeds. Here are new commands you should know:

min-n-of   ; look at documentation as I didn't show it in class

There are lots of commands like ask  which aren't new, but have added features with breeds. You can ask a breed like ask cars, or ask sheep. You should look at the commands that have <breeds> in the netlogo dictionary, as they are available to you to use.

Sample in-radius commands:

;this paints the patches in a circle white
to colorRadius  ;turtle OR patch context
    ask patches in-radius 8 [set pcolor white]

;this tells you how many nearby turtles there are:
count turtles in-radius 5

Code from class:

breed [cars car]

breed[ wolves wolf]

to setup


  set-default-shape wolves "wolf"

  set-default-shape cars "car"

  create-wolves 5 [set size 2]

  create-cars 5 [set size 3 fd 4]



to go

  ask wolves [wiggle]

  ask cars [carStuff]

  wait 0.05


to wiggle

  rt random 40

  lt random 40

  fd 1


to carStuff

  let x wolves in-radius 5

  if any? x

  [face min-one-of x [ distance myself]]

  fd .5


Lecture: 12-19-2012

posted Dec 19, 2012, 6:26 AM by Samuel Konstantinovich   [ updated Dec 21, 2012, 6:06 AM ]

Vacation Assignment: Due Friday January 4th. You have 4 school days and a vacation to work on this, so I have very high expectations : weighted as 5 homeworks
A. Scheme Practice 

Write a scheme function (shuffle A B) that takes two lists A and B, and returns a new list with the elements of both the lists shuffled together in alternating order, starting with the first element of A. 
(shuffle '(a b c) '(1 2 3))  returns:  (a 1 b 2 c 3)
(shuffle '(red foo) '(sky blue)) returns: (red sky foo blue)

When one of the lists is longer than the other (see below) then it shuffles as many elements as it can, then uses the remaining elements of the longer list.

(shuffle '(x y) '(a b c d)) returns: (x a y b c d)
(shuffle '( hey yah) '() ) returns: (hey yah)

B. Final Project Prototype

Prototype your project: (This involves no coding)
  • You will refine/modify your proposal. Decide on more features, be more specific about how you want the project to flow. What are the different modes/parts/levels, when should the program transition between them. (Don't worry about how you will do things yet)
  • Draw / Design your user interface to your project. This includes buttons/sliders/widgets. You should label them and provide descriptions (on a separate typed page) of what each part of the user interface will do/what are they going to be used for. You can leave your "world" view blank here. Keep things basically to scale.
  • Draw / Sketch / Design the different "world" views of your project. You probably want to draw it larger so you can put in more details. Some games always have the same game screen (like Tetris) , while others have menu screens, or a screen that changes when you move to a new area (side scrolling/platform games) 
Drawings: Straight edges should be straight (use a ruler), text should be NEATLY written, the pictures should be reasonable to what your project should look like, but stick-like figures are fine for turtles.
Proposal / Descriptions should be typed. 

You are handing in: (one per group)
Updated proposal (typed) including : Your Super Awesome Team Name!
Interface Design (drawn)
World Design(s) (drawn)
Description of widgets/interface (typed)

Lecture: 12-17-2012

posted Dec 18, 2012, 5:28 AM by Samuel Konstantinovich   [ updated Dec 18, 2012, 5:28 AM ]

Here is the image manipulation code from class:

patches-own [originalColor]

to setup
  import-pcolors "car.jpg"
  ask patches [set originalColor pcolor]

to reset
  ask patches [set pcolor originalColor]

to grayscale
  ask patches [set pcolor pcolor mod 10]

to randomNeighbors
  ask patches [set pcolor [pcolor] of one-of neighbors]

to melt ;streak downwards
   ask patches [ set pcolor [pcolor] of patch (pxcor) (pycor + 1) ]

;use this function using the named color values, like:
; replace red blue   
;replace black white
to replace [ orig final]
  ask patches with [pcolor >= orig - 4 and pcolor <= orig + 4] [set pcolor pcolor - (orig - final) ]

1-10 of 34