Exemple #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);
        }
Exemple #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);
        }