Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Language needed: C Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by

Programming Language needed: C

Project

Overview

Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round, all players take their turn and roll the 2 dice. Each players score in that round is simply the sum of both dice. The player(s) with the lowest roll in that turn loses one life and must change his personal life count (from 6 to 5). The game is continued and each round at least one player loses a life. When a player has lost all his or her lives, that player no longer participates in the game. The game ends when there is only one player left and all other players have lost all their lives. As the game is simple and easy to follow, it is often used as a drinking game or a gambling game. There are also several variations of this popular dice game that follow different scoring mechanics to eliminate a life each round. Write a MATLAB program to simulate the Wild, Wild, West! dice game that can: Automatically play the Wild, Wild, West! dice game for any number of players (input by the game host).

Automatically roll 2 dice for every player participates in the game and clearly print the dice values in the command window.

Automatically sum both dice values together for each player and print the score (the sum of both dice) for everyone participates in the command window.

Automatically find the lowest score of the round and print the lowest score in the command window.

Automatically identify the player(s) with the lowest score and print the player number(s) with the lowest score in the command window.

Automatically reduce one life for the player(s) with the lowest score.

Automatically print the number of lives for every player in the command window at the end of each round.

When a player has lost all lives, the player can no longer participate the game. The program should automatically stop showing the dice rolled by the players with no life. The program should also automatically skip the players with no life when determine which player gets the lowest score of the round.

The game should keep automatically playing until only 1 or 0 player left.

At the end of the game, identify the winning player number and congratulate the winner in the command window.

It is also possible that everyone died at the end of the game. In this case, clearly print a message in the command window. Extra components and functions are always welcome.

Suggested Steps:

1. Add your name, purpose, and copyright the program.

2. Clear command window and clear all variables.

3. Randomize the pseudorandom number generator with the MATLAB built-in rng function and provide shuffle as the function input.

4. Add an input function to ask the game host to enter the number of players. Save the keyboard input value in a new variable.

5. (The number of human players should be an integer and should not be a negative value. We will add 2 if..end statements immediately after the input function to check the user input.) If the number of players is not equal to the floor value of the number of players (i.e. the floor value of 2.8 is 2, 2.8 will not equal to 2), modify the number of players to the floor value of the number of players. End.

6. If the number of players is less than 0, modify the number of players to 0. End.

7. (Now we can create a player number array to track the number of lives.) Create an array of player numbers that starts from 1, with step size 1, and ends at the number of players.

8. Create an array variable to track the number of lives. Call the ones function to create 1 row by number of players column of 1s. Multiple every element of this array by 6. (We need as many 6s in this array as the number of players.)

9. Create a matrix variable to track the dice values. Call the randi function to obtain 2 rows by number of players column of random numbers between 1 and 6.

10. Create an array variable to track the game scores. Call the sum function to sum the random dice values matrix into an array of game scores.

11. For loop counter variable from 1 to number of players: a. If the number of lives array (the counter variable element) contains a value greater than 0: i. Add an fprintf function to print the player number (the counter variable value), the 1 st dice value (from the dice values matrix row 1, counter variable column), the 2 nd dice value (from the dice values matrix row 2, counter variable column), and the game score (from the game scores array the counter variable element). b. Else: i. Set the game scores array the counter variable element value to 20. ii. Add an fprintf function to print the player number (the counter variable value) can no longer participate the game. c. End.

12. End.

13. Call the min function to obtain the minimum value of the game scores array. Save the lowest score in a new variable.

14. Add an fprintf function to print the lowest score in the command window.

15. Call the find function to find from the game scores array element(s) that is/are equal to the lowest score. Save the index value(s) to a new kill a life variable.

16. Add an fprintf function to print the player number(s) that will lose a life, print the value(s) from the kill a life variable.

17. Decrement the number of lives array the value(s) in the kill a life index by 1.

18. Add an fprintf function to print the number of lives table, by using the hard brackets to combine the array of player numbers and the number of lives array into a matrix (reference homework 1 part 2).

19. (Now we are ready to add the while loop to keep looping while more than 1 player is alive) a. Locate the randi function (generated from Step 9), highlight the code block with codes generated from step 9 through step 18 and click the increase indent button. b. Insert the keyword while right above the randi function from Step 9. Add an end right after the fprintf function for step 18. c. Add the while loop logical expression to loop while the length of the (find from the number of lives array that contain values not equal to 0) is greater than 1.

20. (The while loop ended means there is only 1 or 0 player standing. Now we are ready to congratulate the winner.) Call the find function to find the index value of the number of lives array value that is not equal to 0. Save the winner in a new variable.

21. If the length of the winner variable is not equal to 0: a. Add an fprintf function to congratulate the winner player.

22. Else: a. Add an fprintf or disp function to print everyone is gone.

23. End.

24. Play the game a few times to ensure the game runs correctly. After ensuring they are correct, add semicolon (;) to the end of every line with the assignment operation (=) to stop the auto repeating values in the command window.

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

More Books

Students also viewed these Databases questions

Question

please i need complete solution for this question in java :

Answered: 1 week ago