#include "Move.h" Move::Move(vector AllPieces, int column, int row){ // the input argument should be the vector of all Pieces. // I will then make and keep a list of all pieces which are not yet // on the board, and those will be the ones I will need to try for (int ip=0; ipIsOnBoard())){ AllPieces[ip]->ResetConfiguration(); PiecesYetToBeTried.push_back(AllPieces[ip]); } } iColumn = column; iRow = row; } /* Here we Attempt() the next possibility. So we try to increment the configuration of the Piece presently on the Board. If we use up all the Piece's configurations, it is removed from the Board (and the list of untried Pieces in this Move) and we go to the next Piece. If we wind up with a possibility which "works" we return 0. If we run out of Pieces without finding one, then we return nonzero. */ int Move::Attempt(Board* board){ // first check to see if the Piece at the end of the list is already on the Board // (if this is the first Attempt(), then it will not be... // list::iterator pThePiece; while (PiecesYetToBeTried.size() > 0){ // Piece* ThePiece = PiecesYetToBeTried[0]; Piece* ThePiece = *(PiecesYetToBeTried.begin()); bool ThisPieceFails = TRUE; bool KeepTryingPiece=TRUE; if (ThePiece->IsOnBoard()){ ThePiece->RemoveFromBoard(board); } else{ KeepTryingPiece = board->SucceedInserting(ThePiece,iColumn,iRow); if (KeepTryingPiece){ ThisPieceFails = (board->AnyRedOrphans() || board->AnyBlackOrphans()); if (ThisPieceFails) ThePiece->RemoveFromBoard(board); } } while (ThisPieceFails && KeepTryingPiece){ KeepTryingPiece= board->ReconfigureThenTryInserting(ThePiece,iColumn,iRow); if (KeepTryingPiece){ ThisPieceFails = (board->AnyRedOrphans() || board->AnyBlackOrphans()); if (ThisPieceFails) ThePiece->RemoveFromBoard(board); } } if (ThisPieceFails){ // goodbye, Piece ThePiece->ResetConfiguration(); PiecesYetToBeTried.pop_front(); } else{ return 0; // yay, got one!! } } return 1; // bummer. Nothing works }