public void CalculatePokerOdds_WHERE_no_cards_in_hand_or_board_with_zero_opponents_SHOULD_calculate_hand_odds_accurately()
        {
            //arrange
            var myHand    = new Hand(new List <Card>());
            var boardHand = new Hand(new List <Card>());

            //act
            var actual = _instance.CalculatePokerOdds(_deck, myHand, boardHand, 0, 100000);

            //assert
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.RoyalFlush].Error, Is.LessThanOrEqualTo(0.00004));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.RoyalFlush].Percentage, Is.EqualTo(0.000032).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.RoyalFlush].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.StraightFlush].Error, Is.LessThanOrEqualTo(0.00015));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.StraightFlush].Percentage, Is.EqualTo(0.000279).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.StraightFlush].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.FourOfAKind].Error, Is.LessThanOrEqualTo(0.0005));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.FourOfAKind].Percentage, Is.EqualTo(0.00168).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.FourOfAKind].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.FullHouse].Error, Is.LessThanOrEqualTo(0.002));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.FullHouse].Percentage, Is.EqualTo(0.026).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.FullHouse].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.Flush].Error, Is.LessThanOrEqualTo(0.002));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.Flush].Percentage, Is.EqualTo(0.0303).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.Flush].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.Straight].Error, Is.LessThanOrEqualTo(0.002));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.Straight].Percentage, Is.EqualTo(0.0462).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.Straight].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.ThreeOfAKind].Error, Is.LessThanOrEqualTo(0.003));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.ThreeOfAKind].Percentage, Is.EqualTo(0.0483).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.ThreeOfAKind].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.TwoPair].Error, Is.LessThanOrEqualTo(0.005));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.TwoPair].Percentage, Is.EqualTo(0.235).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.TwoPair].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.Pair].Error, Is.LessThanOrEqualTo(0.005));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.Pair].Percentage, Is.EqualTo(0.438).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.Pair].Error));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.HighCard].Error, Is.LessThanOrEqualTo(0.005));
            Assert.That(actual.PokerHandPercentagesWithErrors[PokerHand.HighCard].Percentage, Is.EqualTo(0.174).Within(2 * actual.PokerHandPercentagesWithErrors[PokerHand.HighCard].Error));
        }
        public void PokerCalculator_WITH_empty_hands_2_opponents_and_100000_iterations()
        {
            //arrange
            const int numIterations = 100000;

            var deck = new Deck();

            var myHand    = new Hand(new List <Card>());
            var boardHand = new Hand(new List <Card>());

            //act
            var stopwatch = Stopwatch.StartNew();

            _instance.CalculatePokerOdds(deck, myHand, boardHand, 2, numIterations);

            DisplaySpeedResults(stopwatch.ElapsedTicks / (double)numIterations, 1);
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine("Welcome to the PokerCalculator.");

            while (true)
            {
                var deck = new Deck();
                Console.WriteLine("Please enter your cards (press enter for no cards):");
                var playersHand = ReadHand(deck);
                Console.WriteLine("Please enter the board's cards (press enter for no cards):");
                var boardHand = ReadHand(deck);

                var numOpponents = ReadNumberOfOpponents();

                Console.Clear();
                Console.WriteLine($"Your hand: {string.Join(" ", playersHand.Cards.Select(x => $"{x.Value}{x.Suit}"))}");
                Console.WriteLine($"Board hand: {string.Join(" ", boardHand.Cards.Select(x => $"{x.Value}{x.Suit}"))}");
                Console.WriteLine($"{numOpponents} opponents...");

                var stopwatch = Stopwatch.StartNew();
                var pokerOdds = _pokerCalculator.CalculatePokerOdds(deck, playersHand, boardHand, numOpponents, _appSettings.NumIterations);

                DisplayPokerOdds(pokerOdds, stopwatch);

                Console.WriteLine();
                Console.WriteLine("Press any key to continue, 'X' to quit.");
                var input = Console.ReadKey();
                if (input.Key == ConsoleKey.X)
                {
                    break;
                }

                Console.Clear();
            }

            return(Task.CompletedTask);
        }