In this project, you will write a C program that reinforces programming fundamentals such as control flow, functions, expressions and random number generation with rand() and srand().
The rand() function is a random number generator in C that returns a value in a specified range from [0, max] where the value returned is based off a seed value that is input into srand() where the seed value determines the pseudo-random numbers generated.
After years of attempting to understand the laws of physics, scientists have finally been able to create a time travel machine. A number of archeologists learned of such a feat, and have inquired about it so that they can study the past more thoroughly and effectively. Despite not having tested the time travel machine, the scientists agree to let the group of archeologists use it to go back in time to an ancient civilization named Tarhniv. While on their expedition to Tarhniv, the archeologists find a tablet inscription which details a game that the Tarhniv people of that time are playing. Soon enough, the local Tarhniv people find out that a mysterious band of people have invaded their lands and thus the archeologists need to escape by traveling back in time to their present time. With the Tarhniv gaming table inscription now in hand, the archeologists begin to decrypt the game that was played in the past and have tasked you with implementing a version for them to play it with.
The game of Gehntoo is played with two players. The game is similar to volleyball except that both players do not attempt to throw the ball back over the net. Rather, in Gehntoo, players take turns throwing the ball once per turn over the net, and based on whether their throw went over or under the net, they win or lose points. The player who first reaches a score <=0 points (starting from 75 points), wins the game and can choose to play again if desired.
Gehntoo is a two-player game where player one will be the human player (you) and the second player will be the computer (a nave AI).
When running the program, a welcome message is first displayed and player one is asked to enter his name. The name entered must not be longer than 7 characters and must contain only letters or blank spaces. If at least one of these conditions is not met, your program must display an error message and re-prompt to enter the name until it is a valid input.
Next, ask the player for a seed value. Verify that the seed value entered is no longer than 5 characters. You must validate that this seed value only contains numbers. Do not just call sscanf, call the is_valid_seed()function and check the return value to determine whether it is a valid seed. Skipping this step will result in a penalty on your score.
Ask the player to enter the height of the game net in feet and inches.
Each player has three chances to play the game in a run. When the game ends, the player is asked if want to play again, if he agrees, then he has one less chance to play again. Once a player has no more chances to play, then the run ends. See section c.i (Playing again or exiting the game) for more information regarding playing the game again.
Both players start with 75 points and take turns throwing the ball trying to get it over the net.
Before attempting to throw the ball, the player must make a bet. The bet must not exceed his current total points and must range in [1, 11], inclusive. If this condition is not met, the player is prompted to re-enter a valid bet.
Once the player one has thrown, the computer will throw the ball.
The player who first reaches a score <=0 points win the game. When it occurs:
Choose the appropriate parameters for each of the following functions.
int is_valid_seed()
This function checks the input value for the seed and validates that only digits were entered, and that the value ranges in [1, 99999], inclusive. If at least one of these conditions is not met, then the function returns 0 otherwise 1.
int game_logic()
This function implements the game logic as indicated by the rules above.
int throw_ball()
This function throws the ball to a random height using the rand() function. The height generated at random must range in [0, net_height+16].
int is_valid_name()
This function determines if a valid name is entered by the user. A name must not be longer than 7 characters and must contain only letters or blank spaces. If name is valid, return 1 otherwise return 0.
int calculate_net_height()
This function determines the height of the net in inches of the net string that is input by the user. Return the calculated net height in inches.
You may create any additional functions that help you create your game logic.
Welcome to the Gehntoo game
Enter your name Jim
Enter a seed value to use in the range of [1-99999] 143d
Invalid seed, please enter a new seed value in the range [1-99999] 12563
Seed value to use is 12563
Enter the height of the net in feet and inches [xxft xxin] where xx must be [1-99] 3ft 3in
Height of the net: 39 inches
Each player is starting with 75 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 53 inches, the ball is over the net
Deducting 11 points
Jim now has 64 points
Computer's turn
Ball height: 14 inches, ball is below the net, throwing once more
Ball height: 25 inches, the ball is below the net
Adding 6 points
Computer now has 81 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 48 inches, the ball is over the net
Deducting 11 points
Jim now has 53 points
Computer's turn
Ball height: 13 inches, ball is below the net, throwing once more
Ball height: 10 inches, the ball is below the net
Adding 6 points
Computer now has 87 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 5 inches, Throw again? Type Y or N: Y
Ball height: 3 inches, the ball is below the net
Adding 4 points
Jim now has 57 points
Computer's turn
Ball height: 47 inches, the ball is over the net
Deducting 9 points
Computer now has 78 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 18 inches, Throw again? Type Y or N: Y
Ball height: 42 inches, the ball is over the net
Deducting 11 points
Jim now has 46 points
Computer's turn
Ball height: 21 inches, the ball is below the net
Adding 4 points
Computer now has 82 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 12 inches, Throw again? Type Y or N: Y
Ball height: 20 inches, the ball is below the net
Adding 4 points
Jim now has 50 points
Computer's turn
Ball height: 5 inches, ball is below the net, throwing once more
Ball height: 40 inches, the ball is over the net
Deducting 7 points
Computer now has 75 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 19 inches, Throw again? Type Y or N: Y
Ball height: 18 inches, the ball is below the net
Adding 4 points
Jim now has 54 points
Computer's turn
Ball height: 15 inches, ball is below the net, throwing once more
Ball height: 29 inches, the ball is below the net
Adding 6 points
Computer now has 81 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 50 inches, the ball is over the net
Deducting 11 points
Jim now has 43 points
Computer's turn
Ball height: 17 inches, ball is below the net, throwing once more
Ball height: 19 inches, the ball is below the net
Adding 6 points
Computer now has 87 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 51 inches, the ball is over the net
Deducting 11 points
Jim now has 32 points
Computer's turn
Ball height: 7 inches, ball is below the net, throwing once more
Ball height: 14 inches, the ball is below the net
Adding 6 points
Computer now has 93 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 10 inches, Throw again? Type Y or N: Y
Ball height: 10 inches, the ball is below the net
Adding 4 points
Jim now has 36 points
Computer's turn
Ball height: 35 inches, the ball is below the net
Adding 4 points
Computer now has 97 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 7 inches, Throw again? Type Y or N: Y
Ball height: 9 inches, the ball is below the net
Adding 4 points
Jim now has 40 points
Computer's turn
Ball height: 32 inches, the ball is below the net
Adding 4 points
Computer now has 101 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 22 inches, the ball is below the net
Adding 2 points
Jim now has 42 points
Computer's turn
Ball height: 18 inches, ball is below the net, throwing once more
Ball height: 8 inches, the ball is below the net
Adding 6 points
Computer now has 107 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 35 inches, the ball is below the net
Adding 2 points
Jim now has 44 points
Computer's turn
Ball height: 13 inches, ball is below the net, throwing once more
Ball height: 53 inches, the ball is over the net
Deducting 7 points
Computer now has 100 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 22 inches, the ball is below the net
Adding 2 points
Jim now has 46 points
Computer's turn
Ball height: 44 inches, the ball is over the net
Deducting 9 points
Computer now has 91 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 55 inches, the ball is over the net
Deducting 11 points
Jim now has 35 points
Computer's turn
Ball height: 49 inches, the ball is over the net
Deducting 9 points
Computer now has 82 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 9 inches, Throw again? Type Y or N: Y
Ball height: 12 inches, the ball is below the net
Adding 4 points
Jim now has 39 points
Computer's turn
Ball height: 53 inches, the ball is over the net
Deducting 9 points
Computer now has 73 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 14 inches, Throw again? Type Y or N: Y
Ball height: 36 inches, the ball is below the net
Adding 4 points
Jim now has 43 points
Computer's turn
Ball height: 16 inches, ball is below the net, throwing once more
Ball height: 16 inches, the ball is below the net
Adding 6 points
Computer now has 79 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 51 inches, the ball is over the net
Deducting 11 points
Jim now has 32 points
Computer's turn
Ball height: 29 inches, the ball is below the net
Adding 4 points
Computer now has 83 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 10 inches, Throw again? Type Y or N: Y
Ball height: 13 inches, the ball is below the net
Adding 4 points
Jim now has 36 points
Computer's turn
Ball height: 49 inches, the ball is over the net
Deducting 9 points
Computer now has 74 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 46 inches, the ball is over the net
Deducting 11 points
Jim now has 25 points
Computer's turn
Ball height: 4 inches, ball is below the net, throwing once more
Ball height: 7 inches, the ball is below the net
Adding 6 points
Computer now has 80 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 40 inches, the ball is over the net
Deducting 11 points
Jim now has 14 points
Computer's turn
Ball height: 55 inches, the ball is over the net
Deducting 9 points
Computer now has 71 points
Jim's turn. How much would you like to bet towards your throw? 11
bet 11 points
Ball height: 42 inches, the ball is over the net
Deducting 11 points
Jim now has 3 points
Computer's turn
Ball height: 47 inches, the ball is over the net
Deducting 9 points
Computer now has 62 points
Jim's turn. How much would you like to bet towards your throw? 11
your bet was not within the valid range of [1, 11] or you attempted to bet more points than you
currently have. Please enter a valid bet: 3
bet 3 points
Ball height: 48 inches, the ball is over the net
Deducting 3 points
Jim now has 0 points
Jim has won the current game, congratulations!
Would you like to play again Jim? Type Y or N: N
Jim chose not to play again. Thanks for playing!
Printing out game statistics now:
Jim won a total of 1 time(s)
Computer won a total of 0 time(s)