DinoEcosystem - Boone County Schools

Project 4 Dino Ecosystem Program Solution
This document provides an explanation of a program that fulfills the Dinosaur
Ecosystem challenge in the Modeling and Simulation module.
Stage Program
1. Initialize a timer by putting the reset timer block (Sensing category) into the
stage’s on start script.
2. Place a clear block (Drawing category) into the on start script to clear away any
text from a previous run of the program.
3. Ask user for parameter values by using the ask and wait block for each
parameter (Sensing category). Store the answer value in a variable using the set
variable block. (Create new global variables in the Functions category).
4. Create clones of the three actors according to the numbers specified in the
parameters.
5. Monitor for either food source running out.
a. The when true occurs block will continuously check to see if
num tritops = 0 or num bushes = 0. When that statement becomes
true, the blocks underneath will run.
b. Write the data to the screen and stop the program. The draw text block
links together text and variables.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Project 4 Dino Ecosystem Program Solution –
Page 1
Note: Variables start out as “null”—with no value at all. The when num bushes=0 or
num tritops = 0 event triggers when the value of one of those variables falls to 0. If
variables started out at 0 then this event would trigger as soon as the program
started and that would be a bug!
T-Rex Program
1. Hide the original t-rex actor by putting the hide block in the on start script.
Remember that all future t-rex clones will inherit the hidden property from the
original actor.
2. On clone startup
a. Initialize my energy to 0.
b. Go to random location
c. Show the clone by using the show block. Each clone starts off hidden
because the hide block in the on start script made the original t-rex
hidden. All of its clones start out with the same properties.
d. Move randomly forever
3. When I receive a message to increase energy, add 1 to my energy (This actor
and all of its clones have a local variable called my energy.)
4. When my energy reaches trex spawn energy, add 1 to num trex which holds the
total t-rex count, and then clone a new t-Rex. Reset my energy to 0 so that this trex can start building up energy to spawn again.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Project 4 Dino Ecosystem Program Solution –
Page 2
Note: The t-rex and the tricertatops each have a local variable called my energy that
you have to set up inside each actor’s program. You can name these variables anything
you like. In this example both of the local variables are called my energy.
It might be easier to have students use two different terms, such as this-trex-energy and
this-tritops-energy as this will make it very obvious that these are two different variables
and that they are local to each actor, and to each of the actor’s clones.
Some people choose to use dashes rather than spaces to make variables easier to
identify. This is a matter of personal preference since the Tynker programming
language allows spaces in variable names.
Triceratops Program
1. Hide the original triceratops actor by putting the hide block in the on start
script. All future triceratops clones will start off hidden!
2. On clone startup
a. Initialize local variable my energy to 0.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Project 4 Dino Ecosystem Program Solution –
Page 3
b. Go to random location
c. Show the clone by using the show block.
d. Move randomly forever
3. When I receive a message to increase energy, add 1 to my energy variable
4. When my energy reaches tritops spawn energy, add 1 to num tritops which holds
the total triceratops count, and then clone a new triceratops. Reset my energy to
0 so that this triceratops can start building up energy to spawn again.
5. Monitor for when I am touching a t-rex.
a. Send message “increase energy” to the t-rex clone that touched me
b. Update the total number of triceratops by subtracting 1 from num tritops
c. Delete myself (Note: Once this clone deletes itself its program is gone, so
all blocks should appear before the delete block!)
Remember: The variable my energy must be a local variable.
Do not check Global Variable when creating this variable.
Encourage students to use different variable names for the local variables to
track energy for t-rex and triceratops. This example uses the same variable name
for both.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Project 4 Dino Ecosystem Program Solution –
Page 4
Bush Program
1. Hide the original bush actor by putting the hide block in the on start script. All
future bush clones will start off hidden!
2. On clone startup
a. Go to random location
b. Show the clone by using the show block.
3. Monitor for when I am touching a triceratops.
a. Send message “increase energy” to the triceratops clone that touched me
b. Update the total number of bushes by subtracting 1 from num bushes
c. Delete myself (Note: Once this clone deletes itself its program is gone, so
all blocks should appear before the delete block!)
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Project 4 Dino Ecosystem Program Solution –
Page 5
Debugging Tips
Use the Say block to view values stored in variables
Remind students that the say block is a good
debugging tool. In this image, each t-rex clone is
saying the value of its my energy local variable. The
say block is in the purple Looks category.
Hard code parameters to save time
If you find that students are spending a lot of time
typing in the parameters, you can show them how to
set the parameters with set variable blocks rather than
using the ask and wait blocks.. This should be treated
as a temporary setup just to make it easier to test the
program. In computer science this is called “hard
coding” the parameters because their values are not
changeable.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Project 4 Dino Ecosystem Program Solution –
Page 6