Beispiel #1
0
        public Evaluator(
            string fileName   = null,
            byte[] fileBytes  = null,
            bool fiveCard     = true,
            bool sixCard      = true,
            bool sevenCard    = true,
            double loadFactor = 1.25,
            bool debug        = true,
            bool runCustom    = false)
        {
            DateTime start = DateTime.UtcNow;

            this.debug = debug;

            if (sixCard && !fiveCard)
            {
                throw new ArgumentException("Six card eval requires five card eval");
            }
            if (sevenCard && !sixCard)
            {
                throw new ArgumentException("Seven card eval requires six card eval");
            }

            // Load hand rank table or create one if no filename was given
            if (fileName != null)
            {
                if (!File.Exists(fileName))
                {
                    throw new ArgumentException(string.Format("File {0} does not exist", fileName));
                }
                else
                {
                    if (debug)
                    {
                        Console.WriteLine("Loading table from {0}", fileName);
                    }
                    LoadFromFile(fileName);
                }
            }
            else if (fileBytes != null)
            {
                LoadFromTextAsset(fileBytes);
            }
            else
            {
                int minHashMapSize = (fiveCard ? 2598960 : 0) + (sixCard ? 20358520 : 0) + (sevenCard ? 133784560 : 0);
                handRankMap = new HashMap((uint)(minHashMapSize * loadFactor));
                if (fiveCard)
                {
                    if (debug)
                    {
                        Console.WriteLine("Generating new five card lookup table");
                    }
                    GenerateFiveCardTable();
                }
                if (sixCard)
                {
                    if (debug)
                    {
                        Console.WriteLine("Generating new six card lookup table");
                    }
                    GenerateSixCardTable();
                }
                if (sevenCard)
                {
                    if (debug)
                    {
                        Console.WriteLine("Generating new seven card lookup table");
                    }
                    GenerateSevenCardTable();
                }
            }

            // Run custom scripts like monte carlo generation
            if (runCustom)
            {
                Console.WriteLine("Running monte carlo simulation");
                GenerateMonteCarloMap(100000);
                Console.WriteLine("Writing table to disk");
                SaveToFile(fileName);
            }

            TimeSpan elapsed = DateTime.UtcNow - start;

            if (debug)
            {
                Console.WriteLine("Hand evaluator setup completed in {0:0.00}s", elapsed.TotalSeconds);
            }
        }
Beispiel #2
0
 public void Unload()
 {
     handRankMap = null;
     GC.Collect();
 }