Question: Simulation ( The Tortoise and the Hare ) , You will use a random generator and pointers to develop a simulation of this race. Our

Simulation (The Tortoise and the Hare), You will use a random generator and pointers to develop a simulation of this race.
Our players begin the race at "square 1" of 50 squares. A square is a position along the race course. The finish line is at square 70. The course weaves up the side of a mountain, so the players might lose ground.
Every loop iteration (tick per second), should use the functions moveTortoise and moveHare to change the position of the players according to the following rules, the functions should use POINTER-base PASS-By-Reference to modify the position of both players.
Player Move Type Percentage of time Actual move
Tortoise Fast Plod 50%3 squares to the right
Slip 20%6 squares to the left
Slow Plod 30%1 square to the right
Hare Sleep 20% No move at all
Big Hop 20%9 squares to the right
Big slip 10%12 squares to the left
Small Hop 30%1 square to the right
Small slip 20%2 squares to the left
1. Write the program to simulate the above by using variables to keep track of the players' positions 1-50. Start each player at position 1. Produce a random integer for the percentage called i in the range
fast plod 1<= i <=5, slip 6<= i <=7, slow plod 8<= i <=10.
sleep 1<= i <<2, Big Hop 3<= i <=4, Big slip 5<= i <=6, Small Hop 7<= i <=8, Small slip 9<= i <=10.
For each iteration, show a line of 50 positions showing T for the position of the Tortoise and H for the Hare. If they have the same position, use the letter O for OUCH. Use a star for the rest of the positions. (10 points)
Display who is the winner. If the game is a tie, then display "It is a tie". If there is no winner, then display "No Winner". Stop the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!