public static async void SimulateGames(int playerCount, int targetGameCount)
        {
            //Check if we need to build sqlite tables for the first time.
            SqliteMethods.InitDatabaseIfNeeded(playerCount);
            Console.WriteLine("Press any key to continue!");
            Console.ReadKey();
            // total games to be simulated (from user input)
            recordsTotal = targetGameCount;

            // open connection to the database
            conn = SqliteMethods.CreateConnection(playerCount);

            Timing timer = new Timing();

            timer.StartTime();

            // play with thread priorities to get optimal balance of adding and writing GameRecords
            // on your system
            Console.WriteLine("Starting producer and consumer threads...");

            // set thread priority
            producerThread.Priority = ThreadPriority.Lowest;
            consumerThread.Priority = ThreadPriority.Highest;
            producerThread.Name     = "Producer";
            consumerThread.Name     = "Consumer";
            producerThread.Start();
            consumerThread.Start();


            while (true)
            {
                // non blocking pause
                await Task.Delay(120_000).ConfigureAwait(true);

                Console.WriteLine($"Main thread {Thread.CurrentThread.Name} returning from pause");
                if (consumerThread.ThreadState == ThreadState.Stopped &
                    producerThread.ThreadState == ThreadState.Stopped)
                {
                    timer.StopTime();
                    break;
                }
            }

            Console.WriteLine($"Runtime duration: {timer.Result().TotalMinutes} minutes");
            conn.Dispose();
        }
Exemple #2
0
        internal static void AssignPostFlopPercentages(Board b)
        {
            //    wrap all players in a transaction
            //    postflop calc
            //    commit transaction
            Trace.WriteLine($"{nameof(AssignPostFlopPercentages)} method running...");
            var conn = SqliteMethods.CreateConnection(b.Players.Count);

            using (SQLiteTransaction tran = conn.BeginTransaction())
            {
                foreach (var p in b.Players)
                {
                    long holeId = Card.CardUniquePrimeDict[p.Hole[0]] * Card.CardUniquePrimeDict[p.Hole[1]];
                    long flopId = Card.CardUniquePrimeDict[b.Cards[0]] * Card.CardUniquePrimeDict[b.Cards[1]] * Card.CardUniquePrimeDict[b.Cards[2]];

                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        p.PostFlopOdds = String.Format("{0:0.0}", SqliteMethods.CalculatePostFlopPercentage(holeId, flopId, cmd));
                    }
                }
                tran.Commit();
            }
            conn.Dispose();
        }