Exemplo n.º 1
0
        /// <summary>
        /// Propagates a roll out's result back through the tree.
        /// </summary>
        /// <param name="result">Whether the roll out resulted in a win or loss.</param>
        /// <param name="node">The current node.</param>
        /// <param name="tree">The game tree object.</param>
        private static void Propagate(bool result, int node, GameTree tree)
        {
            // Get the current node's parent ID.
            int parent = tree.GetParent(node);

            // Loop until we hit the root node's null parent link.
            while (parent != -1)
            {
                // Get the parent's node object from the game tree.
                GameTreeNode parentNode = tree.GetNode(parent);

                // Add the win/loss to the parent's node object.
                parentNode.AddResult(result);

                // Save the parent's node object to disk.
                tree.SetNode(parentNode);

                // Set the parent ID to the grandparent ID.
                parent = tree.GetParent(parent);
            }
        }