Add a predator

advertisement
GUTS Introduction to Starlogo TNG
Adding a Predator to a Simple Ecosystem
In this activity, you will learn to add a predator to an aquatic ecosystem model. You will
be introduced to making agent variables and how agents can be programmed to
interact with other agents.
In the models library, open Fish and Plankton. First,
look through the code pieces for the program. Go
through each group and describe the purpose for
each group of blocks. For example, the Fish Up n
Down procedure allows the fish to go up a maximum
of 1 steps or down by 1 step (more precisely, up by –1
steps). If the fish’s altitude is less than the bottom of
Space land (altitude of 1) then set the fish altitude
back to 1, if the fish’s altitude is greater than 30, set it
back to 30. In other words, the fish cannot go lower
than 1 or higher than 30.
After studying and understanding the code, you are going to add a predator to the
existing model.
Part I: Creating the predator and its movements
Click the Edit Breeds button and add a new breed that will
be your predator. When you have chosen and named
your predator, click “OK”.
Add a Create num/do for the predator to the Setup stack
(you’ll find this in the My Blocks, blue drawer for the
predator). We’ll start with just one predator for now and
make it size 10 (set size is in the Traits drawer) so it is bigger
than the fish.
Add simple movement to the predator by connecting a
Forward block to the Forever area of the Runtime.
Check to make sure the above steps are working by going to Space land and hitting the
Setup and Forever blocks. Also, make sure to save your project and renaming it to
personalize it.
Part II: Predator ‘eating’ by using a Collision block
As of now, your predator is just moving forward. If it comes in
contact with a fish, nothing happens. In order for it to
appear like the fish is ‘eating’ we need to use a Collision
block and make the fish ‘die’ when a predator comes in
contact with it.
Go to the Collisions drawer (in My Blocks) (or in earlier
versions of Star Logo, the predator drawer) and you will see a
series of gray collision blocks. Pull out the Predator/Fish Collision block and place it in the
Collisions column. Get a Die block from the logic draw and attach it to the Fish area of
the collision block.
Now run your model and see what happens to the aquatic ecosystem.
At this time, you can add more ‘natural’ movement to the predator by copying the code
for how the fish move (up n down and move but giving it new names). We’ll discuss the
blue energy variable in the next section.
Part III: Adding Energy to the predator
Right now the predator is moving and ‘eating’ fish and is having an effect on the
ecosystem. The predator should also follow similar rules in the ecosystem such as losing
energy as it moves, gaining energy as it eats and dying if it doesn’t have enough energy.
First, we need to create a variable by using an Agent Number Variable and renaming it
Energy (there is no such block as an “energy block”).
Go into the Variables
drawer
pull out and agent number
block and put it in the
predator column
rename it
‘predator energy’
The new ‘predator energy’ block is called a declaration. This block ‘declares’ a new
variable for the predator and does not connect to anything. It is a good idea to add a
comment to this block, reminding yourself not to delete it. Now look in the My Blocks
predator drawer and you will see a series of new blocks related to this energy variable.
These are the blocks that are then used in the program.
We can now use the Fish code to help us create the programming for the Predator, since
much of it will be the same, except substituting Predator Energy where appropriate.
Setup- the predator must be given energy when created.
Movement- as the predator moves, it should lose a very small amount of energy
(incrementing by a negative number).
Eating- when the predator eats (collides with) a fish, the predator should gain some
energy (increment by a number).
Reproduction- if the predator has enough energy, you might want it to be able to
reproduce.
Death- if the predator hasn’t eaten enough fish, it won’t have enough energy and will
therefore die.
Make sure to save your program!
Test your program to see how the new additions work. You might need to spend some
time adjusting the numbers to get your ecosystem to behave the way that you want it,
but using the same numbers on the predator energy variables as the fish energy numbers
can work, changing the numbers will give different effects.
Making the predator chase its prey can be done but is a more advanced programming
level than at this time. Check out the Cookbook pages at the Project GUTS website to see
code pieces for chasing and running away if you’re interested in learning more.
Download