CSCI 210 Homework 2

This assignment focuses on:● Programming in Python● Understanding States and Actions● Designing a State Machine to describe behavior in a game● Implementing a State Machine● Programming to an interfaceThis is an individual assignment. You must work on your own. You may contact the instructor if youhave difficulty with the assignment. Start early so you may ask for help in class, if you run into anyproblems.AssignmentTwo python files, and are available on the class website. file defines the behavior of a pet, while the runs a simple game loopasking for the user to either give food to the Tamagochi, or add or remove a toy. The loop runs once asecond, changing the state of the Tamagochi and having the Tamagochi act. Every five seconds, theuser is asked to add food, a toy, do nothing or quit.Download the two files, and test to make sure they work by running From IDLE,this can be done by opening the file and running it (F5 key). From the command line, you can typepython You should be asked to enter a letter every five seconds.You are to create a Tamagochi (virtual pet) by modifying the file. The Tamagochi willexhibit the following behavior:The Tamagochi is a simple virtual pet, which you can feed and let play with a toy. TheTamagochi has a certain level of nutrition between 0 and 100. Whenever there is foodavailable, the Tamagochi will want to eat, raising its nutrition. If nutrition falls below 25, theTamagochi will be hungry. If the Tamagochi is not hungry, and there is no food in the cage, itwill get bored. If a toy is in the cage and the Tamagochi is not hungry, the Tamagochi will play.If the Tamagochi is hungry, it will refuse to play, even if there is a toy in the cage. If theTamagochi gets hungry while playing, it will stop playing until fed. Essentially, the Tamagochibehaves according to (a minimal version of) Maslow's Hierarchy.Your Tamagochi exists in a Space which contains a certain amount of food and may have a toy at anygiven time. You cannot modify the Space, but there are three methods available which describe thestate:game.seeFood() - Returns True if there is food in the Space, False if there is no - Returns True if there is a toy in the Space, False if there is no - Your Tamagochi consumes a certain amount of food. This method returns theamount your Tamagochi consumes (as an integer), which you can add to theTamagochi's nutrition.You should call these methods during the updateTamagochiState and tamagochiAct methods, based onthe current state.In the updateTamagochiState method, add a command which reduces the nutrition by 3. However, thenutrition should never go below 0, so set nutrition to 0 if it is negative.NOTE: updateTamagochiState should only change the tamagochiState variable, not perform anyspecific action (eating, for instance). Actions (eating, playing, etc.) should only be performed in thetamagochiAct method.For this assignment, you must do the following:1. Identify the different states the Tamagochi can be in, and which actions the Tamagochi can take.2. Create a State Machine (as describe in class, and in Chapter 10 of the book), showing thetransition between States.3. Modify the file so that the Tamagochi's behavior matches the State Machine frompart 2.Submission1. Bring a copy of the states, actions and state machine you created for parts 1 and 2.2. Submit the python file ( to Homework 2 in the dropbox.AssessmentYour grade will be based on how well you followed the above instructions. Each of the three items inthe homework will have equal weight. The Tamagochi's State Machine and program should mimic thebehavior described. If you are unclear as to how the Tamagochi should behave, please ask forclarification (in class, preferably).Late assignments will be deducted 10% per day late.
Powered by