research-writing-services
4.8
research-writing-services
4.9
research-writing-services
4.7

Please fix the bug in the code.

Code is complete but there is a bug when it compiles. Please fix the bug and then I will accept your bid. This is very urgent. I only have one hour!!————————————————————————————————–#ifndef CHESST01_H_INCLUDED#define CHESST01_H_INCLUDED #includeusing namespace std;class Piece{ private: string itsName; int itsVertAddress; int itsHorzAddress; public: void setItsVertAddress (int address){itsVertAddress = address;} void setItsHorzAddress (int address){itsHorzAddress = address;} int getItsVertAddress() {return itsVertAddress;} int getItsHorzAddress() {return itsHorzAddress;} void setItsName (string name){itsName=name;} string getItsName () {return itsName;}};class Board{ private: string itsBoard[26]; public: void setItsBoard(string []); void setPcsLoc(string,int,int); void DisplayBoard(); bool emptySpot(int ,int );};///////////////////// bool searchTouch(Piece [],int);// bool searchMove(Piece [],int,int);/////////////////////void Board::setItsBoard(string arr[]){ for(int i=0;i<26;i++) itsBoard[i]=arr[i];}void Board::DisplayBoard(){ for(int i=0;i<26;i++) cout< #include #include #include”chess.h” bool touchMove(Board*,Piece [],int,int,bool); bool checkMove(int); bool emptySpot(Piece [],int , int); bool pieceMove(Piece [],string ,string ,int ,int ); int switchNum(int,char); void resetBoard(Board *,Piece []); using namespace std; int main() { ///// 2 6 10 14 18 22 26 30 string arrPcs[26]={“–1—2—3—4—5—6—7—8—“, “- #### #### #### ####-“, “1 #### #### #### ####1”,//2 “- #### #### #### ####-“, “-#### #### #### #### -“, “2#### #### #### #### 2”,//5 “-#### #### #### #### -“, “- #### #### #### ####-“, “3 #### #### #### ####3”,//8 “- #### #### #### ####-“, “-#### #### #### #### -“, “4#### #### #### #### 4”,//11 “-#### #### #### #### -“, “- #### #### #### ####-“, “5 #### #### #### ####5”,//14 “- #### #### #### ####-“, “-#### #### #### #### -“, “6#### #### #### #### 6”,//17 “-#### #### #### #### -“, “- #### #### #### ####-“, “7 #### #### #### ####7”,//20 “- #### #### #### ####-“, “-#### #### #### #### -“, “8#### #### #### #### 8”,//23 “-#### #### #### #### -“, “–1—2—3—4—5—6—7—8—” }; Board gameBoard; gameBoard.setItsBoard(arrPcs ); Piece pcs[64]; resetBoard(&gameBoard,pcs); gameBoard.DisplayBoard();/////display the game board on screen cout<<"0 to end the game anytime"<>touch;if(touch!=0){cout<<"CHoose the target location "<>move;if((checkMove(move))&&(checkMove(touch))&&(touchMove(&gameBoard,pcs,touch,move,white))){ gameBoard.DisplayBoard();/////display the game board on screen if(white) { white=false;/////switch player cout<<"Black Turn"<setPcsLoc(pieces[k].getItsName(),MHorz,MVert); pieces[i].setItsName(” “); aboard->setPcsLoc(pieces[i].getItsName(),THorz,TVert); ok_touch=true; }/////////////////////////////////////////////////// } } } else if ((!white)&&(nameT[0]==’B’)) ////black can move black only { for(int k=0;k<=64;k++) ///////searching for the touched piece if((pieces[k].getItsHorzAddress()==MVert)&&(pieces[k].getItsVertAddress()==MHorz)) { nameM=pieces[k].getItsName(); if((!white)&&(nameM[0]!='B')) { /////////////////////////////////////////////////// if(pieceMove(pieces,nameT,nameM,addtouch,addmove))////////////fuction for the rules of each piece movement { pieces[k].setItsName(pieces[i].getItsName()); aboard->setPcsLoc(pieces[k].getItsName(),MHorz,MVert); pieces[i].setItsName(” “); aboard->setPcsLoc(pieces[i].getItsName(),THorz,TVert); ok_touch=true; } ////////////////////////////////////////////////////////// } } } else ok_touch=false; } return ok_touch; } int switchNum(int num,char xChar) { if(xChar==’h’) switch(num) { case 1 : num =2; break; case 2 : num =6; break; case 3 : num =10; break; case 4 : num =14; break; case 5 : num =18; break; case 6 : num =22; break; case 7 : num =26; break; case 8 : num =30; break; default : break; } else switch(num) { case 1 : num =2; break; case 2 : num =5; break; case 3 : num =8; break; case 4 : num =11; break; case 5 : num =14; break; case 6 : num =17; break; case 7 : num =20; break; case 8 : num =23; break; default : break; } return num; } void resetBoard(Board *gameBoard,Piece pcs[]) { for(int i=0,j=2;i<8;i++) { pcs[i].setItsName("WP"); pcs[i].setItsVertAddress(j); pcs[i].setItsHorzAddress(5); gameBoard->setPcsLoc(pcs[i].getItsName(),j,5); j+=4; } for(int i=8,j=2;i<16;i++) { pcs[i].setItsName("BP"); pcs[i].setItsVertAddress(j); pcs[i].setItsHorzAddress(20); gameBoard->setPcsLoc(pcs[i].getItsName(),j,20); j+=4; }/////set rook locations for(int i=16,j=2;i<18;i++) { //////set location for white rook pcs[i].setItsName("WR"); pcs[i].setItsVertAddress(j); pcs[i].setItsHorzAddress(2); gameBoard->setPcsLoc(pcs[i].getItsName(),j,2); ////set location for black rook pcs[i+2].setItsName(“BR”); pcs[i+2].setItsVertAddress(j); pcs[i+2].setItsHorzAddress(23); gameBoard->setPcsLoc(pcs[i+2].getItsName(),j,23); j=30; } /////set Knight locations for(int i=20,j=6;i<22;i++) { //////set location for white knight pcs[i].setItsName("WN"); pcs[i].setItsVertAddress(j); pcs[i].setItsHorzAddress(2); gameBoard->setPcsLoc(pcs[i].getItsName(),j,2); ////set location for black knight pcs[i+2].setItsName(“BN”); pcs[i+2].setItsVertAddress(j); pcs[i+2].setItsHorzAddress(23); gameBoard->setPcsLoc(pcs[i+2].getItsName(),j,23); j=26; } /////set Bishops locations for(int i=24,j=10;i<26;i++) { //////set location for white bishop pcs[i].setItsName("WB"); pcs[i].setItsVertAddress(j); pcs[i].setItsHorzAddress(2); gameBoard->setPcsLoc(pcs[i].getItsName(),j,2); ////set location for black bishop pcs[i+2].setItsName(“BB”); pcs[i+2].setItsVertAddress(j); pcs[i+2].setItsHorzAddress(23); gameBoard->setPcsLoc(pcs[i+2].getItsName(),j,23); j=22; } /////set Queens locations //////set location for white queen pcs[28].setItsName(“WQ”); pcs[28].setItsVertAddress(14); pcs[28].setItsHorzAddress(2); gameBoard->setPcsLoc(pcs[28].getItsName(),14,2); ////set location for black queen pcs[29].setItsName(“BQ”); pcs[29].setItsVertAddress(14); pcs[29].setItsHorzAddress(23); gameBoard->setPcsLoc(pcs[29].getItsName(),14,23); /////set kings locations //////set location for white king pcs[30].setItsName(“WK”); pcs[30].setItsVertAddress(18); pcs[30].setItsHorzAddress(2); gameBoard->setPcsLoc(pcs[30].getItsName(),18,2); ////set location for black king pcs[31].setItsName(“BK”); pcs[31].setItsVertAddress(18); pcs[31].setItsHorzAddress(23); gameBoard->setPcsLoc(pcs[31].getItsName(),18,23);/////////////set the other spotsint k=8; for(int i=32,j=2;i<64;i++) { //////set location for white knight pcs[i].setItsName(" "); pcs[i].setItsVertAddress(j); pcs[i].setItsHorzAddress(k); gameBoard->setPcsLoc(pcs[i].getItsName(),j,k);if(j<30)j+=4;else{j=2;k+=3;} } }bool checkMove(int move){ int first = move/10; int second = move%10; if((first<1)||(first>8)||(second<1)||(second>8)) return false; return true;}bool pieceMove(Piece pieces[],string nameT,string nameM,int touch ,int move ){ int moving=touch; int THorz = touch%10; int TVert = touch/10; int MHorz = move%10; int MVert = move/10; int movingH=THorz; int movingV=TVert; int diff=abs(touch-move); int signedDiff=touch-move; if(nameT[1]==’P’) ////if its pawn { if(nameT[0]==’W’)//////white pawn { if(nameM[0]==’ ‘)//////////////piece not attacking { if(move==touch+10)////one step forward ? return true;//yes? go return false;//no ? not accepted } else if(nameM[0]!=’ ‘)////attacking abviously black piece if((move==touch+11)||(move==touch+9)) //moving diagonal down? return true; /////diagonal return false;/////not diagonal } if(nameT[0]==’B’)//////black pawn { if(nameM[0]==’ ‘)//////////////piece not attacking { if(move==touch-10)////one step up return true;/////up ok return false;/////not up not accepted } if(nameM[0]!=’.’)////attacking abviously white piece if((move==touch-11)||(move==touch-9)) ////diagonal up return true;/////ok move return false;////not accepted } return false;////any unexpected mistake will return a non accepted move }///////////////////////////////////////////////////////////////////end of pawn statment ////////////knight if(nameT[1]==’N’) { int Hdiff=abs(THorz-MHorz); int Vdiff=abs(TVert-MVert); cout<<"Hdiff and Vdiff are "<MHorz)//theobjects is moving to the left movingH–; if(movingHMVert)//theobjects is moving Down movingV–; if(movingVTHorz)&&(MVert>TVert))//theobjects is moving to the left { movingH++; movingV++; } if((MHorzTHorz)&&(MVertTVert))////right direction { movingH–; movingV++; } ////after we move and before we accept the movement we need to check if ////there is no object is blocking the way of our moving object moving=movingV*10+movingH; if(moving!=move) if(!emptySpot(pieces,switchNum(movingH,’h’),switchNum(movingV,’v’))) return false; ////if an object is found the movement cant be done } ////if the while loop ends it means the path is clear and its ok to move return true; } else return false; } if(nameT[1]==’Q’) { if((movingH==MHorz)||(movingV==MVert)) ////if its vertical or horizontal moving rook or queen { ////while loop to the check that there are no objects to block the moving objects’s way while(moving!=move) ////the while loop ends if we reach the target { if(movingH>MHorz)//theobjects is moving to the left movingH–; if(movingHMVert)//theobjects is moving Down movingV–; if(movingVTHorz)&&(MVert>TVert))//theobjects is moving to the left { movingH++; movingV++; } if((MHorzTHorz)&&(MVertTVert))////right direction { movingH–; movingV++; } ////after we move and before we accept the movement we need to check if ////there is no object is blocking the way of our moving object moving=movingV*10+movingH; if(moving!=move) if(!emptySpot(pieces,switchNum(movingH,’h’),switchNum(movingV,’v’))) return false; ////if an object is found the movement cant be done } ////if the while loop ends it means the path is clear and its ok to move return true; } }return false;}bool emptySpot(Piece pieces[],int h, int v){ for(int i=0;i<=64;i++) if((pieces[i].getItsHorzAddress()==v)&&(pieces[i].getItsVertAddress()==h)&&(pieces[i].getItsName()==" ")) return true; return false;}

Related Posts

Quality Writing Features

Price Start $10
  • 24/7 Customer Support
  • All Subject Areas
  • Money-Back Guarantee
  • Timely Delivery
  • Originality report
  • Confidentiality guaranteed

Ordering Homework Writing Service

You can get our ideal online homework help services with four easy steps. All you have to do is inform us of your requirements. Immediately we will match with a specialist in your academic discipline. After that, we will track your order, review it to ensure it meets your requirements, and submit it to your email.

research-writing-services

Submit Requirements

Fill in your assignment instructions on the order form

research-writing-services

Writer match

Immediately you contact us for homework help; we will assign your assignment to an academic expert.

research-writing-services

Quality review

We have a team of editors, who will thoroughly review your assignment, ensuring there are no errors before submission

research-writing-services

Get Your Completed Paper

Once we have completed the assignment, we will deliver it to your account. Additionally, we will send a notification to your email.

ordernow

Affordable

Budget-friendly writing services

ordernow

Privacy

We don’t share our client’s information with a third party

ordernow

Unique

We write every assignment from scratch

Amazing Homework Writing Features

Once you consult us for homework help online services, you will attest to why we are among the USA's best essay writing services.

Read on and find out some of the features that make our services superlative.

Free Homework Writing Services

Free plagiarism checker

You can confirm that the content you get is original for free using our plagiarism checker.

Free samples

We offer unlimited access to our essay homework samples.

Free title page and bibliography

Once you place an order, we format it accordingly without demanding additional charges.

Free unlimited revisions

We offer free unlimited revisions until your assignment is of your desired quality..

Free editing and proofreading

We have a team of specialized editors who review your assignment before submission.

Free customer support

You can track the progress of your homework for free.

Request for Homework Writing Service Today!

We have over 500 homework writing experts, ready and waiting to help you improve your writing skills