ClassroomIlness - Boone County Schools

Problem 5 Classroom Illness Program Solution
This document provides pictures of a working Tynker program that fulfills the classroom
illness and hand washing problem in the Modeling and Simulation module. This solution
uses just one actor and clones it to make the needed number of agents. There is
another possible solution that uses two actors, one for healthy and one for sick.
Students should create a solution that makes the most sense to them. There is often
more than one right answer in computer science!
I. Initialize variables and agents in Stage on start script.
1. Create global variables:

numstudents

numsick

numhealthy

count
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Problem 5 Classroom Illness Solution – Page 1
2. Clear the screen from any previous run of the program.
3. Ask user for parameters and set the appropriate variables to the user’s answers.
a. numstudents = total number of students
b. numhealthy = number healthy students to start with
c. numsick = number of sick students to start with
d. susceptibility = hand washing rating (1-5)
4. Run a loop to create the correct number of sick clones and healthy clones
a. Initialize counter to 0.
b. Repeat a loop the number of times indicated by the variable
numstudents.
i. Increment counter each time a new clone is made. This counter
is checked in the agent’s clone startup script to create the
correct number of sick and healthy clones. See the agent’s
program explanation below for more information about how the
counter variable is used.
II. Set up each student in agent’s clone start program.
This solution uses two different costumes for the agent: one “sick costume” and one
“healthy costume.” You can find these costumes in the Sci Fi category by scrolling to
the bottom row and then swiping all the way to the right. You can add a new costume
and rename the costumes in the actor’s properties page. There are other ways to
indicate healthy and sick status. This example simply shows one possible solution.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Problem 5 Classroom Illness Solution – Page 2
1. Hide the original agent actor by using the hide block in the on start script.
Remember: Every new clone inherits the properties of the original actor, so new
clones will start out hidden.
2. Create local variables mystatus and mysicktouches. Each agent clone gets its
own local variables to track how many sick agents they have touched, and
whether they are sick or healthy. Of course, these variables can have any name
that makes sense to the programmer.
3. During clone startup script:
a. Use show block to make the new clone visible
b. Initialize counter variable to 0
c. Go to random location
d. If the variable counter is greater than the variable numsick (the value of
the parameter set to the number of sick students during stage on start)
then set up this clone as a healthy clone. Otherwise, create a sick clone.
e. Move randomly forever
f. Note: this code shows a say block being used to display the agent’s
mysicktouches value. This is a good debugging technique!
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Problem 5 Classroom Illness Solution – Page 3
III. Program the behavior of the agents when they touch each other.
1. When touching clone of agent: (Use clone of agent block!)
2. Check to see if this is a healthy agent.
a. If yes, check to see if the agent being touched is sick.
b. If yes, increment the local variable mysicktouches by 1.
c. Check to see if mysicktouches is now at the susceptibility threshold.
i. If yes, set this clone’s mystatus to sick and change its costume to
the sick color.
IV. Monitor for ending condition of numhealthy reaching 0. (Stage program)
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Problem 5 Classroom Illness Solution – Page 4
When variable numhealthy has decreased all the way to 0 (meaning all students are
sick):
1. Clear any existing writing on the stage.
2. Write data to the stage simulation time, numsick/numstudents ratio, and hand
washing rating.
3. Stop the actors.
Remind students that the say block is a good debugging tool. In the image below,
the agent clones are saying the value of their sick contacts variable. The say block is
in the purple Looks category.
Variables start out as “null”—with no value at all. The when numhealthy=0 event
triggers when the number of healthy students 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!
Note: Sometimes when you start the program on Tynker it will immediately go to the
final data screen. Just click the stop button and then the play button. Tynker often
has values saved from the last run of the program.
© 2015 Project Lead The Way, Inc.
PLTW Launch – Infection: Modeling and Simulation Problem 5 Classroom Illness Solution – Page 5