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 board rather than the top. Two variations in this game is that landing on another player is not permitted and that a player must have an exact roll to land on the final square to win. There can be 2-4 players.
The purpose of the assignment is to learn to use functions in a program, and how to use 1D arrays. You do NOT have to pass arrays to a function for this program.
Problem Statement
The program runs on a 40 square (8 columns and 5 rows) grid, with all players starting off the board, so a roll of one will put a player in the first square. The user will choose how many players will be playing. If there are fewer than 2 players or more than 4 players, the user is prompted again. The player pieces are labeled with character a, b, c, and d, in that order. Therefore, a game with 2 people would use pieces a and b.
Next, the program asks the user if the game should be run in debug, power, or regular mode (D, P, or anything else, case insensitive). If D is entered, set the random seed to 10 (srand(10)) and generate random player rolls. If P is entered, set the random seed to 10 and users get to state what their roll is, including going backwards! If anything else is entered, use the time seed and generate random player rolls.
During the game, the users are presented with two options: (R)oll and (Q)uit. Any other option other than Ror Q (case insensitive) should prompt the user again. R will roll the dice, and Q will stop the game. Please see the sample output for the formatting. A roll can be any value of 1 to 6. After a roll, the following may occur:
The square has a chute or ladder
Output what occurred and move the player to the end of the chute or ladder
This precedes checking if another players is already in the square
There is another player in the space,
Output which player you would have landed on and skip the current players turn. This should be done AFTER a chute or ladder.
The roll would place the player past the last square
Output that an exact roll is needed, and skip the current players turn (see the example output for formatting)
The square is blank
Move the player to the square
The square is blank and is the last square
More the player to the square and end the game since they won.
At the beginning of each turn, print the game board again. The following are the starting game board, and after placing one player that rolled a 6. So, the player starts at the top left.
| | | | # | 1 | a | 2 | |
| | | | 1 | $ | | | |
| | # | | 3 | | | | |
| | | % | 2 | | | $ | |
| | | | % | 3 | | | |
Landing on a chute or ladder
This program will permit some flexibility on what is output when this occurs. You may be creative on “what happened” to a player, but there must be at least 2 random results for both a chute or a ladder (4 total).
Chute or ladder locations
The game must have the following chutes and ladders (indexed starting at 0, from the top and left)
Ladder (takes player away the goal)
Square 11 (row 1, column 3) climbs to square 4 (row 0, column 4), and is displayed as 1 on the game board.
Square 27 (row 3, column 3) climbs to square 6 (row 0, column 6), and is displayed as 2 on the game board.
Square 36 (row 4, column 4) climbs to square 19 (row 2, column 3), and is displayed as 3 on the game board.
Chute (takes player towards the goal)
Square 3 (row 0, column 3) drops to square 17 (row 2, column 1), and is displayed as # on the game board.
Square 12 (row 1, column 4) drops to square 30 (row 3, column 6), and is displayed as $ on the game board.
Square 26 (row 3, column 2) drops to square 35 (row 4, column 3), and is displayed as % on the game board.
Since they do not change over the course of the game these are constants.
Functions
The following are the minimum number of functions you must create for the game. You may add more (and may need to due to coding style requirements of a maximum of 50 lines or 2 pages, with comments and whitespace included), but these functions MUST work as described. There are no return or parameter types stated here, you must decide on these yourself.
_____ print_menu(___)
print the (R)oll and (Q)uit menu, and return the option selected
_____ move(___)
try to move a current player position to a new position based on the rules given (ignoring the other players). It should be calling has_chute_or_ladder(), activate_ladder(), and activate_chute()
_____ get_mode(___)
Asks what mode the game should be in, and return the mode
_____square_symbol(____)
Returns the board symbol to be used at that location
_____ activate_ladder(____)
Print out a random message on what occurred to the player that landed on a ladder
_____ activate_chute (____)
Print out a random message on what occurred to the player that landed on a chute
_____ has_chute_or_ladder(___)
Returns whether the player landed on the START of chute, ladder or a normal square, and also return where the chute or ladder would lead to.
int main()
Mostly drives the program, but also holds the player list and game board.
Formatting
For each of the following event output the stated text.
The board is printed before each turn and has a line between the board and the player’s turn
Getting the player count: Please, enter how many players:
Getting an invalid player count: Please enter 2 to 4 players:
Printing the mode menu:
Choose which mode to play in
(D)ebug mode
(P)ower mode
Anything else will be regular mode
Enter Mode:
Printing the menu (where X is substituted with the current player’s letter:
----Current player is X----
(R)oll
(Q)uit
Getting an invalid menu option;
Invalid option
(R)oll
(Q)uit
After a normal roll(substitute a X with the value): Rolled a X
After a power roll(substitute a X with the user’s input value): Roll: X
After rolling past the end: Rolled past the end of the board. You need an exact roll.
After someone wins (substitute X with the user’s letter): "Player X won."
When quitting: Quitting...
Requirements
The players positions and letters MUST be stored in an array
The board MUST be in an array
You may NOT have corrupted memory with the game ends. This means you tried to put a value outside an array. MSVS will tell you when you end.
Since you do NOT have to pass arrays into functions, main may be up to, but no larger than, 100 lines (including whitespace and comments)
IF you decide to jump ahead and pass in arrays, main must be less than 60 lines. (including whitespace and comments)
All other functions must be under 50 lines, or two pages, including whitespace and comments
You should be able to get an exact match for all the described outputs at this time. This should match down to the character (ignoring trailing spaces)
Sample Output of the program (user input in bold italics)
The text file debug.txt shows a debug run
The text file power.txt shows power mode run
The text file normal.txt shows a normal run
Additional Comments
The functions must be written as described.
Vectors are not allowed.
Strings are not allowed with the exception of Cstrings.
Sample Program in Debug Mode
-----Chutes and ladders----- 1,2 3 go up, and #, $, and ^ go down Please, enter how many players: 2 Choose which mode to play in (D)ebug mode (P)ower mode Anything else will be regular mode Enter Mode: d | | | | # | 1 | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is a---- (R)oll (Q)uit r Rolled a 6 | | | | # | 1 | a | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is b---- (R)oll (Q)uit r Rolled a 4 Chute: Slippery | | | | # | 1 | a | 2 | | | | | | 1 | $ | | | | | | b | | 3 | | | | | | | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is a---- (R)oll (Q)uit r Rolled a 3 | | | | # | 1 | | 2 | | | a | | | 1 | $ | | | | | | b | | 3 | | | | | | | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is b---- (R)oll (Q)uit r Rolled a 6 | | | | # | 1 | | 2 | | | a | | | 1 | $ | | | | | | # | | 3 | | | | b | | | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is a---- (R)oll (Q)uit r Rolled a 3 Ladder: Climbing | | | | # | a | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | b | | | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is b---- (R)oll (Q)uit r Rolled a 1 | | | | # | a | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | b | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is a---- (R)oll (Q)uit r Rolled a 3 | | | | # | 1 | | 2 | a | | | | | 1 | $ | | | | | | # | | 3 | | | | | | b | | % | 2 | | | $ | | | | | | % | 3 | | | | ----Current player is b---- (R)oll (Q)uit r Rolled a 4 | | | | # | 1 | | 2 | a | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | b | | $ | | | | | | % | 3 | | | | ----Current player is a---- (R)oll (Q)uit r Rolled a 1 | | | | # | 1 | | 2 | | | a | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | b | | $ | | | | | | % | 3 | | | | ----Current player is b---- (R)oll (Q)uit r Rolled a 6 | | | | # | 1 | | 2 | | | a | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | $ | | | | | b | % | 3 | | | | ----Current player is a---- (R)oll (Q)uit r Rolled a 4 Chute: Slippery | | | | # | 1 | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | a | | | | | b | % | 3 | | | | ----Current player is b---- (R)oll (Q)uit r Rolled a 4 | | | | # | 1 | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | a | | | | | | % | 3 | | b | | ----Current player is a---- (R)oll (Q)uit r Rolled a 5 | | | | # | 1 | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | $ | | | | | | a | 3 | | b | | ----Current player is b---- (R)oll (Q)uit r Rolled a 6 Rolled past the end of the board. You need an exact roll. | | | | # | 1 | | 2 | | | | | | 1 | $ | | | | | | # | | 3 | | | | | | | | % | 2 | | | $ | | | | | | a | 3 | | b | | ----Current player is a---- (R)oll (Q)uit r Rolled a 4 Player a won.
//I have revised the previous incomplete solution. Sorry for the
inconvenience.Time was too less.Please reconsider your decision to
dislike.If you find this helpful, please leave a like.
#include <stdio.h>
#include <stdlib.h>
int print_menu()
{
char ress;
printf("(R)oll\n(Q)uit\n");
scanf(" %c",&ress);
while(ress!='r'&&ress!='R'&&ress!='q'&&ress!='Q')
{
printf("Invalid option\n(R)oll\n(Q)uit\n");
scanf(" %c",&ress);
}
if(ress=='r'||ress=='R')
return 1;
else
return 0;
}
int move(int cp)
{
int fl,obst,boo,fpp;
obst=has_chute_or_ladder(cp,&fl);
if(obst==1)
{
boo=activate_ladder();
if(boo==1)
fpp=fl;
else
fpp=cp;
}
else if(obst==-1)
{
boo=activate_chute();
if(boo==1)
fpp=fl;
else
fpp=cp;
}
else if(obst==0)
fpp=cp;
return fpp;
}
int get_mode()
{
int op;
char ress;
printf("\nChoose which mode to play in\n(D)ebug mode\n(P)ower
mode\nAnything else will be regular mode\nEnter Mode: ");
scanf(" %c",&ress);
if(ress=='d'||ress=='D')
op=1;
else if(ress=='p'||ress=='P')
op=2;
else
op=3;
return op;
}
char square_symbol(int y,int x)
{
char board[]=" #1 2 1$ # 3 %2 $ %3 "; //The board
int ti=(8*y)+x;
return board[ti];
}
int activate_ladder()
{
int boo;
if(rand()%2==0) //These are the two random situations
{
printf("Ladder: Climbing\n");
boo=1;
}
else
{
printf("Ladder: Not Climbing\n");
boo=0;
}
return boo;
}
int activate_chute()
{
int boo;
if(rand()%2==0) //These are the two random situations
{
printf("Chute: Slippery\n");
boo=1;
}
else
{
printf("Chute: Did not slip\n");
boo=0;
}
return boo;
}
int has_chute_or_ladder(int cpp,int *fll)
{
switch(cpp)
{
case 11:
*fll=4;
return 1;
break;
case 27:
*fll=6;
return 1;
break;
case 36:
*fll=19;
return 1;
break;
case 3:
*fll=17;
return -1;
break;
case 12:
*fll=30;
return -1;
break;
case 26:
*fll=35;
return -1;
break;
default:
return 0;
}
return 0;
}
int main()
{
printf("-----Chutes and ladders-----\n1,2 3 go up, and #, $, and ^
go down\n\nPlease, enter how many players: ");
int
fp,i,j,k,qq,pp,roll,mode,nplayers,res,cplyr,pos[]={-1,-1,-1,-1};
char players[]={'a','b','c','d'},sym;
scanf("%d",&nplayers);
while(nplayers<2||nplayers>4)
{
printf("Please enter 2 to 4 players: ");
scanf("%d",&nplayers);
}
mode=get_mode();
if(mode==3)
{
time_t t;
srand((unsigned) time(&t)); //Randomizing with time seed
}
else if(mode==1)
srand(10); //Randomizing
int rnr=0;
do
{
cplyr=rnr%nplayers;
for(i=0;i<5;i++) //Printing the board
{
for(j=0;j<8;j++)
{
sym=square_symbol(i,j); //Finding symbol to print
for(k=0;k<nplayers;k++)
{
if(pos[k]==(8*i)+j)
{
sym=players[k]; //Changing symbol if player is present there
}
}
printf("| %c ",sym);
}
printf("|\n");
}
printf("\n----Current player is %c----\n",players[cplyr]);
res=print_menu(); //taking roll or quit response
if(res==1)
{
if(mode==1||mode==3)
{
roll=(rand()%6)+1; //Generating random roll
printf("Rolled a %d\n",roll);
}
else
{
printf("Roll: ");
scanf("%d",&roll); // Taking roll as input for power mode
}
if(pos[cplyr]+roll>39)
{
printf("Rolled past the end of the board. You need an exact
roll.\n");
}
else if(pos[cplyr]+roll==39) //Checking for victory
{
printf("Player %c won.",players[cplyr]);
res=0;
}
else
{
fp=move(pos[cplyr]+roll); // Finding final position
for(pp=1;pp<nplayers;pp++)
{
qq=(cplyr+pp)%nplayers;
if(fp==pos[qq]) // Checking if there is anyone in final
position
{
printf("Would've landed on %c\n",players[qq]);
break;
}
}
if(pp==nplayers)
pos[cplyr]=fp;
}
}
rnr++;
}while(res==1);
return 0;
}
Please, I need help with program c++. This is a chutes and ladders program. The code...
"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 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...
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?...
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 20. 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 should the...
Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1) ...
I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional String 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 does the following: a. Displays the contents of the board array. b. Allows player 1 to select a location...
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...
18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use 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 does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...
Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...
I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...