Question: #include #include #include #include using namespace std ; //Globalconstantdefinition const int PLAYER_NUM= 5 ; const int SIZE= 5 ; const int MAX_NAME_LENGTH= 10 ; const
#include#include #include #include usingnamespacestd; //Globalconstantdefinition constintPLAYER_NUM=5; constintSIZE=5; constintMAX_NAME_LENGTH=10; constintMAX_NUMBER=SIZE*SIZE; //User-defineddatatype structPlayer { charname[MAX_NAME_LENGTH]; intbingo_card[SIZE][SIZE]; boolcard_status[SIZE][SIZE];//0forempty,1foroccupied boolbingo; }; //Yourcodehere /* Task1 Initializetheplayers: Assignthename Randomlygenerateabingocard Initializecard_statustoallzerosandbingotofalse Hint:youcanuse"std::random_shuffle()"functiontogenerate1darraywithsize25,andresizeitto5x52darray */ //functionname:init_player //Yourcodehere voidinit_player(Player&plys,charname[]) { strcpy(plys.name,name); constunsignedintrow=5; constunsignedintcol=5; //generate1Darray unsignedinta[row*col]; for(inti=0;i 1; random_shuffle(&a[0],&a[row*col]); //Assign1Darrayvaluetobingocard for(intj=0;j
for(intk=0;k
0; } plys.bingo=false; } /* Task2: Displayfiveplayers'information: Ifthenumberhasbeenpicked,add'*'afterit. Theoutputforeachplayerlookslikethis: ___________________________________________________ Name:Peter Bingocard('*'meansthenumberhasbeenpicked) 204151611 323259*5 2186122 101221419 132471718 */ //functionname:display_info //Yourcodehere voiddisplay_info(Playerplys[],constintnum) { for(intk=0;k cout<<"Name:"< endl; cout<<"Bingocard('*'meansthenumberhasbeenpicked)"<<endl; for(inti=0;i for(intj=0;j if(plys[k].card_status[i][j]==1) cout< '*'<<'\t'; cout< '\t'; } cout<<endl;}} } /* Task3: Changethestatusforpickednumber: Youshouldfindthepositionofthenumberyoupickedinbingocardandupdatethestatus. */ //functionname:change_status //Yourcodehere voidchange_status(Player&plys,intchosenNum) { for(inti=0;i for(intj=0;j if(plys.bingo_card[i][j]==chosenNum) {plys.card_status[i][j]==1;} } } /* Task4: Checkbingo: Youshouldcheckthestatusforallrows,columnsandtwodiagonals. Returntrueifthereisanentireoccupiedline,otherwise,returnfalse. */ //functionname:check_bingo //Yourcodehere boolcheck_bingo(Player&plys) { //columnwin for(inti=0;i if(plys.card_status[0][i]==1&&plys.card_status[1][i]==1&&plys.card_status[2][i]==1 &&plys.card_status[3][i]==1&&plys.card_status[4][i]==1) {returntrue;} } //rowwin for(intj=0;j if(plys.card_status[j][0]==1&&plys.card_status[j][1]==1&&plys.card_status[j][2]==1 &&plys.card_status[j][3]==1&&plys.card_status[j][4]==1) {returntrue;} } //diagonalright if(plys.card_status[4][0]==1&&plys.card_status[3][1]==1&&plys.card_status[2][2]==1 &&plys.card_status[1][3]==1&&plys.card_status[0][4]==1) {returntrue;} //diagonalleft if(plys.card_status[0][4]==1&&plys.card_status[1][3]==1&&plys.card_status[2][2]==1 &&plys.card_status[3][1]==1&&plys.card_status[4][0]==1) {returntrue;} returnfalse; } intmain() { boolEND=false; structPlayerplys[PLAYER_NUM]; //inputinformationforeachplayer for(inti=0;i charname[MAX_NAME_LENGTH]; cout<<"Player"<1<<endl; cout<<"Entername(shorterthan10characters)"<<endl; cin>>name; cout<<"Generatingbingocardforplayer"<1<<"..."<<endl; init_player(plys[i],name); } cout<<"Initializationdone."<<endl; display_info(plys,PLAYER_NUM); //Startgame cout<<endl; cout<<"=================WelcometoBingoGame================="<<endl; intround=0; while(!END){ cout<<"-----------Round"<<++round<<"-----------"<<endl; cout<<"Pleaseselectanumberbetween1to25:"; intselected_number; cin>>selected_number; for(inti=0;i<5;i++){ change_status(plys[i],selected_number); boolret=check_bingo(plys[i]); if(ret){ END=true; } } display_info(plys,PLAYER_NUM); } //printthewinner(s) for(inti=0;i<5;i++){ if(plys[i].bingo) cout< "isthewinner!"<<endl; } cout<<"=================Gameover=================="<<endl; return0; }
Background Information:
This is a group game with 5 players. Each player has a bingo card (the size is 5x5), which is filled with numbers from 1 to 25. The position of each number is random and one number appears exactly once.
The procedure of the game:
- At the beginning, you need to initialize the information for players, including their names, bingo cards and so on.
- After that you can start the game. For each round, you need to pick one number from range 1 to 25. (You can assume that you never pick the repeated number.) Then, the grid with this number on the bingo card is considered as occupied.
- After several rounds, when there is one player having an entire occupied row, column, or diagonal, the game is over and that player gets bingo!
Problem:
I am simulating a 5x5 array Bingo game where each turn the player's bingo_card will be "occupied" if the selected number is equal to the value of the bingo_card. In this scenario, the card_status will be changed to 1.
Right now, I am having trouble in the change_status/display_info function. I can't seem to update my Struct Array to reflect the change in card_status after each round.
Not sure where I gone wrong in my code and will appreciate some help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
