Beispiel #1
0
        private TicTacToeMonteCarloGameState(TicTacToeSquareState[][] board, bool initState, bool isXTurn)
        {
            IsXTurn = isXTurn;
            Board   = board;
            int numOfEmpties = 0;

            if (initState)
            {
                for (int i = 0; i < Board.Length; i++)
                {
                    Board[i] = new TicTacToeSquareState[Board.Length];
                }
                numOfEmpties = 9;
            }
            else
            {
                for (int i = 0; i < Board.Length; i++)
                {
                    for (int j = 0; j < Board.Length; j++)
                    {
                        if (Board[i][j] == TicTacToeSquareState.None)
                        {
                            numOfEmpties++;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public TicTacToeSquareState Winning()
        {
            for (int i = 0; i < Board.Length; i++)
            {
                TicTacToeSquareState curr = Board[i][0];
                bool valid = true;
                for (int j = 0; j < Board.Length; j++)
                {
                    if (curr != Board[i][j])
                    {
                        valid = false;
                        break;
                    }
                }
                if (valid && curr != TicTacToeSquareState.None)
                {
                    return(curr);
                }
            }

            for (int i = 0; i < Board.Length; i++)
            {
                TicTacToeSquareState curr = Board[0][i];
                bool valid = true;
                for (int j = 0; j < Board.Length; j++)
                {
                    if (curr != Board[j][i])
                    {
                        valid = false;
                        break;
                    }
                }
                if (valid && curr != TicTacToeSquareState.None)
                {
                    return(curr);
                }
            }

            TicTacToeSquareState curr2 = Board[0][0];
            bool valid2 = true;

            for (int i = 0; i < Board.Length; i++)
            {
                if (curr2 != Board[i][i])
                {
                    valid2 = false;
                    break;
                }
            }
            if (valid2 && curr2 != TicTacToeSquareState.None)
            {
                return(curr2);
            }

            valid2 = true;
            curr2  = Board[Board.Length - 1][0];
            for (int i = 0; i < Board.Length; i++)
            {
                if (curr2 != Board[Board.Length - 1 - i][i])
                {
                    valid2 = false;
                    break;
                }
            }
            if (valid2 && curr2 != TicTacToeSquareState.None)
            {
                return(curr2);
            }

            return(TicTacToeSquareState.None);
        }