Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions