Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose you have a Pikachu that is standing in the middle of an image, at coordinates (75, 75). Assume the top left corner of the

Suppose you have a Pikachu that is standing in the middle of an image, at coordinates (75, 75). Assume the top left corner of the board is (0,0) like in an image. You are going to read input from the user ten times. Though you do not have to use a loop for this part, it will considerably shorten your code to use one and it is highly recommended. However, using a loop in place of simple list functions such as sorting will incur penalties during grading. Each user input will be an action taken by Pikachu. You are going to execute each command as it is entered, and then print Pikachus current location and direction. At the same time, you are going to put all the given commands in a list, sort this resulting list at the end of the program and print it as is (no other formatting). Everything Pikachu does affects Pikachus energy. Moving (or attempting to move when at a boundary) costs 1 energy. Attacking costs 5 energy. Pikachu starts with 10 energy and energy cannot go below 0. Here are the allowed commands: One of E, N, W, S will move Pikachu 20 steps in the specified direction. Pikachu can only move if it has enough energy. 8 attack will print a message, but keep Pikachu at its current location. Pikachu will only attack if it has some energy, If Pikachu has at least 5 energy the attack succeeds. Otherwise it fails. Either way Pikachu loses up to 5 energy with the caveat that its energy cannot go below 0. rest will turn recharge Pikachu back to its initial energy level of 10. If user enters an incorrect command, you should treat it as a move with respect to checking energy level and decreasing energy, but nothing else happens. You should accept commands in a case insensitive way (N, e, W, RESt, Rest, rest) should all work. There is a fence along the boundary of the image. No coordinate can be less than 0 or greater than 150. 0 and 150 are allowed. You must implement at least one function for this program: move(x,y,direction,amount) will return the next location of the Pikachu as an (x,y) tuple. You can use the following code to test your move function. Feel free to write other functions if you want, but be sure to test them to make sure they work as expected!

x = 10 y = 15

p r i n t (move ( x , y , 'N') ) # Should p r i n t ( 1 0 , 0 )

p r i n t (move ( x , y , 'E') ) # Should p r i n t ( 3 0 , 1 5 )

p r i n t (move ( x , y , 'S ') ) # Should p r i n t ( 1 0 , 3 5 )

p r i n t (move ( x , y , 'W') ) # Should p r i n t ( 0 , 1 5 )

p r i n t ( ) x = 140 y = 135 p r i n t (move ( x , y , 'N' , ) ) # Should p r i n t ( 1 4 0 , 1 1 5 ) p r i n t (move ( x , y , 'E' , ) ) # Should p r i n t ( 1 5 0 , 1 3 5 ) p r i n t (move ( x , y , 'S ' , ) ) # Should p r i n t ( 1 4 0 , 1 5 0 ) p r i n t (move ( x , y , 'W' , ) ) # Should p r i n t ( 1 2 0 , 1 3 5 ) Now, write some code that will call these functions for each command entered and update the location of Pikachu accordingly. Here is an example run of the program: Pikachu at (75, 75) with power 10 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? N N Pikachu at (75, 55) with power 9 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? AtTack AtTack Bzzzt, Pikachu zaps its foe! Pikachu at (75, 55) with power 4 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? Attack 9 Attack Pffft, It's a dud ... Pikachu at (75, 55) with power 0 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? sleep sleep Pikachu is too tired! Pikachu at (75, 55) with power 0 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? N N Pikachu is too tired! Pikachu at (75, 55) with power 0 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? Rest Rest Pikachu at (75, 55) with power 10 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? N N Pikachu at (75, 35) with power 9 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? SLEEP SLEEP Pikachu at (75, 35) with power 8 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? N N Pikachu at (75, 15) with power 7 What does Pikachu do ('N', 'S', 'E', 'W', 'Attack', 'Rest')? N N Pikachu at (75, 0) with power 6 All commands entered: ['N', 'AtTack', 'Attack', 'sleep', 'N', 'Rest', 'N', 'SLEEP', 'N', 'N'] All commands sorted: ['AtTack', 'Attack', 'N', 'N', 'N', 'N', 'N', 'Rest', 'SLEEP', 'sleep'] In the above example, Sleep is an invalid command, so it has no effect on Pikachus state other than to cause Pikachu to lose power. In case you are wondering, the list is sorted by string ordering, which is called lexicographic (or dictionary) ordering. Here is a second example: Pikachu a t ( 7 5 , 7 5 ) with power 10 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? N N Pikachu a t ( 7 5 , 5 5 ) with power 9 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? N N Pikachu a t ( 7 5 , 3 5 ) with power 8 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? N 10 N Pikachu a t ( 7 5 , 1 5 ) with power 7 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? N N Pikachu a t ( 7 5 , 0 ) with power 6 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? N N Pikachu a t ( 7 5 , 0 ) with power 5 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? W W Pikachu a t ( 5 5 , 0 ) with power 4 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? Sl e e p Sl e e p Pikachu a t ( 5 5 , 0 ) with power 3 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? ATTaCk ATTaCk P f f f t , I t ' s a dud . . . Pikachu a t ( 5 5 , 0 ) with power 0 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? Sl e e p Sl e e p Pikachu i s t o o t i r e d ! Pikachu a t ( 5 5 , 0 ) with power 0 What d oe s Pikachu do ( 'N' , 'S ' , 'E' , 'W' , ' Attack ' , ' Rest ') ? RESt RESt Pikachu a t ( 5 5 , 0 ) with power 10 All commands e n t e r e d : [ 'N' , 'N' , 'N' , 'N' , 'N' , 'W' , ' Sleep ' , 'ATTaCk' , ' Sleep ' , 'RESt ' ] All commands s o r t e d : [ 'ATTaCk' , 'N' , 'N' , 'N' , 'N' , 'N' , 'RESt' , ' Sleep ' , ' Sleep ' , 'W' ]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

1. How does Kiwi Experience maintain a continual customer focus?

Answered: 1 week ago