Exemplo n.º 1
0
        public Board ComputerMakeMove(int depth)
        {
            Board next = Current.FindNextMove(depth);
            if (next != null)
                Current = next;

            return Current;
        }
Exemplo n.º 2
0
        static bool IsSameBoard(Board a, Board b, bool compareRecursiveScore)
        {
            if (a == b)
                return true;
            if (a == null || b == null)
                return false;
            for (int i = 0; i < a.BoardArray.Length; i++)
            {
                if (a.BoardArray[i] != b.BoardArray[i])
                    return false;
            }

            if (a.m_Score != b.m_Score)
                return false;

            if (compareRecursiveScore && Math.Abs(a.RecursiveScore) != Math.Abs(b.RecursiveScore))
                return false;

            return true;
        }
Exemplo n.º 3
0
        public int MiniMaxWithDebug(int depth, bool needMax, int alpha, int beta, out Board childWithMax)
        {
            childWithMax = null;
            System.Diagnostics.Debug.Assert(m_TurnForPlayerBlack == needMax);
            if (depth == 0 || IsTerminalNode())
            {
                RecursiveScore = m_Score;
                return m_Score;
            }

            var childBoards = GetChildren();
            foreach (Board cur in childBoards)
            {
                Board dummy;
                int score = cur.MiniMaxWithDebug(depth - 1, !needMax, alpha, beta, out dummy);
                if (!needMax)
                {
                    if (beta > score)
                    {
                        beta = score;
                        childWithMax = cur;
                        if (alpha >= beta)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    if (alpha < score)
                    {
                        alpha = score;
                        childWithMax = cur;
                        if (alpha >= beta)
                        {
                            break;
                        }
                    }
                }
            }

            RecursiveScore = needMax ? alpha : beta;
            return RecursiveScore;
        }
Exemplo n.º 4
0
 public CheckGame(GridEntry[] testBoard)
 {
     GridEntry[] values = testBoard;
     init = new Board(values, true);
     Current = init;
 }
Exemplo n.º 5
0
        public int MiniMax(int depth, int alpha, int beta, out Board childWithMax)
        {
            childWithMax = null;
            if (depth == 0 || IsTerminalNode())
            {
                //When it is turn for WhitePlayer, we need to find the minimum score.
                RecursiveScore = m_Score;
                return m_TurnForPlayerBlack ? m_Score : -m_Score;
            }

            foreach (Board currentBoard in GetChildren())
            {
                Board dummy;
                int score = -currentBoard.MiniMax(depth - 1, -beta, -alpha, out dummy);
                if (alpha < score)
                {
                    alpha = score;
                    childWithMax = currentBoard;
                    if (alpha >= beta)
                    {
                        break;
                    } 
                }
            }

            RecursiveScore = alpha;
            return alpha;
        }
Exemplo n.º 6
0
 public CheckGame()
 {
     GridEntry[] values = SetUpInitBoard();
     init = new Board(values, true);
     Current = init;
 }