public void CanDetectFormation(string source, Formation target)
    {
        var formationChecker = new FormationChecker(source);

        formationChecker.CheckFormation();
        Assert.True(formationChecker.GetFormationDescription().Formation == target);
    }
示例#2
0
    public void CanDescribeFormation(string source, string target)
    {
        var formationChecker = new FormationChecker(source);

        formationChecker.CheckFormation();
        Assert.True(formationChecker.ToString() == target);
    }
示例#3
0
    public void CanProduceAdjustableQualityOnSecondHand()
    {
        const int samplePoints = 10000;

        var hand1Score = 0.0;
        var hand2Score = 0.0;

        for (var x = 0; x < samplePoints; x++)
        {
            var deckManager = new DeckManager();
            var hands       = deckManager.PopHands(10);

            var fc1 = new FormationChecker(hands.Hand1);
            Assert.True(fc1.CheckFormation(out var score1));
            hand1Score += score1;

            var fc2 = new FormationChecker(hands.Hand2);
            Assert.True(fc2.CheckFormation(out var score2));
            hand2Score += score2;
        }

        hand1Score /= samplePoints;
        hand2Score /= samplePoints;

        Assert.True(hand1Score is > 0 and <= 100);
        Assert.True(hand2Score is > 150 and <= 250);

        hand1Score = 0.0;
        hand2Score = 0.0;

        for (var x = 0; x < samplePoints; x++)
        {
            var deckManager = new DeckManager();
            var hands       = deckManager.PopHands(100);

            var fc1 = new FormationChecker(hands.Hand1);
            Assert.True(fc1.CheckFormation(out var score1));
            hand1Score += score1;

            var fc2 = new FormationChecker(hands.Hand2);
            Assert.True(fc2.CheckFormation(out var score2));
            hand2Score += score2;
        }

        hand1Score /= samplePoints;
        hand2Score /= samplePoints;

        Assert.True(hand1Score is > 0 and <= 100);
        Assert.True(hand2Score is > 350 and <= 450);
    }
示例#4
0
    /// <summary>
    ///     For a cheating computer player in a poker game, creates a used deck with enough cards left for one player to make one swap.
    /// </summary>
    /// <param name="secondHandQuality">Cheat level.</param>
    /// <returns></returns>
    public HandPair PopHands(int secondHandQuality)
    {
        var deckCount   = secondHandQuality > 0 ? secondHandQuality / 8 : 0;
        var redealCount = secondHandQuality % 8;
        var structures  = new List <NewDeckStructure>();

        for (var i = 0; i < deckCount + 1; i++)
        {
            var structure = new NewDeckStructure
            {
                Deck = new Deck()
            };

            var d = structure.Deck;
            structure.Deck.Shuffle();
            structure.Hand1 = $"{d.PopString()},{d.PopString()},{d.PopString()},{d.PopString()},{d.PopString()}";
            var redeals = i < deckCount ? 8 : redealCount + 1;
            for (var j = 0; j < redeals; j++)
            {
                var hand2 = $"{d.PopString()},{d.PopString()},{d.PopString()},{d.PopString()},{d.PopString()}";

                var fc = new FormationChecker(hand2);

                fc.CheckFormation();

                var hand2Score = fc.Score;

                structure.Hands2.Add(
                    new HandScorePair(hand2, hand2Score)
                    );
            }
            structures.Add(structure);
        }

        structures.Sort(
            (a, b) => a.HighestDeck2Score > b.HighestDeck2Score
                ? 1
                : a.HighestDeck2Score < b.HighestDeck2Score ? -1 : 0
            );

        Deck = structures.Last().Deck;

        return(new HandPair(
                   structures.Last().Hand1 ?? "",
                   structures.Last().HighestHand2()
                   ));
    }
示例#5
0
        } // method ParseHandForChecking

        public void ShowDown()
        {
            WriteLine("Showdown time!");

            string           playerMappedHand = ParseHandForChecking(Gambler);
            string           dealerMappedHand = ParseHandForChecking(Dealer);
            FormationChecker playerChecker    = new FormationChecker(playerMappedHand);

            playerChecker.CheckFormation();
            FormationChecker dealerChecker = new FormationChecker(dealerMappedHand);

            dealerChecker.CheckFormation();

            string playerHand      = $"{Gambler.ShowHand()}\n{Table.ShowHand()}";
            string dealerHand      = $"{Dealer.ShowHand()}\n{Table.ShowHand()}";
            string playerFormation = playerChecker.GetFormationDescription().Formation.ToString();
            string dealerFormation = dealerChecker.GetFormationDescription().Formation.ToString();

            WriteLine($"{Gambler.Name} has:\n{playerHand}\nFormation: {playerFormation}");
            WriteLine($"{Dealer.Name} has:\n{dealerHand}\nFormation: {dealerFormation}");

            int    playerScore = playerChecker.GetFormationDescription().Score;
            int    dealerScore = dealerChecker.GetFormationDescription().Score;
            Player winner;
            string winningFormation;

            if (dealerScore >= playerScore)
            {
                winner           = Dealer;
                winningFormation = dealerFormation;
            }
            else
            {
                winner           = Gambler;
                winningFormation = playerFormation;
            } // if (dealerScore >= playerScore)

            WriteLine($"{winner.Name} wins this hand with {winningFormation}!");
            GivePotToWinner(ref winner);
            ResetHands();
        } // method ShowDown