示例#1
0
        public static MCTSNodeStore Restore(string directory, string id, bool clearSearchInProgressState = true)
        {
            // Read in miscellaneous information file
            string miscInfoFN = Path.Combine(directory, id + FN_POSTFIX_MISC_INFO);
            MCTSNodeStoreSerializeMiscInfo miscInfo = SysMisc.ReadObj <MCTSNodeStoreSerializeMiscInfo>(miscInfoFN);

            MCTSNodeStore store = new MCTSNodeStore(miscInfo.NumNodesReserved);

            store.Nodes.InsureAllocated(miscInfo.NumNodesAllocated);
            store.RootIndex = miscInfo.RootIndex;
            store.Nodes.Reset(miscInfo.PriorMoves, true);

            long numNodes = SysMisc.ReadFileIntoSpan <MCTSNodeStruct>(Path.Combine(directory, id + FN_POSTFIX_NODES), store.Nodes.Span);

            //store.Nodes.InsureAllocated((int)numNodes);
            store.Nodes.nextFreeIndex = (int)numNodes;

            store.Children.InsureAllocated((int)miscInfo.NumChildrenAllocated);
            long numChildren = SysMisc.ReadFileIntoSpan <MCTSNodeStructChild>(Path.Combine(directory, id + FN_POSTFIX_CHILDREN), store.Children.Span);

            if (numChildren > int.MaxValue)
            {
                throw new NotImplementedException("Implementation restriction: cannot read stores with number of children exceeding int.MaxValue.");
            }
            store.Children.nextFreeBlockIndex = (int)numChildren / MCTSNodeStructChildStorage.NUM_CHILDREN_PER_BLOCK;

            if (clearSearchInProgressState)
            {
                // Reset the search state fields
                MemoryBufferOS <MCTSNodeStruct> nodes = store.Nodes.nodes;
                for (int i = 1; i < store.Nodes.NumTotalNodes; i++)
                {
                    nodes[i].ResetSearchInProgressState();
                }
            }

            return(store);
        }
示例#2
0
        public static void Save(MCTSNodeStore store, string directory, string id)
        {
            if (store.Children.NumAllocatedChildren >= int.MaxValue)
            {
                throw new NotImplementedException("Implementation restriction: cannot write stores with number of children exceeding int.MaxValue.");
            }

            SysMisc.WriteSpanToFile(GetPath(directory, id, FN_POSTFIX_NODES), store.Nodes.Span.Slice(0, store.Nodes.NumTotalNodes));
            SysMisc.WriteSpanToFile(GetPath(directory, id, FN_POSTFIX_CHILDREN), store.Children.Span.Slice(0, (int)store.Children.NumAllocatedChildren));

            MCTSNodeStoreSerializeMiscInfo miscInfo = new MCTSNodeStoreSerializeMiscInfo()
            {
                Description = "",
                PriorMoves  = store.Nodes.PriorMoves,
                RootIndex   = store.RootIndex,

                NumNodesReserved     = store.MaxNodes,
                NumNodesAllocated    = store.Nodes.NumTotalNodes,
                NumChildrenAllocated = store.Children.NumAllocatedChildren
            };

            SysMisc.WriteObj(GetPath(directory, id, FN_POSTFIX_MISC_INFO), miscInfo);
        }