Ejemplo n.º 1
0
        public Node CreateTree(bool maximizingPlayer, int maxDepth, Node node)
        {
            if (maxDepth == 0)
            {
                return(node);
            }

            if (node == null)
            {
                node      = CreateLevel(maximizingPlayer);
                maxDepth -= 1;
            }

            if (node.Children == null)
            {
                node = CreateLevel(maximizingPlayer);
            }

            for (int i = 0; i < node.Children.Count; i++)
            {
                maximizingPlayer = !maximizingPlayer;
                var childrenGameState = new GameTree(node.Children[i].GameBoardState);
                node.Children[i] = childrenGameState.CreateTree(maximizingPlayer, maxDepth - 1, node.Children[i]);
            }

            return(node);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            char[,] gameBoard = new char[7, 7] {
                { 'e', 'e', 'e', 'b', 'e', 'e', 'e' },                         // e <-- empty
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e' },                         // b <-- black pawn
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e' },                         // w <-- white pawn
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e' },                         // d <-- blocked
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'w', 'e', 'e', 'e' },
            };

            var gameTree = new GameTree(gameBoard);
            var tree     = gameTree.CreateTree(true, 4, null);

            var minimax = new Minimax();

            tree.Value = minimax.Compute(tree, 3, true);
        }