Question

To decide your fate, you will play a board game on a simple board: a linear...

To decide your fate, you will play a board game on a simple board: a linear track with 16 sequential spaces numbered from 1 to 15. The “zero” space is marked “Start,” and your token is placed on it. The jailer has one silver coin and places it on a random numbered space. The jailer then gives you a gold coin, and you are allowed to place it on any numbered space that you want except that the coins must be placed on different spaces. Once placed, the coins are never moved. After both coins are placed, you roll a fair, six-sided die and move your token forward the corresponding number of spaces. If, after moving the token, it lands on the space with your gold coin, you have instantly won your freedom. On the other hand, if, after moving the token, it lands on the space with the jailer’s silver coin, you have instantly lost and become dragon food. If you land on a space with no coin, you roll again and continue moving forward. Anytime your token gets past space 15, you place your piece on to the Start position and that move ends with your token on Start; with your next roll of the die, you again proceed across the board. For example, let’s say the token is on space 13. If you were to roll a 1, then you would place the token on space 14; if instead you rolled a 2, then you would place the token on space 15; and if you had rolled a 3, 4, 5, or 6, then you place the token back on Start and that move ends. Your token moves across the board as many times as needed until it lands on a space with a coin. The coins are not moved. In this assignment, you will develop code that allows a user to play this game against the computer; the computer is the jailer and the player is the prisoner. When run, the program should 1) welcome the player to the game; 2) announce which space the jailer has randomly chosen for the silver coin; 3) ask the player on which space they would like to place their gold coin; 4) check that the player has placed their coin on a valid space and, if not, keep asking the player until they provide a valid space; 5) run the game as described above, moving the token random numbers of spaces as with the roll of a six-sided die, each time printing to the screen the result of the die roll and the new location of the token; 6) checking at the end of each move to see if the token has landed on the silver coin, the gold coin, or off the end of the board; 7) reset the token to the Start position anytime it has landed past space 15; and 8) end the game when it lands on a coin, displaying a game-over message appropriate to whether the player has won or lost.

The answer should be in C++ programming language.

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

//The program with output

#include <iostream>

#include <random>

using namespace std;

// function declarations

int getRandomSpace(void);

int getPlayerSpace(int js);

int getTokenSpace(int ts);

int main() {

  // welcome message

  cout << "Welcome to the Game!\n";

  // randomly finds jailers space and display it

  int jailer_space = getRandomSpace();

  cout << "The jailer has placed his silver coin at space #" << jailer_space

       << "\n";

  // ask player for their space and display it

  int player_space = getPlayerSpace(jailer_space);

  cout << "The player has placed his silver coin at space #" << player_space

       << "\n";

  int token_space = 0;

  // run loop until the game is lost or won

  while (true) {

    token_space = getTokenSpace(token_space);

    if (token_space == player_space) {

      cout << "Hurray, you won!\n";

      cout << "You are now free.\n";

      break;

    } else if (token_space == jailer_space) {

      cout << "You lost!\n";

      cout << "You will be feeded to dragon.\n";

      break;

    }

  }

}

int getRandomSpace(void) {

  // function to get random space for jailer

  random_device rd;

  mt19937 mt(rd());

  uniform_int_distribution<int> space(1, 15);

  return space(mt);

}

int getPlayerSpace(int js) {

  // function to get player space

  int ps;

  cout << "On which space would you like to place your gold coin? ";

  cin >> ps;

  while (ps > 15 || ps < 1 || ps == js) {

    cout << "Invalid space, please enter again. ";

    cin >> ps;

  }

  return ps;

}

int getTokenSpace(int ts) {

  // function to get token space by random die roll

  random_device rd;

  mt19937 mt(rd());

  uniform_int_distribution<int> die(1, 6);

  int die_roll = die(mt);

  ts += die_roll;

  if (ts > 15) {

    ts = 0;

  }

  cout << "Die roll: " << die_roll << "\tToken location: " << ts << "\n";

  return ts;

}

Output :

The program runs as expected. You can change the output message if you want.

If there is any doubt please ask in the comments, i will be happy to help you out.

Add a comment
Know the answer?
Add Answer to:
To decide your fate, you will play a board game on a simple board: a linear...
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
  • INTRODUCTION: Play sorry with two die, and one peg. Move your piece down the board first....

    INTRODUCTION: Play sorry with two die, and one peg. Move your piece down the board first. But rolling certain numbers will change the pace of the game. INCLUDE IN YOUR ASSIGNMENT: Annotation is a major part of any program. At the top of each of your C++ programs, you should have at least four lines of documentation: // Program name: tictactoe.cpp // Author: Twilight Sparkle // Date last updated: 5/26/2016 // Purpose: Play the game of Tic-Tac-Toe ASSIGNMENT: Sorry Game...

  • JAVA Program The Game This is a simple game played on a linear board with squares...

    JAVA Program The Game This is a simple game played on a linear board with squares numbered from 0 to 100. The player starts at position 0, and the object of the game is to land on position 100 exactly. Objectives By the end of this program, the student will have demonstrated the ability to Write static methods Call a static method in another class Pass parameters to a method Return values from a method Write loops Write if statements...

  • "Chutes and Ladders" is a popular board game for children. The game consists of a board...

    "Chutes and Ladders" is a popular board game for children. The game consists of a board that has squares which are numbered from 1 to 100, and players have counters which start on the theoretical square 0. On each player’s turn, the player generates a random integer number from 1 to 6 (e.g. by rolling a die or spinning a wheel) and move their marker through the board that many spaces. If you land at the bottom of a ladder...

  • Suppose you have a six sided die. One face is printed with the number 1.  Two faces...

    Suppose you have a six sided die. One face is printed with the number 1.  Two faces are printed with the number 2. Three faces are printed with the number 3. You also have 3 coins:  C_1, C_2, and C_3. C_1 will land Heads with probability 1/5. C_2 will land Heads with probability 1/3. C_3 will land Heads with probability 1/2. You roll the die. If the die lands with a 1 face up, flip coin C_1 If the die lands with...

  • Suppose you have a six sided die. One face is printed with the number 1. Two...

    Suppose you have a six sided die. One face is printed with the number 1. Two faces are printed with the number 2. Three faces are printed with the number 3. You also have 3 coins: C_1, C_2, and C_3. C_1 will land Heads with probability 1/3. C_2 will land Heads with probability 1/5. C_3 will land Heads with probability 1/4. You roll the die. If the die lands with a 1 face up, flip coin C_1 If the die...

  • Suppose you have a six sided die. One face is printed with the number 1. Two...

    Suppose you have a six sided die. One face is printed with the number 1. Two faces are printed with the number 2. Three faces are printed with the number 3. You also have 3 coins: C_1, C_2, and C_3. C_1 will land Heads with probability 1/5. C_2 will land Heads with probability 1/3. C_3 will land Heads with probability 1/2. You roll the die. If the die lands with a 1 face up, flip coin C_1 If the die...

  • Suppose you have a six sided die. One face is printed with the number 1. Two...

    Suppose you have a six sided die. One face is printed with the number 1. Two faces are printed with the number 2. Three faces are printed with the number 3. You also have 3 coins: C_1, C_2, and C_3. C_1 will land Heads with probability 1/5. C_2 will land Heads with probability 1/3. C_3 will land Heads with probability 1/2. You roll the die. If the die lands with a 1 face up, flip coin C_1 If the die...

  • Please answer all parts to this 4 part question Suppose you have a six sided die....

    Please answer all parts to this 4 part question Suppose you have a six sided die. One face is printed with the number 1. Two faces are printed with the number 2. Three faces are printed with the number 3. You also have 3 coins: C_1, C_2, and C_3. C_1 will land Heads with probability 1/5. C_2 will land Heads with probability 1/3. C_3 will land Heads with probability 1/2. You roll the die. If the die lands with a...

  • A fair die is rolled in a board game to determine how many spaces a player...

    A fair die is rolled in a board game to determine how many spaces a player can move on their turn. It has one of the numbers 1,2,3,4,5, or 6 on each of its faces.Let event A be rolling an even number and event B be rolling an odd number.Identify the numbers of each of the following:Provide your answer below:There are _______  outcomes in the sample space.There are _______  outcomes in event A.P(A)=_______  is the probability that you choose an...

  • 2. One the last exam, you analyzed a mini-version of the board game Chutes and Ladders. For your ...

    2. One the last exam, you analyzed a mini-version of the board game Chutes and Ladders. For your reference, this information is repeated on the next page. (a) Give the one-step transition matrix P for the Markov chain {Xn,n 2 0]. (This is the same question that was on the exam) (b) What is the expected length (number of spins) of a game? (c) In which square should the player expect to spend the most time? (d) In which square...

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