Question
#include #include using namespace std; int rollDice() { string color[4]={green, orange,blue, red}; int r1=3-rand()%4; int r2=3-rand()%4; cout <
#include
using namespace std;
int rollDice() { string color[4]={"green", "orange","blue", "red"};
int r1=3-rand()%4; int r2=3-rand()%4;
cout<<" Dice Thrown: "< if(r1==0 && r2==0) return 1; if(r1==1 && r2==1) return 9; if(r1==2 && r2==2) return 10; if(r1==3 && r2==3) return 7; if((r1==0 && r2==1 )||(r1==1 && r2==0)) return 2; if((r1==0 && r2==2 )||(r1==2 && r2==0)) return 3; if((r1==0 && r2==3 )||(r1==3 && r2==0)) return 4; if((r1==3 && r2==2 )||(r1==2 && r2==3)) return 5; if((r1==3 && r2==1 )||(r1==1 && r2==3)) return 6; if((r1==1 && r2==2 )||(r1==2 && r2==1)) return 8; } void printBoard(int board[50]) { for(int i=0;i<50;i++){ if((i)%10==0) cout<<" "; if(board[i]==0) cout<<"- "; if(board[i]==1) cout<<"p1 "; if(board[i]==2) cout<<"p2 "; if(board[i]==3) cout<<"p3 "; if(board[i]==4) cout<<"p4 "; } } int checkPlayer(int board[50],int m) { if(board[m]!=0) return 1; else return 0; } int main() { int board[50]; int player[4]; int n,c,flag=0; char yes; for(int i=0;i<50;i++) board[i]=0; cout<<" How many players (2-4):"; cin>>n; for(int p=1;p<=n;p++) player[p]=0; printBoard(board); cout<<" Play the game hit 'y' "; cin>>yes; while(yes=='y') { for(int p=1;p<=n;p++) { cout<<" Player #"< if(c==1) { for(int i=1;i<=n;i++) if(player[p] } if(c==2) flag=3; if(c==3) flag=4; if(c==5) flag=-1; if(c==7) flag=8; if(c==10) flag=5; if(c==9) flag=6; int pos=checkPlayer(board,player[p]+=flag); if(pos==0){ player[p]+=flag; board[player[p]]=0; board[player[p]+flag]=p; } else{ int t=board[pos]; board[player[p]]=board[pos]; board[pos]=board[player[p]]; player[p]+=flag; player[pos]-=flag; } if(player[p]>49) { cout<<" Player #"< printBoard(board); return 1; } } } return 0; } What would this code look like with comments describing each segment?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started