/** * @brief Update a board. * * Update a board by flipping its discs and updating every other data, * according to the 'move' description. * * @param board the board to modify * @param move A Move structure describing the modification. */ void update(Move move) { player ^= (move.flipped | Bit.X_TO_BIT[move.x]); board.opponent ^= move.flipped; swap_players(board); check(board); }
/** * @brief Compute a move. * * Compute how the board will be modified by a move without playing it. * * @param board board * @param x square on which to move. * @param move a Move structure remembering the modification. * @return the flipped discs. */ ulong get_move(int x, ref Move move) { move.flipped = flip[x](player, opponent); move.x = x; return move.flipped; }
/** * @brief Restore a board. * * Restore a board by un-flipping its discs and restoring every other data, * according to the 'move' description, in order to cancel a update_move. * * @param board board to restore. * @param move a Move structure describing the modification. */ void restore(Board board, Move move) { swap_players(board); board.player ^= (move.flipped | Bit.X_TO_BIT[move.x]); board.opponent ^= move.flipped; check(board); }
/** * @brief Check if a move is legal. * * @param board board * @param move a Move. * @return true if the move is legal, false otherwise. */ bool check_move(Move move) { if (move.x == PASS) return !can_move(board.player, board.opponent); else if ((X_TO_BIT[move.x] & ~(board.player|board.opponent)) == 0) return false; else if (move.flipped != flip[move.x](board.player, board.opponent)) return false; else return true; }