示例#1
0
        /// <summary>
        /// Returns a new GameBoard identical to this one.
        /// </summary>
        /// <returns></returns>
        public GameBoard Duplicate()
        {
            GameBoard copy  = new GameBoard();
            char      turn  = this.CurrentTurn;
            int       count = 0;

            Utility.ActOnMatrix((i, j) =>
            {
                char mark = moveMatrix[i, j];

                if (mark == 'X')
                {
                    count++;
                }
                if (mark == 'O')
                {
                    count--;
                }
                if (mark != 'N')
                {
                    copy.Mark(j, i, moveMatrix[i, j]);
                }
            });

            copy.CurrentTurn = turn;

            return(copy);
        }
示例#2
0
        /// <summary>
        /// Marks the GameBoard at the specified coordinates.
        /// </summary>
        /// <param name="x">The x-coordinate of the space to mark.</param>
        /// <param name="y">The y-coordinate of the space to mark.</param>

        public void Mark(int x, int y)
        {
            if (gameBoard.Mark(x, y))
            {
                char winner = gameBoard.TestBoard();
                if (winner != 'N')
                {
                    isFinished = true;
                    DisplayResult(winner);
                }
                UpdateMarks();
            }
        }
示例#3
0
        /// <summary>
        /// Gets all potential moves of the specified game board for the current player, in the form of a
        /// List of GameBoards where each board has one of the moves performed.
        /// </summary>
        /// <param name="board">The GameBoard whose children should be generated.</param>
        /// <returns>Returns a List of GameBoards, each representing possible states that the specified GameBoard could reach.</returns>
        public static List <GameBoard> GenerateChildren(GameBoard board)
        {
            List <GameBoard> children = new List <GameBoard>();

            Utility.ActOnMatrix((i, j) =>
            {
                if (board.MoveMatrix[i, j] == 'N')
                {
                    GameBoard copy = board.Duplicate();
                    copy.Mark(j, i);
                    children.Add(copy);
                }
            });

            return(children);
        }