Пример #1
0
        private double maxValue(CheckersModel gameClone, int depth)
        {
            var moves = shuffle(gameClone.GetPossibleMoves(Colour));

            if (moves.Count == 0)
            {
                return(double.MinValue);
            }
            if (depth == 0)
            {
                return(gameClone.CountPiecesOfColour(Colour) - gameClone.CountPiecesOfColour(Colour.MyEnemy()));
            }

            var maxFound = double.MinValue;

            foreach (var move in moves)
            {
                CheckersModel clone = gameClone.Clone();
                if (!clone.TryMakeMove(Colour, move))
                {
                    Console.WriteLine("YOU ALSO F****D UP");
                }
                maxFound = Math.Max(maxFound, minValue(clone, depth - 1));
            }
            return(maxFound);
        }
Пример #2
0
        private Move miniMax(CheckersModel gameModel, int depth = 5)
        {
            var bestScore = double.MinValue;
            var bestMove  = Move.Empty;

            foreach (var move in shuffle(gameModel.GetPossibleMoves(Colour)))
            {
                CheckersModel clone = gameModel.Clone();
                clone.TryMakeMove(Colour, move);

                var score = minValue(clone, depth - 1);
                if (score >= bestScore)
                {
                    bestMove  = move;
                    bestScore = score;
                }
            }
            return(bestMove);
        }