# CSC 180 H1F Project # 1

\$30.00

## Description

• Explain any conditions that the function assumes are true. Examples: “n is an int”, “n != 0”,
“the height and width of p are both even”.
• Be concise.
• Ensure that the text you write is grammatically correct.
• Write the docstring as a command (e.g., “Return the first . . . ”) rather than a statement (e.g.,
“Returns the first . . . ”).
Engineering Science, University of Toronto Page 4 of 8
CSC 180 H1F Project # 1 — Gamification of Exercise
Gamification is the integration of elements found in games – such as points and badges – into nongame activities. One example of gamification is students’ being awarded badges and points for completing
exercises in online courses. This is done in order to encourage students to complete the exercises. Another
example is supermarkets awarding points to customers for purchasing various items. This is done, in part,
to induce the customers to purchase more items in order to gain more points.
In this project, you will implement a simulator for an app that encourages the user to exercise more
by awarding “stars” to the user for exercising. The simulator will model how the user behaves, and could
be used to try out various strategies for awarding stars.
We imagine the user as accumulating “health points” and “fun points” (sometimes called hedons).
Every activity is associated with gaining some number of health points and some number of hedons.
Receiving a star increases the number of hedons that the user gains from performing the activity. Receiving
too many stars too often makes the user lose interest in stars altogether.
The simulation proceeds as a series of operations, which are simulated using calls to the functions that
you will define. For example, a simulation might proceed as follows:
if __name__ == ’__main__’:
initialize()
perform_activity(“running”, 30)
print(get_cur_hedons()) #-20 = 10 * 2 + 20 * (-2)
print(get_cur_health()) #90 = 30 * 3
print(most_fun_activity_minute()) #resting
perform_activity(“resting”, 30)
offer_star(“running”)
print(most_fun_activity_minute()) #running
perform_activity(“textbooks”, 30)
print(get_cur_health()) #150 = 90 + 30*2
The lines in the code above correspond to performing various activities (running, resting, carrying
textbooks), for various durations of time, as well as querying the system for the number of health points
and hedons that the user accumulated and querying the system for the activity that would gain the user
the most hedons if it were performed for one minute.
We assume that the use is always either running, carrying textbooks, or resting.
The user accumulates fun points and health points according to the following rules.
• The user starts out with 0 health points, and 0 hedons.
• The user is always either running, carrying textbooks, or resting.
• Running gives 3 health points per minutes for up to 180 minutes of running resting or carrying
textbooks, and 1 health point per minute for every minute over 180 minutes that the user runs.
(Note that if the user runs for 90 minutes, then rests for 10 minutes, then runs for 110 minutes, the
user will get 600 health points, since they rested in between the times that they ran.)
• Carrying textbooks always gives 2 health points per minute.
• Resting gives 0 hedons per minute.
• Both running and carrying textbooks give -2 hedons per minute if the user is tired (definition: the
user is tired if they finished carrying running or carrying textbooks less than 2 hours before the
current activity started.)
Engineering Science, University of Toronto Page 5 of 8
CSC 180 H1F Project # 1 — Gamification of Exercise
• If the user is not tired, running gives 2 hedons per minute for the first 10 minutes of running, and -2
hedons per minute for every minute after the first 10.
• If the user is not tired, carrying textbooks gives 1 hedon per minute for the first 20 minutes, and -1
hedon per minute for every minute after the first 20.
• If a star is offered for a particular activity and the user takes the star right away, the user gets an
additional 3 hedons per minute for at most 10 minutes. (Note that the user only gets 3 hedons per
minute for the first activity they undertake, and do not get the hedons due to the star if they decide
to keep performing the activity:
offer_star(“running”)
perform_activity(“running”, 5) #gets extra hedons
perform_activity(“running”, 2) #no extra hedons
• If three stars are offered within the span of 2 hours, the user loses interest, and will not get additional
hedons due to stars for the rest of the simulation.
Engineering Science, University of Toronto Page 6 of 8
CSC 180 H1F Project # 1 — Gamification of Exercise Fall 2016
Here is a sample output of a simulation, along with comments explaining the output.
if __name__ == ’__main__’:
initialize()
perform_activity(“running”, 30)
print(get_cur_hedons()) #-20 = 10 * 2 + 20 * (-2)
print(get_cur_health()) #90 = 30 * 3
print(most_fun_activity_minute()) #resting
perform_activity(“resting”, 30)
offer_star(“running”)
print(most_fun_activity_minute()) #running
perform_activity(“textbooks”, 30)
print(get_cur_health()) #150 = 90 + 30*2
print(get_cur_hedons()) #-80 = -20 + 30 * (-2)
offer_star(“running”)
perform_activity(“running”, 20)
print(get_cur_health()) #210 = 150 + 20 * 3
print(get_cur_hedons()) #-80 = -80 + 10 * (3-1) – 10 * (-2)
perform_activity(“running”, 170)
print(get_cur_health()) #700 = 210 + 160 * 3 + 10 * 1
print(get_cur_hedons()) #-120 = -80 + 170 * (-2)
We provide you with a “starter” version of gamify.py—a skeleton of the code you will have to write,
with some parts already filled in. Please read it carefully and make sure you understand everything in the
starter code before you start making changes! You must not change the function signatures.
When designing and testing your functions, you may assume that every date given is a valid date in
2016 (there is no need to check that). However, you may not assume that dates used later in the simulation
always occur chronologically after dates that were used earlier.
Part 1.
Implement the following functions in gamify.py. Note that the names of the functions are case-sensitive
and must not be changed. You are not allowed to change the number of input parameters. Doing so
will cause your code to fail when run with our testing programs, so that you will not get any marks for
functionality.
Note that “iff” means “if and only if.” When we say that a function f returns True iff condition c holds,
we mean that f returns True if c holds, and False if it doesn’t hold.
Subpart (a) get_cur_hedons
This function returns the number of hedons that the user has accumulated so far.
Subpart (b) get_cur_health
This function returns the number of health points that the user has accumulated so far.
Engineering Science, University of Toronto Page 7 of 8
CSC 180 H1F Project # 1 — Gamification of Exercise
Subpart (c) off_star(activity)
This function simulates a offering the user a star for engaging in the exercise activity. Assume activity
is a string, one of “running”, “textbooks”, or “resting”.
Subpart (d) perform_activity(activity, duration)
The function simulates the user’s performing activity activity for duration minutes. Assume duration
is a positive int. If activity is not one of “running”, “textbooks”, or “resting”, running the function
should have no effect.
Subpart (e) star_can_be_taken(activity)
The function returns True iff a star can be used to get more hedons for activity activity. A star can only
be taken if no time passed between the star’s being offered and the activity, and the user is not bored with
stars, and the star was offered for activity activity.
Part 2.
In the if __name__ == “__main__” block, add code that tests your functions. While you may run
large simulations as well, your job is to come up with a testing strategy that ensures that your code works
according to the project specifications. This is best done by testing every individual aspect of the behaviour