コード例 #1
0
        protected int eval(Game g, LastTwoGamesEvaluationDto gamesEvaluation)
        {
            if (isAlreadyQuintEssence)
            {
                return(gamesEvaluation.GetLastGameEvaluation());
            }

            isAlreadyQuintEssence = true;
            if (!isMinLast)
            {
                var gameValue = abSearchMax(7, lastAlpha, lastBeta, gamesEvaluation);
                isAlreadyQuintEssence = false;
                return(gameValue);
            }
            else
            {
                var gameValue = abSearchMin(7, lastAlpha, lastBeta, gamesEvaluation);
                isAlreadyQuintEssence = false;
                return(gameValue);
            }
        }
コード例 #2
0
 public LastTwoGamesEvaluationDto(LastTwoGamesEvaluationDto lastTwoGamesEvaluationDto, int lastEval)
 {
     this.lastEval   = lastEval;
     penultimateEval = lastTwoGamesEvaluationDto.lastEval;
 }
コード例 #3
0
        protected int abSearchMin(int depth, int alpha, int beta, LastTwoGamesEvaluationDto lastTwoGamesEvaluationDto)
        {
            Console.WriteLine("searching depth :{0}, alpha: {1}, beta: {2}", depth, alpha, beta);
            if (g.hasFinished)
            {
                switch (g.winner)
                {
                case true:
                    return(1000 + depth);

                case false:
                    return(-1000 - depth);

                case null:
                    return(0);
                }
            }

            int b = beta;

            LastTwoGamesEvaluationDto thisGameEvaluation;

            if (isAlreadyQuintEssence)
            {
                var expectedGameResult = base.eval(g);

                var change =
                    Math.Min(
                        Math.Abs(lastTwoGamesEvaluationDto.GetPenultimateGameEvaluation() - expectedGameResult),
                        Math.Abs(lastTwoGamesEvaluationDto.GetLastGameEvaluation() - expectedGameResult)
                        );
                if (change >= ChangeThreshold)
                {
                    Console.WriteLine("unstable state found with change {0}", change);
                    thisGameEvaluation = new LastTwoGamesEvaluationDto(lastTwoGamesEvaluationDto, expectedGameResult);
                }
                else
                {
                    return(expectedGameResult);
                }
            }
            else
            {
                if (depth == 1 || depth == 2)
                {
                    thisGameEvaluation = new LastTwoGamesEvaluationDto(lastTwoGamesEvaluationDto, base.eval(g));
                }
                else
                {
                    thisGameEvaluation = new LastTwoGamesEvaluationDto(lastTwoGamesEvaluationDto, HighThreshold);
                }
            }

            if (depth <= 0)
            {
                SetState(true, alpha, beta);
                return(eval(g, thisGameEvaluation));
            }

            List <int> moves = new List <int>(g.possibleMoves);
            int        value, bestMove = -1, bestValue = 2000;

            foreach (var item in moves)
            {
                g.playMove(false, item);

                value = abSearchMax(depth - 1, alpha, b, thisGameEvaluation);
                if (value < bestValue)
                {
                    bestValue = value;
                    bestMove  = item;
                }
                g.undoMove(item);
                if (bestValue <= alpha)
                {
                    return(bestValue);
                }
                b = Math.Min(b, value);
            }
            return(bestValue);
        }