12-17-2013

posted Dec 17, 2013, 5:30 AM by Samuel Konstantinovich   [ updated Dec 17, 2013, 3:48 PM ]
DO NOW:
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. 
examples:
(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)

Exam: Friday: Does not include Breeds. 

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


breed 
set-default-shape

NOTE:
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]
end

;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

  ca

  set-default-shape wolves "wolf"

  set-default-shape cars "car"

  create-wolves 5 [set size 2]

  create-cars 5 [set size 3 fd 4]

end

  

to go

  ask wolves [wiggle]

  ask cars [carStuff]

  wait 0.05

end


to wiggle

  rt random 40

  lt random 40

  fd 1

end


to carStuff

  let x wolves in-radius 5

  if any? x

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

  fd .5

end

Comments