コード例 #1
0
ファイル: ClusterTree.cs プロジェクト: ivan-alles/poker-acpc
        private void ReadInternal(BinaryReader r)
        {
            Version = new BdsVersion();
            Version.Read(r);
            int serFmtVer = r.ReadInt32();

            if (serFmtVer > SERIALIZATION_FORMAT_VERSION)
            {
                throw new ApplicationException(string.Format(
                                                   "Unsupported serialization format: {0}, max supported: {1}",
                                                   serFmtVer, SERIALIZATION_FORMAT_VERSION));
            }

            if (serFmtVer == 1)
            {
                throw new ApplicationException("Serialization format version 1 is not supported");
            }

            int nodeSerFmtVer = 0;

            if (serFmtVer >= 3)
            {
                nodeSerFmtVer = r.ReadInt32();
            }

            IClusterNode       root;
            string             typeName = r.ReadString();
            ClassFactoryParams p        = new ClassFactoryParams(typeName, "");

            root = ClassFactory.CreateInstance <IClusterNode>(p);
            root.Read(r, nodeSerFmtVer);
            Root = root;
        }
コード例 #2
0
ファイル: HandStrength.cs プロジェクト: ivan-alles/poker-acpc
        static Entry[] ReadTable(string path)
        {
            Entry[] table = null;
            using (BinaryReader r = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                BdsVersion fileVersion = new BdsVersion();
                fileVersion.Read(r);
                if (Version.Major != fileVersion.Major ||
                    Version.Minor != fileVersion.Minor ||
                    Version.Revision != fileVersion.Revision)
                {
                    throw new ApplicationException(
                              String.Format("Wrong file version: expected: {0:x8}, was: {1:x8}, file: {2}",
                                            Version, fileVersion, path));
                }
                int count = r.ReadInt32();
                table = new Entry[count];

                for (int i = 0; i < count; ++i)
                {
                    table[i].key   = r.ReadUInt32();
                    table[i].value = r.ReadSingle();
                }
            }
            return(table);
        }
コード例 #3
0
        static UInt32[] ReadTable(string path)
        {
            BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly());

            UInt32 [] table = null;
            using (BinaryReader r = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                BdsVersion fileVersion = new BdsVersion();
                fileVersion.Read(r);
                if (assemblyVersion.Major != fileVersion.Major ||
                    assemblyVersion.Minor != fileVersion.Minor ||
                    assemblyVersion.Revision != fileVersion.Revision)
                {
                    throw new ApplicationException(
                              String.Format("Wrong file version: expected: {0:x8}, was: {1:x8}, file: {2}",
                                            assemblyVersion, fileVersion, path));
                }
                int count = r.ReadInt32();
                table = new UInt32[count];

                for (int i = 0; i < count; ++i)
                {
                    table[i] = r.ReadUInt32();
                }
            }
            return(table);
        }
コード例 #4
0
        /// <summary>
        /// Load precalcuation table for fast calculation.
        /// If not called by user, will be called automatically as soon as
        /// it is necessary (which may slow-down the very first calculation).
        /// </summary>
        public static void LoadLut()
        {
            string path = GetLutPath();

            BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly());

            using (BinaryReader r = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                BdsVersion fileVersion = new BdsVersion();
                fileVersion.Read(r);
                if (assemblyVersion.Major != fileVersion.Major ||
                    assemblyVersion.Minor != fileVersion.Minor ||
                    assemblyVersion.Revision != fileVersion.Revision)
                {
                    throw new ApplicationException(
                              String.Format("Wrong file version: expected: {0:x8}, was: {1:x8}, file: {2}",
                                            assemblyVersion, fileVersion, path));
                }
                int count = r.ReadInt32();
                _lut = new Precalculated[count];

                for (int i = 0; i < count; ++i)
                {
                    _lut[i].Read(r);
                }
            }
        }
コード例 #5
0
 public void Read(string fileName)
 {
     using (BinaryReader r = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read)))
     {
         Version = new BdsVersion();
         Version.Read(r);
         Data = r.ReadString();
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: ivan-alles/poker-acpc
        private static BdsVersion ProcessBinary(string fileName)
        {
            BdsVersion ver = new BdsVersion();

            using (BinaryReader r = new BinaryReader(File.Open(fileName, FileMode.Open)))
            {
                ver.Read(r);
            }
            return(ver);
        }
コード例 #7
0
ファイル: UFTree.cs プロジェクト: ivan-alles/poker-acpc
        private void ReadInternalFDA(BinaryReader r)
        {
            Version = new BdsVersion();
            Version.Read(r);
            int serFmtVer = r.ReadInt32();

            _nodesByteSize = r.ReadInt64();
            _nodesCount    = r.ReadInt64();
            _nodeByteSize  = (int)(_nodesByteSize / _nodesCount);
            _fdaReader     = r;
            _depthFilePos  = r.BaseStream.Position;
            _nodesFilePos  = _depthFilePos + _nodesCount;
            AfterRead();
        }
コード例 #8
0
ファイル: UFTree.cs プロジェクト: ivan-alles/poker-acpc
        private void ReadInternal(BinaryReader r)
        {
            Version = new BdsVersion();
            Version.Read(r);
            int serFmtVer = r.ReadInt32();

            _nodesByteSize = r.ReadInt64();
            _nodesCount    = r.ReadInt64();
            _nodeByteSize  = (int)(_nodesByteSize / _nodesCount);
            Allocate(_nodesCount, _nodeByteSize);
            UnmanagedMemory.Read(r, _depthPtr, _nodesCount);
            UnmanagedMemory.Read(r, _nodesPtr, _nodesByteSize);
            ReadUserData(r);
            AfterRead();
        }
コード例 #9
0
        public void Test_BinarySerialization()
        {
            Assembly   assembly = typeof(BdsVersion).Assembly;
            BdsVersion v1       = new BdsVersion(assembly);

            MemoryStream s = new MemoryStream();
            BinaryWriter w = new BinaryWriter(s);

            v1.Write(w);
            BdsVersion v2 = new BdsVersion();

            s.Seek(0, SeekOrigin.Begin);
            using (BinaryReader r = new BinaryReader(s))
            {
                v2.Read(r);
            }
            Assert.AreEqual(v1, v2);
        }
コード例 #10
0
        static LutEvaluator7()
        {
            string    fileName  = LutPath;
            Exception exception = null;

            try
            {
                using (FileStream file = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (BinaryReader r = new BinaryReader(file))
                    {
                        BdsVersion version = new BdsVersion();
                        version.Read(r);
                        UInt32 formatId    = r.ReadUInt32();
                        UInt32 lutSize     = r.ReadUInt32();
                        UInt32 lutByteSize = lutSize * 4;
                        _lutPtr = UnmanagedMemory.AllocHGlobalExSmartPtr(lutByteSize);
                        pLut    = (UInt32 *)_lutPtr;
                        UnmanagedMemory.Read(r, _lutPtr, lutByteSize);
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            if (exception != null)
            {
                if (_lutPtr != null)
                {
                    _lutPtr.Dispose();
                    _lutPtr = null;
                }
                pLut = (UInt32 *)IntPtr.Zero.ToPointer();

                // If IO error occured leave the class uninitialized. This is a normal case for table generation.
                // If the application tries to use an uninitialized class, an exception will be thrown somewhere.
                // Otherwise rethrow the exception.
                if (!(exception is IOException))
                {
                    throw exception;
                }
            }
        }
コード例 #11
0
        ///<summary>Create instance for file acesss.</summary>
        ///<param name="forceCreation">If true - always create a new index file, otherwise create only if no file exists.</param>
        public UFTreeChildrenIndex(UFTree ufTree, string fileName, bool forceCreation)
        {
            if (forceCreation || !File.Exists(fileName))
            {
                CreateIndex(ufTree);
                using (BinaryWriter bw = new BinaryWriter(File.Open(fileName, FileMode.Create, FileAccess.Write)))
                {
                    BdsVersion v = new BdsVersion(Assembly.GetExecutingAssembly());
                    v.Description = "UFTreeChildrenIndex for : '" + ufTree.Version.Description + "'";
                    v.Write(bw);
                    bw.Write(SERIALIZATION_FORMAT_VERSION);
                    bw.Write(ufTree.NodesCount);
                    for (long i = 0; i < _childrenBeginIdx.Length; ++i)
                    {
                        bw.Write(_childrenBeginIdx[i]);
                    }
                    for (long i = 0; i < _childrenIdx.Length; ++i)
                    {
                        bw.Write(_childrenIdx[i]);
                    }
                }
            }
            _childrenBeginIdxReader =
                new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read));
            BdsVersion v1 = new BdsVersion();

            v1.Read(_childrenBeginIdxReader);
            int serFmtVer = _childrenBeginIdxReader.ReadInt32();

            if (serFmtVer > SERIALIZATION_FORMAT_VERSION)
            {
                throw new ApplicationException(
                          string.Format("Unsupported serialization format '{0}', max supported: '{1}'", serFmtVer,
                                        SERIALIZATION_FORMAT_VERSION));
            }
            long nodesCount = _childrenBeginIdxReader.ReadInt64();

            _childrenBeginIdxFilePos = _childrenBeginIdxReader.BaseStream.Position;
            _childrenIdxFilePos      = _childrenBeginIdxFilePos + (nodesCount + 1) * 4;
            _childrenIdxReader       = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read));

            _childrenBeginIdx = _childrenIdx = null;
        }
コード例 #12
0
ファイル: CtMcGen.cs プロジェクト: ivan-alles/poker-acpc
            /// <summary>
            /// Merging read a tree from a stream.
            /// </summary>
            public void Read(BinaryReader r)
            {
                Version = new BdsVersion();
                Version.Read(r);
                int serFmtVer = r.ReadInt32();

                if (serFmtVer > SERIALIZATION_FORMAT_VERSION)
                {
                    throw new ApplicationException(
                              String.Format("Unsupported serialization format version: file format: {0}, supported: {1}",
                                            serFmtVer, SERIALIZATION_FORMAT_VERSION));
                }
                int    playersCount = r.ReadInt32();
                int    roundsCount  = r.ReadInt32();
                UInt64 samplesCount = r.ReadUInt64();
                string sourceInfo   = r.ReadString();

                if (SamplesCount == 0)
                {
                    // This is a virgin tree - copy all the data.
                    PlayersCount = playersCount;
                    RoundsCount  = roundsCount;
                    SourceInfo   = sourceInfo;
                }
                else
                {
                    if (PlayersCount != playersCount || RoundsCount != roundsCount || SourceInfo != sourceInfo)
                    {
                        throw new ApplicationException(String.Format(
                                                           "Merge target (pc: {0}, rc: {1}, si: {2}) does not match the merge source (pc: {3}, rc: {4}, si: {5})",
                                                           PlayersCount, RoundsCount, SourceInfo, playersCount, roundsCount, sourceInfo));
                    }
                }
                UInt64 sumLeavesCount = SamplesCount;

                SamplesCount += samplesCount;

                Int64 leavesCount = r.ReadInt64();
                int   cardsCount  = RoundsCount * PlayersCount;

                for (Int64 l = 0; l < leavesCount; ++l)
                {
                    byte[] cards = r.ReadBytes(cardsCount);
                    UInt32 count, result;
                    if (serFmtVer == 1)
                    {
                        UInt64 tmp = r.ReadUInt64();
                        if (tmp > UInt32.MaxValue)
                        {
                            throw new ApplicationException("Overflow");
                        }
                        count = (UInt32)tmp;
                        tmp   = r.ReadUInt64();
                        if (tmp > UInt32.MaxValue)
                        {
                            throw new ApplicationException("Overflow");
                        }
                        result = (UInt32)tmp;
                    }
                    else
                    {
                        count  = r.ReadUInt32();
                        result = r.ReadUInt32();
                    }
                    LeafT[] leaves   = GetLeavesByCards(cards);
                    int     lastCard = cards[cards.Length - 1];
                    leaves[lastCard].IncrementCount(count);
                    leaves[lastCard].IncrementResult(result);
                    sumLeavesCount += count;
                }
                VerifyTotalCount(sumLeavesCount);
            }