Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void OthelloBoard::UndoLastMove() {
- OthelloMove *m = (OthelloMove*)mHistory.back();
- // If last move was a pass, delete the pointer, pop off the stack and switch the player.
- if (m->IsPass()) {
- delete m;
- mHistory.pop_back();
- mNextPlayer = mNextPlayer * -1;
- }
- // Otherwise look through flipset class and switch back the pieces
- for (OthelloMove::FlipSet &s : m->mFlips) {
- int row = m->mRow + s.rowDelta, col = m->mCol + s.colDelta, enemy = s.switched;
- mBoard[m->mRow][m->mCol] = EMPTY; // set the last inputed piece as an empty spot
- while (enemy != 0) { // loop flipping the previous pieces
- mBoard[row][col] = mNextPlayer;
- enemy--;
- }
- }
- // Delete m pointer, switch player, and pop the history off the stack
- delete m;
- mNextPlayer = mNextPlayer * -1;
- mHistory.pop_back();
- // Get the new value of the board
- mValue = 0;
- for (int row = 0; row < BOARD_SIZE; row++) {
- for (int col = 0; col < BOARD_SIZE; col++) {
- mValue += mBoard[row][col];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement