#include #include #include #include #include #include "Space.h" #include "Piece.h" #include "Board.h" using namespace std; bool SucceedInserting(Piece* piece,Board* board,int icol,int irow){ while (board->InsertPiece(piece,icol,irow)!=0){ // doesnt fit in this configuration. Try rotating if (piece->RotateCounterClockwise()!=0){ // we have tried all rotations at this centerpoint. Try recentering if (piece->RecenterAtNextBlackSquare()!=0){ // that's it. We have tried everything. It does not fit at all return false; // means doesn't fit } } } return true; // that means there was no problem. The Piece was inserted at the next available Space on the Board } // in this following function, we increment the configuration once first, then go to the SucceedInserting() bool ReconfigureThenTryInserting(Piece* piece,Board* board,int icol, int irow){ // cout << "--6\n"; if (piece->RotateCounterClockwise()!=0){ // we have tried all rotations at this centerpoint. Try recentering // cout << "--6.1\n"; if (piece->RecenterAtNextBlackSquare()!=0){ // that's it. We have tried everything. It does not fit at all // cout << "--6.2\n"; return false; // means doesn't fit } } // cout << "--7\n"; return SucceedInserting(piece,board,icol,irow); } bool IncrementConfiguration(Piece* p){ if (p->RotateCounterClockwise()!=0){ if (p->RecenterAtNextBlackSquare()!=0){ return false; } } return true; } int main(){ Board TheBoard; cout << "\n Empty Board\n"; TheBoard.Draw(); vector AllPieces; Space* sp; Piece* thePiece; // define Piece#1 thePiece = new Piece(); thePiece->SetId(1); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); sp = new Space(red,-1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,-1,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,-1,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#2 thePiece = new Piece(); thePiece->SetId(2); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); sp = new Space(black,0,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-3); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#3 thePiece = new Piece(); thePiece->SetId(3); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#4 (note #4 and #12 are identical pieces) thePiece = new Piece(); thePiece->SetId(4); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,-2); sp->SetOccupied(); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,2,-2); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#5 thePiece = new Piece(); thePiece->SetId(5); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(2); thePiece->AddSquare(sp); sp = new Space(red,2,-1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#6 thePiece = new Piece(); thePiece->SetId(6); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,0,-2); sp->SetOccupied(); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-3); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,-2); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#7 thePiece = new Piece(); thePiece->SetId(7); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,0,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-3); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,-1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#8 thePiece = new Piece(); thePiece->SetId(8); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); sp = new Space(black,-1,-1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,-1,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,-1,-3); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#9 thePiece = new Piece(); thePiece->SetId(9); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(red,0,1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(black,0,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,-1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,-1,-1); sp->SetOccupied(); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#10 thePiece = new Piece(); thePiece->SetId(10); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,1,-3); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#11 thePiece = new Piece(); thePiece->SetId(11); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,0,-1); sp->SetOccupied(); thePiece->AddSquare(sp); sp = new Space(black,0,-2); sp->SetOccupied(); thePiece->AddSquare(sp); sp = new Space(red,0,-3); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,-1,-1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,-1,-2); sp->SetOccupied(); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(red,1,-2); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); // define Piece#12 (note #4 and #12 are identical pieces) thePiece = new Piece(); thePiece->SetId(12); sp = new Space(black,0,0); // first Square should always be at 0,0 then others are relative to it sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,0); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); thePiece->AddSquare(sp); sp = new Space(black,1,-1); sp->SetOccupied(); sp->SetBorder(1); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(red,1,-2); sp->SetOccupied(); sp->SetBorder(2); sp->SetBorder(3); thePiece->AddSquare(sp); sp = new Space(black,2,-2); sp->SetOccupied(); sp->SetBorder(0); sp->SetBorder(1); sp->SetBorder(2); thePiece->AddSquare(sp); AllPieces.push_back(thePiece); list PiecesOnBoard; list PiecesOffBoard; // none of the Pieces, as yet, are on the Board for(vector::iterator iter = AllPieces.begin(); iter < AllPieces.end(); iter++){ PiecesOffBoard.push_back(*iter); } // for (int ipp=0; ippGetId() << endl; TheBoard.InsertPiece(AllPieces[ip],3,3); TheBoard.Draw(); AllPieces[ip]->RemoveFromBoard(&TheBoard); } cout << "\n Empty Board\n"; TheBoard.Draw(); TheBoard.DrawForPaw(); int look; cout << "What piece do you want to put at position (4,4)?\n"; cin >> look; look--; // pieceId=index-1 cout << "\n Piece Number " << AllPieces[look]->GetId() << endl; if (TheBoard.InsertPiece(AllPieces[look],3,3) != 0){ // if it returns non-zero, then piece didn't fit cout << "Piece did not fit on the Board!\n"; } TheBoard.Draw(); cout << "\n ======== Cut and paste the below into paw ========" << endl; cout << "title 'Piece " << AllPieces[look]->GetId() << "'" << endl; cout << "exec StartMovie" << endl; TheBoard.DrawForPaw(); cout << "pic/print Piece" << AllPieces[look]->GetId() << ".gif" << endl; return 0; }