#include "Piece.h" #include "Board.h" #include #include #include using namespace std; void Piece::AddSquare(Space* s){ spaces.push_back(s); if (s->Color() == black) { blackSpaces.push_back(s);} // cout << "Piece "<< id << " has " << spaces.size() << " squares of which " << blackSpaces.size() << " are black\n"; } int Piece::RecenterAtNextBlackSquare(){ assert (!isOnBoard); // piece may NOT be on the Board when it is recentered iCenterBlackSquare++; if (iCenterBlackSquare == blackSpaces.size()) {iCenterBlackSquare = 0;} // back to beginning Recenter(); if (iCenterBlackSquare == 0){ return 1; // notify caller that we are back at beginning } else{ return 0; } } int Piece::RecenterAtOriginalSquare(){ iCenterBlackSquare = 0; Recenter(); return 0; } void Piece::ResetConfiguration(){ RecenterAtOriginalSquare(); ResetNumberOfTimesRotated(); } int Piece::Recenter(){ // cout << "Piece " << id << " being recentered at black square " << iCenterBlackSquare+1 << " of " << blackSpaces.size() << endl; // now make all coordinates relative to this piece int CenterColumn = blackSpaces[iCenterBlackSquare]->Column(); int CenterRow = blackSpaces[iCenterBlackSquare]->Row(); for (int is=0; isColumn() - CenterColumn; int newRow = s->Row() - CenterRow; // cout << "Square " << is << " rel. coords. changed from (" << s->Column() << "," << s->Row() << ")" // << " to (" << newColumn << "," << newRow << ")\n"; s->SetColumnRow(newColumn,newRow); } } // the rotation is around the axis at (0,0) which is one of the black squares of the piece int Piece::RotateCounterClockwise(unsigned int n){ assert (!isOnBoard); // piece may NOT be on the Board when it is rotated int wentAllTheWayRound=0; for (int i=0; iNumberOfSquares(); is++){ spaces[is]->RotateCounterClockwise(); } } return wentAllTheWayRound; } int Piece::RemoveFromBoard(Board* theBoard){ assert (isOnBoard); // don't remove it if it's not currently on Board (will reset Board spaces and screw it all up) // if (!isOnBoard) { return 1;} // return error if the thing is NOT on the board already isOnBoard = false; // clear the board, space by space // for (int is=0; isNumberOfSquares(); is++){ int boardCol = columnOfCenterSquare + spaces[is]->Column(); int boardRow = rowOfCenterSquare + spaces[is]->Row(); // cout << "clearing " << boardCol << " " << boardRow << endl; theBoard->Clear(boardCol,boardRow); } return 1; }