Question

C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

C or 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 player’s 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

It is a rather simple code. The only thing you need to know is how to generate a random number. A pseudo-random number generator (PRNG) is a program that takes a starting number (called a seed) and performs mathematical operations on it to transform it into some other number that appears to be unrelated to the seed. It then takes that generated number and performs the same mathematical operation on it to transform it into a new number that appears unrelated to the number it was generated from. By continually applying the algorithm to the last generated number, it can generate a series of new numbers that will appear to be random if the algorithm is complex enough.

Please find the code below:

#include <iostream>
using namespace std;
int looser(int ar[],int n) // function to find the player who loses in this round
{
    int m=-1,index;
    int i=0;
    for(i=0;i<n;i++)
    {
        if(ar[i]==-1) // continuing if player is already eleminated
        {
            continue;
        }
        else if (m==-1)
        {
            m=ar[i];
            index=i;
        }
        else if(ar[i]<m) // saving the index of players with minimum score
        {
            m=ar[i];
            index=i;
        }
    }
    return index;    //getting index of loosing player
}
unsigned int dice() // function to generate random dice numbers
{
    static unsigned int seed{ 5323 };

    // Take the current seed and generate a new value from it
    // Due to our use of large constants and overflow, it would be
    // hard for someone to casually predict what the next number is
    // going to be from the previous one.
    seed = 8253729 * seed + 2396403;

    return (seed % 6) +1;//return value between 1 to 6
}
int main()
{
    int n; //number of players
    cout<<"Enter the number of players";
    cin>>n;
    cout<<"\nGame begin\n";
    int ar[n],l;
    for(int i=0;i<n;i++) //initially assuming all players are at 0 score
    {
        ar[i]=0;
    }
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(ar[j]==-1)       //checking if player is eleminated
            {
                continue;
            }
            ar[j]=dice()+dice(); // getting score of players
        }
        l=looser(ar,n);
        ar[l]=-1;
        cout<<"Looser this round "<<l+1<<" player\n";
    }
    for(int i=0;i<n;i++)
    {
        if(ar[i]>0)
        {
            cout<<"Winner is "<<i+1<<" Player";
            break;
        }
    }
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 2 – The two player game of Poaka The game of Poaka is a dice...

    Assignment 2 – The two player game of Poaka The game of Poaka is a dice game played by two players. Each player takes turns at rolling the dice. At each turn, the player repeatedly rolls a dice until either the player rolls a 1 (in which case the player scores 0 for their turn) or the player chooses to end their turn (in which case the player scores the total of all their dice rolls). At any time during...

  • python code( using functions please)! Rules of the game: - This game requires a dice. The...

    python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows:  1—penny  2—nickel  3—dime  4—quarter  5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...

  • Create a Dice Game: PYTHON This game is between two people. They will roll a pair...

    Create a Dice Game: PYTHON This game is between two people. They will roll a pair of dice each 10 times. Each roll will be added to a total, and after 10 rolls the player with the highest total will be the Winner! You will use the RANDOM class RANDRANGE to create a random number from 1 to 6. You'll need a function for "rollDice" to roll a pair of dice and return a total of the dice. You must...

  • For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two p...

    For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn,...

  • I need some help creating C++ Left, Center, Right (LCR) dice game Pseudocode. Address the following : A. Analyze the giv...

    I need some help creating C++ Left, Center, Right (LCR) dice game Pseudocode. Address the following : A. Analyze the given problem statement. B. Break the problem down into distinct steps of pseudocode that will solve the problem. C. Create variables to track the various elements in the pseudocode. D. If applicable, determine any breakdown of pseudocode into functions and/or classes. E. Use natural language to work through the problems. Using three special dice and player pieces called chips. In...

  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...

  • Complete a program In C#: some code is included, you edit the areas that have not...

    Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • C++ program This program involves writing a VERY simplified version of the card game War. You...

    C++ program This program involves writing a VERY simplified version of the card game War. You may know this game or not but my rules are these 1. Split the deck between player1 and player2. Only the face values matter (2-14) and not the suits 2. Each player puts a card down on the table. The higher face value wins that hand. If the card values match, you will simply indicate tie and neither player wins.The original rules would require...

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT