예제 #1
0
        public double Execute(OthelloBoard board, bool max, int depth)
        {
            if (depth == MaxDepth)
            {
                return(board.HeuristicUtility());
            }

            var children = board.Expand(max ? 1 : 2);

            if (children.Count == 0)
            {
                return(board.HeuristicUtility());
            }

            var result = !max ? double.MaxValue : double.MinValue;

            foreach (var othelloBoard in children)
            {
                var value = Execute(othelloBoard, !max, depth + 1);
                othelloBoard.UtilityValue = value;
                result = max ? Math.Max(value, result) : Math.Min(value, result);
            }

            if (depth == 0)
            {
                _resultMove = children.First(c => c.UtilityValue == result).MoveFrom;
            }

            return(result);
        }