Question

Can someone please help me with this C++ problem?

Let's Play Chutes and Ladders!

The board is shown below.

Use a map structure to store all the chutes and ladders movements

  • Key is the starting square
  • Value is the final movement square
  • EXAMPLE: std::make_pair(95, 75) handles one chute I see (Fall from 95 to 75)
  • Both types can be stored in the same structure since they don't share spaces
  • It looks like there are 9 ladders and 10 chutes total?

Our version of the game is played as follows:

  • Start on square 0
  • Roll two normal six -sided dice and move that many squares
  • If you land on a ladder, move up accordingly
  • If you land on a chute, move down accordingly
  • If you end your turn on square 100 or above you are done
  • Print out each move
  • Print out the number of total moves made (Chutes/Ladders movements don't count)

Example Output

0 8 13 16=>6 17 28=>84 92 95=>75 86 97 102    MOVES = 10

96 INNA 100 95 831 86 87 3 88 85 89 90 8079 62 63 66 60 59 58 57 5453 51 55 56 42 43 45 46 49 50 44 40 37 33 35 34 26 27 23 2

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

#include <bits/stdc++.h>
using namespace std;

int main()
{
// map to store pair of ladders and chutes values
map<int,int> chutesLadders;
  
// making pair of ladders
chutesLadders.insert(pair<int,int>(1,38));
chutesLadders.insert(pair<int,int>(4,14));
chutesLadders.insert(pair<int,int>(9,31));
chutesLadders.insert(pair<int,int>(28,84));
chutesLadders.insert(pair<int,int>(21,42));
chutesLadders.insert(pair<int,int>(36,44));
chutesLadders.insert(pair<int,int>(51,67));
chutesLadders.insert(pair<int,int>(71,91));
chutesLadders.insert(pair<int,int>(80,100));
  
// making pair of chutes
chutesLadders.insert(pair<int,int>(16,6));
chutesLadders.insert(pair<int,int>(62,19));
chutesLadders.insert(pair<int,int>(87,24));
chutesLadders.insert(pair<int,int>(47,26));
chutesLadders.insert(pair<int,int>(49,11));
chutesLadders.insert(pair<int,int>(56,53));
chutesLadders.insert(pair<int,int>(64,60));
chutesLadders.insert(pair<int,int>(93,73));
chutesLadders.insert(pair<int,int>(95,75));
chutesLadders.insert(pair<int,int>(98,78));

// key is initial position and value is final position
int key=0, value=100;
  
// position will keep track the position of a person
// count will count the nuumber of times the dice thrown
// or moves needed to reach 100
int position=key, flag=1, count=0;
  
// dice1 and dice2 will have random numbers
int dice1, dice2;
  
// loop unitl we react at 100 or further
while(position<100) {
  
// dice first random value
dice1 = rand() % 6 + 1;
  
// dice second random value
dice2 = rand() % 6 + 1;
  
// current position of the person
position+=dice1+dice2;
  
// check if a person step on the chute or Ladder
if(chutesLadders.find(position) != chutesLadders.end()) {
cout<<position<<"=>";
position = chutesLadders[position];
cout<<position<<" ";
flag=0;
}
  
// will print currect position
if(flag) {
cout<<position<<" ";
}
  
flag=1;
  
// increase it's value on every count
count++;
}

cout<<" MOVES "<<count;
return 0;
}

#include <bits/stdc++.h> using namespace std; int main() // map to store pair of ladders and chutes values map<int, int> chut

1/ loop unitl we react at 100 or further while(position<100) { // dice first random value dice1 = rand() % 6 + 1; // dice sec

// Hope it will be helpful, don't forget to upvote the answer, really appreciated.

Add a comment
Know the answer?
Add Answer to:
Can someone please help me with this C++ problem? Let's Play Chutes and Ladders! The board...
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
  • "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...

  • 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...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • Please use C++ as a Programming language and do the tasks specified per the Guideline above...

    Please use C++ as a Programming language and do the tasks specified per the Guideline above and include comments of your work. Please make sure that the following test cases are working: Example 1 For input D13 D60 D76 D12 A17 D98 A94 D70 D3 A23 A42 D45 A100 D50 A99 A22 A87 A4 A90 D88 A71 A20 D39 D83 A97 A56 D28 A9 D43 A19 D5 A11 A54 A73 D54 A9 A24 A58 D6 D80 A72 A47 A82 A12...

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