/// <summary> /// Saves the generated states as a look-up table. /// Format: /// BdsVersion. /// UInt32 format ID. /// UInt32 LUT size (number of UInt32 entries). /// UInt32 [] LUT. /// </summary> public void SaveLut(string path, UInt32 formatId) { string dirName = Path.GetDirectoryName(path); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } using (BinaryWriter w = new BinaryWriter(File.Open(path, FileMode.Create, FileAccess.Write))) { BdsVersion version = new BdsVersion(Assembly.GetExecutingAssembly()); version.Write(w); w.Write(formatId); w.Write((UInt32)_states.Count * 52); for (int s = 0; s < _states.Count; ++s) { for (int i = 0; i < 52; ++i) { UInt32 value = (UInt32)_states[s].Table[i]; if (_states[s].Key.HandSize < _maxHandSize - 1) { value *= 52; } w.Write(value); } } } }
static void WriteTable(UInt32[] table, string path) { BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly()); BdsVersion fileVersion = new BdsVersion(); fileVersion.Major = assemblyVersion.Major; fileVersion.Minor = assemblyVersion.Minor; fileVersion.Revision = assemblyVersion.Revision; fileVersion.ScmInfo = assemblyVersion.ScmInfo; string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (BinaryWriter wr = new BinaryWriter(File.Open(path, FileMode.Create))) { fileVersion.Write(wr); wr.Write(table.Length); for (int i = 0; i < table.Length; ++i) { wr.Write(table[i]); } } }
public static void Precalculate() { DateTime startTime = DateTime.Now; string lutPath = GetLutPath(); if (File.Exists(lutPath)) { // Do not ovewriting an existing file to save time. Console.WriteLine("LUT file {0} already exist, exiting. Delete the file to recalculate.", lutPath); return; } Precalculated[] precalcArray = new Precalculated[HePocket.Count * (HePocket.Count + 1) / 2]; int i = 0; Console.WriteLine("Calculating for"); for (int pk1 = 0; pk1 < HePocket.Count; pk1++) { Console.Write(" {0}", (HePocketKind)pk1); for (int pk2 = pk1; pk2 < HePocket.Count; pk2++) { Result r = Calculate((HePocketKind)pk1, (HePocketKind)pk2); precalcArray[i].PocketKind1 = (byte)pk1; precalcArray[i].PocketKind2 = (byte)pk2; precalcArray[i].Count = (byte)r.Count; precalcArray[i].Equity = r.Equity; ++i; } } Console.WriteLine(); BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly()); BdsVersion fileVersion = new BdsVersion(); fileVersion.Major = assemblyVersion.Major; fileVersion.Minor = assemblyVersion.Minor; fileVersion.Revision = assemblyVersion.Revision; fileVersion.ScmInfo = assemblyVersion.ScmInfo; fileVersion.Description = "HE heads-up pocket equity LUT."; string dir = Path.GetDirectoryName(lutPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (BinaryWriter wr = new BinaryWriter(File.Open(lutPath, FileMode.Create))) { fileVersion.Write(wr); wr.Write(precalcArray.Length); for (i = 0; i < precalcArray.Length; ++i) { precalcArray[i].Write(wr); } } Console.WriteLine("Calculated in {0} s", (DateTime.Now - startTime).TotalSeconds); }
public void Write(string fileName) { using (BinaryWriter w = new BinaryWriter(File.Open(fileName, FileMode.Create, FileAccess.Write))) { Version.Write(w); w.Write(Data); } }
static void WriteTable(List <Entry> table, string path) { BdsVersion fileVersion = new BdsVersion(Version); BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly()); fileVersion.ScmInfo = assemblyVersion.ScmInfo; using (BinaryWriter wr = new BinaryWriter(File.Open(path, FileMode.Create))) { fileVersion.Write(wr); wr.Write(table.Count); for (int i = 0; i < table.Count; ++i) { wr.Write(table[i].key); wr.Write(table[i].value); } } }
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); }
///<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; }
static void WriteTable <T>(List <T> table, string path) where T : IPersistent { BdsVersion fileVersion = new BdsVersion(Version); BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly()); fileVersion.ScmInfo = assemblyVersion.ScmInfo; string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (BinaryWriter wr = new BinaryWriter(File.Open(path, FileMode.Create))) { fileVersion.Write(wr); wr.Write(table.Count); for (int i = 0; i < table.Count; ++i) { table[i].Write(wr); } } }