Example #1
0
        /**
         * @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);
        }
Example #2
0
        /**
         * @brief Compute a board resulting of an opponent move played on a previous board.
         *
         * Compute the board after passing and playing a move.
         *
         * @param board board to play the move on.
         * @param x opponent move to play.
         * @param next resulting board.
         * @return flipped discs.
         */
        ulong pass_next(int x, Board next)
        {
            const ulong flipped = flip[x](board.opponent, board.player);

            next.opponent = board.opponent ^ (flipped |  Bit.X_TO_BIT[x]);
            next.player = board.player ^ flipped;

            return flipped;
        }
Example #3
0
        /**
         * @brief Compute a board resulting of a move played on a previous board.
         *
         * @param board board to play the move on.
         * @param x move to play.
         * @param next resulting board.
         * @return flipped discs.
         */
        ulong next(int x, Board next)
        {
            const ulong flipped = flip[x](board.player, board.opponent);
            const ulong player = board.opponent ^ flipped;

            next.opponent = board.player ^ (flipped |  Bit.X_TO_BIT[x]);
            next.player = player;

            return flipped;
        }
Example #4
0
 /**
  * @brief Compare two board for equality
  *
  * @param b1 first board
  * @param b2 second board
  * @return true if both board are equal
  */
 static bool equal(Board b1, Board b2)
 {
     return (b1.player == b2.player && b1.opponent == b2.opponent);
 }
Example #5
0
 /**
  * @brief Compare two board
  *
  * @param b1 first board
  * @param b2 second board
  * @return -1, 0, 1
  */
 static int compare(Board b1, Board b2)
 {
     if (b1.player > b2.player) return 1;
     else if (b1.player < b2.player) return -1;
     else if (b1.opponent > b2.opponent) return 1;
     else if (b1.opponent < b2.opponent) return -1;
     else return 0;
 }
Example #6
0
        /**
         * @brief unique board
         *
         * Compute a board unique from all its possible symertries.
         *
         * @param board input board
         * @param unique output board
         */
        public int unique(Board unique)
        {
            Board sym;
            int i, s = 0;

            unique = new Board(player, opponent);
            for (i = 1; i < 8; ++i) {
            sym = symetry(i);
            if (compare(sym, unique) < 0) {
            unique = sym;
            s = i;
            }
            }

            return s;
        }