Exemplo n.º 1
0
        /// <summary>
        /// Clone method which does a deep copy of the object.
        /// This is needed if we are materializing a tranposition subtree and
        /// encounter a subnode which is itself tranposition linked; we need to create
        /// another instance of the visitor which can then proceed enumerating indpendently.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            MCTSNodeTranspositionVisitor ret = new MCTSNodeTranspositionVisitor();

            ret.Visitor = Visitor.Clone() as MCTSNodeSequentialVisitor;
            ret.TranspositionRootNWhenVisitsStarted = TranspositionRootNWhenVisitsStarted;
            return(ret);
        }
Exemplo n.º 2
0
        private static LeafEvaluationResult ExtractTranspositionNodesFromSubtree(MCTSNode node, ref MCTSNodeStruct transpositionRootNode,
                                                                                 ref int numAlreadyLinked, MCTSNodeTranspositionVisitor linkedVisitor)
        {
            LeafEvaluationResult result = default;

            // Determine how many evaluations we should extract (based on number requested and number available)
            int numAvailable = linkedVisitor.TranspositionRootNWhenVisitsStarted - numAlreadyLinked;
            int numDesired   = node.NInFlight + node.NInFlight2;

            if (numDesired > numAvailable && WARN_COUNT < 10)
            {
                Console.WriteLine(numDesired + " Warning: multiple nodes were requested from the transposition subtree, available " + numAvailable);
                WARN_COUNT++;
            }
            int numToFetch = Math.Min(numDesired, numAvailable);

            Debug.Assert(numToFetch > 0);

            // Extract each evaluation
            for (int i = 0; i < numToFetch; i++)
            {
                MCTSNodeStructIndex transpositionSubnodeIndex = linkedVisitor.Visitor.GetNext();
                Debug.Assert(!transpositionSubnodeIndex.IsNull);

                NumExtractedAndNeverCloned++;
                numAlreadyLinked++;

                // Prepare the result to return
                ref MCTSNodeStruct   transpositionSubnode = ref node.Context.Tree.Store.Nodes.nodes[transpositionSubnodeIndex.Index];
                LeafEvaluationResult thisResult           = new LeafEvaluationResult(transpositionSubnode.Terminal, transpositionRootNode.WinP,
                                                                                     transpositionRootNode.LossP, transpositionRootNode.MPosition);

                // Update our result node to include this node
                result = AddResultToResults(result, numToFetch, i, thisResult);

                if (VERBOSE)
                {
                    Console.WriteLine($"ProcessAlreadyLinked {node.Index} yields {result.WinP} {result.LossP} via linked subnode root {transpositionRootNode.Index.Index} {transpositionRootNode} chose {transpositionSubnode.Index.Index}");
                }

                node.Ref.NumNodesTranspositionExtracted++;
            }