Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python language: A pokemon trainer is placed in the middle of a grid that is size rows tall and size columns wide. This value is

Python language:

A pokemon trainer is placed in the middle of a grid that is size rows tall and size columns wide. This value is read into the program by asking the user. The user must also be asked for a probability p that must be greater than 0.0 and less than 1.0, but will generally be relatively small. The reason for the probability is explained below. You may assume all input is correct. The upper left corner of the grid is location (0, 0), while the bottom right corner is location (size1, size1). Again, the maximum limits of the grid are (size1, size1). This is important both to get Part 2 correct and because it will cause an error accessing the tracking grid in Part 3 if you do not set this correctly. The trainer starts out at location (size//2, size//2). The program must simulate random movements of the trainer. The trainer can only move in a straight line to one of the four compass points to the North (decreasing row), East (increasing column), South (increasing row), or West (decreasing column) one step per turn. After taking a step, the trainer will have a p probability of seeing a pokemon on that spot and if they see one they will throw a pokeball for a chance to catch it. In Part 1 you put together the random calls that you need to manage moving and throwing the pokeball. In this part modify your functions to return the values you roll instead of just printing them out. move_trainer should return a tuple of (direction, probability) and throw_pokeball should return either True or False. To proceed, set your trainer at the center point of the grid as described above, then move the trainer based on the results of a call to move_trainer. If the probability returned by move_trainer is less than the value p, the user sees a pokemon on the current spot and you need to call throw_pokeball to see if she catches it. Pokeballs are expensive. Only throw a pokeball if you see a pokemon. The first time you call throw_pokeball you should provide it with 3 False values and 1 True value. Thereafter, increase the number of Trues by one for every pokemon the trainer successfully catches. Nothing changes if the pokemon is not caught. The trainer should continue to make these random steps until she reaches the edge of the grid (row or column becomes 0 or size 1),image text in transcribedimage text in transcribed

Example 1: Enter the integer grid size => 10 10 Enter a probability (0.0 - 1.0) => 0.2 0.2 Saw a pokemon at turn 7, location (4, 5) Missed .. Saw a pokemon at turn 13, location (4, 5) Caught it! Saw a pokemon at turn 18, location (5, 3) Missed Saw a pokemon at turn 19, location (5, 4) Missed ... Saw a pokemon at turn 20, location (5, 5) Caught it! Saw a pokemon at turn 23, location (6, 5) Caught it! Saw a pokemon at turn 26, location (4, 4) Missed ... Saw a pokemon at turn 29, location (3, 4) Missed ... Saw a pokemon at turn 35, location (1, 6) Caught it! Trainer left the field at turn 37, location (0, 7). 9 pokemon were seen, 4 of which were captured

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

Step: 3

blur-text-image

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

4. How has e-commerce affected business-to-business transactions?

Answered: 1 week ago