Beispiel #1
0
 public Node(bool containsLeaves, int initialCapacity)
 {
     if (containsLeaves)
     {
         _data = new LeafT[initialCapacity];
     }
     else
     {
         _data = new Node[initialCapacity];
     }
 }
Beispiel #2
0
            private void WriteInternal(BinaryWriter w)
            {
                // Write version first to allow standard tools work.
                Version.Write(w);
                w.Write(SERIALIZATION_FORMAT_VERSION);
                w.Write(PlayersCount);
                w.Write(RoundsCount);
                w.Write(SamplesCount);
                w.Write(SourceInfo);
                Int64 leavesCount = CalculateLeavesCount();

                w.Write(leavesCount);

                UInt64 sumLeavesCount = 0;

                var wt = new WalkTreePP <Node, object, int, WriteInternalContext>();

                wt.OnNodeEnd =
                    (Node tree, object node, List <WriteInternalContext> stack, int depth) =>
                {
                    int maxDepth = PlayersCount * RoundsCount;
                    if (depth < maxDepth)
                    {
                        return;
                    }
                    byte[] cards = new byte[PlayersCount * RoundsCount];
                    for (int d = 0; d < cards.Length; ++d)
                    {
                        cards[d] = (byte)(stack[d].ChildrenIterator - 1);
                    }
                    LeafT leaf = (stack[depth - 1].Node as Node).Leaves[cards[depth - 1]];
                    w.Write(cards);
                    w.Write(leaf.Count);
                    w.Write(leaf.Result);
                    sumLeavesCount += leaf.Count;
                };

                wt.Walk(Root, Root);
                VerifyTotalCount(sumLeavesCount);
                UpdateDescription();
            }
Beispiel #3
0
            bool SyncNodes(Node uniTree, object uniNode, byte uniDepth, int uniIt, UFTree ufTree, Int64 ufNode, object userData)
            {
                ChanceTree ct = (ChanceTree)ufTree;

                ct.SetDepth(ufNode, uniDepth);
                ct.Nodes[ufNode].Card     = uniDepth == 0 ? 0 : uniIt - 1;
                ct.Nodes[ufNode].Position = (uniDepth - 1) % PlayersCount;
                if (uniNode is LeafT)
                {
                    // This is a leaf
                    LeafT leaf = (LeafT)uniNode;

                    ct.Nodes[ufNode].Probab = (double)leaf.Count / SamplesCount;
                    double [] potShares = new double[2];
                    potShares[0] = 0.5 * leaf.Result / leaf.Count;
                    potShares[1] = 1 - potShares[0];
                    ct.Nodes[ufNode].SetPotShare(0x11, potShares);
                }
                else
                {
                    ct.Nodes[ufNode].Probab = 0;
                }
                return(true);
            }