Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. void OthelloBoard::UndoLastMove() {
  2.    OthelloMove *m = (OthelloMove*)mHistory.back();
  3.       // If last move was a pass, delete the pointer, pop off the stack and switch the player.
  4.       if (m->IsPass()) {
  5.       delete m;
  6.       mHistory.pop_back();
  7.       mNextPlayer = mNextPlayer * -1;
  8.    }
  9.     // Otherwise look through flipset class and switch back the pieces
  10.    for (OthelloMove::FlipSet &s : m->mFlips) {
  11.       int row = m->mRow + s.rowDelta, col = m->mCol + s.colDelta, enemy = s.switched;
  12.       mBoard[m->mRow][m->mCol] = EMPTY; // set the last inputed piece as an empty spot
  13.       while (enemy != 0) { // loop flipping the previous pieces
  14.         mBoard[row][col] = mNextPlayer;
  15.         enemy--;
  16.       }
  17.    }
  18.     // Delete m pointer, switch player, and pop the history off the stack
  19.    delete m;
  20.    mNextPlayer = mNextPlayer * -1;
  21.    mHistory.pop_back();
  22.  
  23.    // Get the new value of the board
  24.     mValue = 0;
  25.    for (int row = 0; row < BOARD_SIZE; row++) {
  26.       for (int col = 0; col < BOARD_SIZE; col++) {
  27.          mValue += mBoard[row][col];
  28.       }
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement