Пример #1
0
        public char[] MinMax(char[] val, int depth, bool isOpening)
        {
            MiniMaxOpening m   = new MiniMaxOpening();
            MiniMaxGame    mid = new MiniMaxGame();

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

                double v = Double.PositiveInfinity;

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

                    double staticEstimate = isOpening ? m.StaticEstimationOpening(minValue) : mid.StaticEstimationMidEndGame(minValue, isOpening);
                    if (v > staticEstimate)
                    {
                        v = staticEstimate;
                        _MiniMaxEstimate = v;
                        minValue         = blackChild[ind];
                    }
                }
                return(minValue);
            }
            else if (depth == 0)
            {
                _Positions_Evaluated++;
            }
            return(val);
        }
Пример #2
0
        public char[] MaxMin(char[] val, int depth, bool isOpening)
        {
            MiniMaxOpening m   = new MiniMaxOpening();
            MiniMaxGame    mid = new MiniMaxGame();

            if (depth > 0)
            {
                depth--;
                List <char[]> child = new List <char[]>();
                char[]        minValue;
                char[]        maxValue = new char[43];
                child = isOpening ? m.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);

                    double staticEstimate = isOpening ? m.StaticEstimationOpening(minValue) : mid.StaticEstimationMidEndGame(minValue, isOpening);
                    if (v < staticEstimate)
                    {
                        v = staticEstimate;
                        _MiniMaxEstimate = v;
                        maxValue         = child[ind];
                    }
                }
                return(maxValue);
            }
            else if (depth == 0)
            {
                _Positions_Evaluated++;
            }
            return(val);
        }
Пример #3
0
        public List <char[]> GenerateBlackMove(char[] val, bool isOpening)
        {
            MiniMaxOpening m   = new MiniMaxOpening();
            MiniMaxGame    mid = new MiniMaxGame();

            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 ?  m.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);
        }