示例#1
0
        public char[] MinMax(char[] val, int depth, bool isOpening, double alpha, double beta)
        {
            BoardCommon b = new BoardCommon();

            ABGame mid = new ABGame();

            if (depth > 0)
            {
                depth--;
                List <char[]> blackChild = new List <char[]>();
                char[]        minValue   = new char[50];
                char[]        maxValue;
                blackChild = GenerateBlackMove(val, isOpening);

                double v = Double.PositiveInfinity;

                for (int ind = 0; ind < blackChild.Count; ind++)
                {
                    maxValue = MaxMin(blackChild[ind], depth, isOpening, alpha, beta);

                    double staticEstimate = isOpening ? StaticEstimationOpening(minValue) : mid.StaticEstimationMidEndGame(minValue, isOpening);

                    if (v > staticEstimate)
                    {
                        v = staticEstimate;
                        _ABMiniMaxEstimate = v;
                        minValue           = blackChild[ind];
                    }

                    if (v <= alpha)
                    {
                        return(minValue);
                    }
                    else
                    {
                        beta = Math.Min(v, beta);
                    }
                }
                return(minValue);
            }
            else if (depth == 0)
            {
                _ABPositions_Evaluated++;
            }
            return(val);
        }
示例#2
0
        public char[] MaxMin(char[] val, int depth, bool isOpening, double alpha, double beta)
        {
            BoardCommon b = new BoardCommon();

            ABGame mid = new ABGame();

            if (depth > 0)
            {
                depth--;
                List <char[]> child = new List <char[]>();
                char[]        minValue;
                char[]        maxValue = new char[50];
                child = isOpening ? GenerateAdd(val) : mid.GenerateMovesMidgameEndgame(val);  //so that midgame move and generate add are called by passing parameter from calling function

                double v = Double.NegativeInfinity;

                for (int ind = 0; ind < child.Count; ind++)
                {
                    minValue = MinMax(child[ind], depth, isOpening, alpha, beta);

                    double staticEstimate = isOpening ? StaticEstimationOpening(minValue) : mid.StaticEstimationMidEndGame(minValue, isOpening);
                    if (v < staticEstimate)
                    {
                        v = staticEstimate;
                        _ABMiniMaxEstimate = v;
                        maxValue           = child[ind];
                    }

                    if (v >= beta)
                    {
                        return(maxValue);
                    }
                    else
                    {
                        alpha = Math.Max(v, alpha);
                    }
                }
                return(maxValue);
            }
            else if (depth == 0)
            {
                _ABPositions_Evaluated++;
            }
            return(val);
        }
示例#3
0
        public List <char[]> GenerateBlackMove(char[] val, bool isOpening)
        {
            ABGame mid = new ABGame();

            char[] copyOfBoard = (char[])val.Clone();

            for (int ind = 0; ind < copyOfBoard.Length; ind++)
            {
                if (copyOfBoard[ind] == 'W')
                {
                    copyOfBoard[ind] = 'B';
                    continue;
                }
                if (copyOfBoard[ind] == 'B')
                {
                    copyOfBoard[ind] = 'W';
                }
            }

            List <char[]> blackMove        = new List <char[]>();
            List <char[]> blackMoveReplace = new List <char[]>();

            blackMove = isOpening ? GenerateAdd(copyOfBoard) : mid.GenerateMovesMidgameEndgame(copyOfBoard);
            foreach (char[] b in blackMove)
            {
                char[] board = b;
                for (int i = 0; i < board.Length; i++)
                {
                    if (board[i] == 'W')
                    {
                        board[i] = 'B';
                        continue;
                    }
                    if (board[i] == 'B')
                    {
                        board[i] = 'W';
                    }
                }
                blackMoveReplace.Add(b);
            }
            return(blackMoveReplace);
        }