Need help figuring out what this code does.

Posted November 3, 2016 by ilee
  1. “First we will do a Model Observation” –   open the model and play with the model then answer the following questions.
    • Who/what are the agents in a model?
    • What are the interactions in a model?
    • What is the environment in a model?
    • How do you think this model works (in general terms)?
    • What are you observing when the simulation is run?
  2. Now we are going to ask some more questions:

    “Next, we are going to ask you to look at the code below. 

  • What happens when the forever button is pushed?
  • Describe what happens each time through the main forever loop

Code blocks that I don't understand (YET)


Submitted by turtle on Wed, 11/09/2016 - 11:08 · Permalink

So, for the first set of questions, I would say that the agents are blue and red squares which set up scattered.  When you hit forever, they seem to jump around a little bit and end up in segregated clumps.  The environment is just the basic green background and the agents don't seem to interact with it.  I think the model works by some complicated math formula relating to slider #1 - the agents count who is near them with their same color, divide by who is near them, and compare to the slider setting -- if less, they scatter.  It seems like some kind of segregation model, where the colors start scattered and end up with like colors in clumps.

#2 is sort of what I said -- each iteration, the turtle compares the number of turtles near it (within 6) with its own color, divided by the total number of turtles near it, and if that is less than the slider setting, the turtle scatters itself.

Submitted by ilee on Thu, 11/10/2016 - 13:13 · Permalink

Great observations Su.  Yes, it does seem that the agents clump together by color.  But why do they stop?  Are they done? or does the simulation time out?   I'm still trying to tell if the agents change color or if they always stay the same color.

For #1, Do the agents set up in the same place each time?
  and do you think there is any interaction between the agents?  like spreading a color from one to another?

For #2, I think your description is right on.  The agent scatters if the condition is true.  Does each turtle do this before the other turtles do their check?

(I'm thinking for a more realistic view of this we might want to try converting Tryangles this way.)