We're going to continue working with the 'Heroes and Cowards' model today
and we're going to talk a little bit about how you might want to extend it
which is a topic we're going to get into in a lot more detail in the upcoming units
One of the first things you might ask after you've been playing around with it
is - what if not everyone is a hero? Or what if not everyone is a coward?
Right now, the model doesn't allow that.
One way we can fix that is that we can edit the chooser
to allow 'cowards', 'heroes', and 'mixed' personality types.
So now, if we go over to the code,
we have to figure out how to address what happens when the personality type is 'mixed'.
The first thing I would do is find all the places where I'm using 'personalities',
and the only place I'm actually using it is just this one spot in the setup,
because after that I set the color, and the color represents the personality.
So I could then use this one spot to help me figure out how to set up the personalities.
'if ( personalities = 'mixed' ) ['
And what do I want from a personality of mixed?
What I want is for some of the people to be cowards, and some to be heroes,
which essentially means some of them are red and some of them are blue.
So what I can do is I can say set the color to one-of...
and here I'm going to create my own list, which is red and blue:
'[ set color one-of [ red blue ] ]'
so this says set the color of this particular agent to be one of either red or blue.
So when I click back over and I set the personalities type to 'mixed',
you'll see I get a mixed group of individuals, some are red and some are blue.
Now you might ask the question, what's going to be the outcome?
Well, if I let it run you'll see that you get some very interesting behaviour,
some of them are on the sides, some of them are frozen in the middle.
In fact, this is something that really depends upon where the turtles started,
where they wound up, and which exact turtles wound up red and blue.
We're explore that in a little more detail...
when we look at the actual 'Heroes and Cowards' model that was built for the textbook.
I want to look at one other thing before I stop extending this model
I want to think about extending it to visualise who my enemies and friends are.
So let's say you like your model, you like what it's doing,
but you're not 100% positive that it's working the way you want it to work.
Let's take this simple example of 'Heroes'
where you're trying to move between two individuals.
One thing you might want to do is use the turtle inspectors to debug your model.
So I'm going to inspect one of these turtles,
we showed this before, and now they have these properties of 'friend' and 'enemy',
and what I can do is create some visualisations...
to help me explore whether the model is actually working the way I want.
So, I'm going to have this focal turtle, which is turtle 98...
create a link with its friend,
and I'm going to set the color of that link to be green.
Now I've created that. Unfortunately, you can't blow up the turtle window,
so I can't make it any bigger for you to see.
Now we'll have it create a link with its enemy,
and have it make the color of that link red.
So now you can see where this turtle is,
and so we know, from the 'heroes' rule, that if this is its 'friend'...
and this is its 'enemy', this turtle should move to roughly this location.
So we can turn the speed down, and see, does the turtle move there?
Well, first of all as you can see it turns around right away
and starts to head in that direction
so that's given me pretty good confidence that it's doing what I want.
Now I can speed it up a little bit
Of course, it needs to keep updating its own destination
because the friend and the enemy are also moving under their own set of rules.
And now it's gotten to be half way between
it's just oscillating back and forth
and you can see the friend and the enemy are moving back and forth as well.
So this is a cool little way I often use the inspectors to debug my code
to make sure it's doing what it's meant to.
Of course we can do the same thing with the cowardly code as well.
So that's a great way to extend your model in a way that allows you to debug.
You could have all the different turtles display their friend and enemy links
but that might clutter up the display quite a bit,
so if you're using it for debugging it's usually easier to do it for just one.
In the next lecture we're going to talk about...
some of the things this model can teach us about documentation..
and random numbers.