Пример #1
0
        public void PlayHand_Deal_DealerHasOneVisibleCard()
        {
            // Arrange
            var cards = new List <Card>()
            {
                new Card(CardSuit.Clubs, 4, CardType.Number),
                new Card(CardSuit.Clubs, 5, CardType.Number),
                new Card(CardSuit.Clubs, 6, CardType.Number)
            };
            var dealer = new Dealer();
            var table  = new Table(dealer)
            {
                Dealer = dealer
            };
            var playHand = new PlayHand();

            playHand.Init(cards, table);


            // Act
            playHand.Deal();

            // Assert
            Assert.Single(dealer.Hand.Cards.Where(a => a.Visible));
        }
Пример #2
0
        static void TestAttackDefendPlayMethod()
        {
            Deck d = new Deck();

            d.Shuffle();
            Card c2 = d.DetermineTrump();

            //just for testing display trump card
            Console.WriteLine("The trump card is: " + d.DisplayTrumpCard());
            FoolHand fh = new FoolHand();
            PlayHand ph = new PlayHand();

            fh.DrawUpToSixCards(fh, d);

            Console.WriteLine("Current Fool Hand.  Expecting 6 cards.\n" + fh);
            //Card c = fh.Attack(1);
            Console.WriteLine("Test AttackDefendPlay method");
            //Console.WriteLine("Attacking with a card at index '0'.\n" + c);
            //Card c3 = fh.Defend(fh, c, c2);
            //Console.WriteLine("Defending with a card from the deck.\n" + c3);
            Console.WriteLine("Current Fool Hand.  Expecting 4 cards left in a hand:\n" + fh);
            //ph.AddCardToPlayHand(ph, fh, c);
            //ph.AddCardToPlayHand(ph, fh, c3);
            Console.WriteLine("Current Play Hand.  Expecting 2 cards in a hand:\n" + ph);
            Console.WriteLine("Number of cards in the PlayHand.  Expecting 2 cards:\n" + ph.NumCards);
        }
Пример #3
0
        public void PlaySingleHand_1Player_PlayerDraws_Bust()
        {
            // Arrange
            var dealer   = new Dealer();
            var table    = new Table(dealer);
            var shoe     = new Shoe(4);
            var playHand = new PlayHand();

            playHand.Init(shoe.Cards, table);

            var blackJackStrategy = new BlackJackStrategy()
            {
                StrategyItems = new List <BlackJackStrategyItem>()
                {
                    new BlackJackStrategyItem()
                    {
                        DealerCard           = new Card(CardSuit.Spades, 3, CardType.Number),
                        PlayerTotalCardValue = 6,
                        Action = PlayerAction.TakeCard
                    },
                    new BlackJackStrategyItem()
                    {
                        DealerCard           = new Card(CardSuit.Spades, 3, CardType.Number),
                        PlayerTotalCardValue = 12,
                        Action = PlayerAction.TakeCard
                    },
                    new BlackJackStrategyItem()
                    {
                        DealerCard           = new Card(CardSuit.Spades, 3, CardType.Number),
                        PlayerTotalCardValue = 19,
                        Action = PlayerAction.TakeCard
                    }
                }
            };

            var player = new Player()
            {
                Money    = 100,
                Strategy = blackJackStrategy
            };

            // Act
            table.SitPlayer(player);
            playHand.PlayerAnte(player, 10);
            playHand.Deal();

            while (playHand.GameInProgress)
            {
                playHand.Play();
            }

            playHand.Payout();

            // Assert
            Assert.Equal(90, player.Money);
            Assert.True(player.Hand.Cards.AddUp() > 21);
        }
Пример #4
0
        /// <summary>
        /// Handles the all the action required when it is a computer player's turn.
        /// </summary>
        /// <param name="aDeck"></param>
        /// <param name="dumpCards"></param>
        /// <param name="dumpPic"></param>
        public void Turn(Deck aDeck, List <Card> dumpCards, Panel panelDump)
        {
            Card drawnCard = aDeck.DrawOneCard();

            PlayHand.AddCard(drawnCard);

            //Gets and display SameKind Combo
            List <Card> comboCards = PlayHand.GetSameKindCards();

            DisplayInPanelComboCards(comboCards);

            //Gets and display Straight Combo
            comboCards = PlayHand.GetStraightCards();
            DisplayInPanelComboCards(comboCards);
        }
Пример #5
0
        static void TestPickPlayHandCards()
        {
            Deck     d  = new Deck();
            FoolHand fh = new FoolHand();
            PlayHand ph = new PlayHand();

            fh.DrawUpToSixCards(fh, d);
            ph.AddCard(new Card(13, 1));
            ph.AddCard(new Card(13, 2));
            ph.AddCard(new Card(13, 3));

            Console.WriteLine("Current Fool Hand.  Expecting 6 cards.\n" + fh);
            Console.WriteLine("Current Play Hand.  Expecting 3 Kings.\n" + ph);
            fh.PickPlayHandCards(fh, ph);
            Console.WriteLine("Test PickPlayHandCards method");
            Console.WriteLine("Execting 9 cards in Fool Hand:\n" + fh + "\nand '0' cards in Play Hand:\n" + ph.NumCards);
        }
Пример #6
0
        static void TestCanDefendMethod()
        {
            Deck d = new Deck();

            d.Shuffle();
            Card c2 = d.DetermineTrump();

            //just for testing display trump card
            Console.WriteLine("The trump card is: " + d.DisplayTrumpCard());
            FoolHand fh = new FoolHand();
            PlayHand ph = new PlayHand();

            fh.DrawUpToSixCards(fh, d);

            Console.WriteLine("Current Fool Hand.  Expecting 6 cards.\n" + fh);

            Card c = fh.Attack(1, fh, ph);

            Console.WriteLine("Test AttackDefendPlay method");
            Console.WriteLine("Attacking with a card at index '0'.\n" + c);

            Card c3 = fh.Defend(fh, c, c2);

            Console.WriteLine("Defending with a card from the deck.\n" + c3);
            Console.WriteLine("Current Fool Hand.  Expecting 4 cards left in a hand:\n" + fh);

            bool canDefend = fh.CanDefend(fh, c, c2);

            Console.WriteLine("Checking if a player can defend.\n" + canDefend);
            Console.WriteLine("Current Fool Hand.  Expecting 4 cards left in a hand:\n" + fh);

            ph.AddCardToPlayHand(ph, fh, c);
            ph.AddCardToPlayHand(ph, fh, c3);
            Console.WriteLine("Current Play Hand.  Expecting 2 cards in a hand:\n" + ph);
            Console.WriteLine("Number of cards in the PlayHand.  Expecting 2 cards:\n" + ph.NumCards);

            DiscardHand dh = new DiscardHand();

            Console.WriteLine("Number of cards in the DiscardHand.  Expecting 2 cards:\n" + dh.AddToDiscardPile(dh, ph));
            ph.DiscardAll();
            Console.WriteLine("Number of cards in the PlayHand.  Expecting 0 cards after DiscardAll():\n" + ph.NumCards);
            dh.DiscardAll();
            Console.WriteLine("Number of cards in the DiscardHand.  Expecting 0 cards after DiscardAll():\n" + dh.NumCards);
        }
Пример #7
0
        static void TestCanAttackAgainMethod()
        {
            Deck d = new Deck();

            d.Shuffle();

            FoolHand fh = new FoolHand();
            CompHand ch = new CompHand();
            PlayHand ph = new PlayHand();

            Card tc = d.DetermineTrump();

            ch.DrawUpToSixCards(ch, d);
            ch.CompSortCards(ch, tc);
            fh.DrawUpToSixCards(fh, d);
            fh.SortCards(fh, tc);

            Card lastCard = d.GetCard(d.NumCards - 1);

            Console.WriteLine("Test CanAttackAgain method");
            Console.WriteLine("Determining a trump card.  The trump card (Suit) is: " + tc);
            Console.WriteLine("Last card in the deck - should be the same as the trump card: " + lastCard);
            Console.WriteLine("Current FoolHand.  Expecting 6 cards.\n" + fh);
            Console.WriteLine("Current CompHand.  Expecting 6 cards.\n" + ch);
            Card attkCard = ch.Attack(0, ch, ph);

            Console.WriteLine("Computer attacking a player with: " + attkCard);
            ph.AddCardToPlayHand(ph, fh, attkCard);

            Card defCard = fh.Defend(fh, attkCard, tc);

            Console.WriteLine("Player is defending with the following card: " + defCard);
            ph.AddCardToPlayHand(ph, fh, defCard);

            Console.WriteLine("Current FoolHand.  Expecting 5 cards.\n" + fh);
            Console.WriteLine("Current CompHand.  Expecting 5 cards.\n" + ch);

            Console.WriteLine("Current PlayHand:\n" + ph);
            Console.WriteLine("Checking if compuetr can attack again: " + ch.CanAttackAgain(ch, ph));
        }
Пример #8
0
        public void PlayHand_Deal_GameInProgress()
        {
            // Arrange
            var cards = new List <Card>()
            {
                new Card(CardSuit.Clubs, 4, CardType.Number),
                new Card(CardSuit.Clubs, 5, CardType.Number)
            };
            var dealer = new Dealer();
            var table  = new Table(dealer)
            {
                Dealer = dealer
            };
            var playHand = new PlayHand();

            playHand.Init(cards, table);

            // Act
            playHand.Deal();

            // Assert
            Assert.True(playHand.GameInProgress);
        }
        public async Task RunAnalysis_Steady_ReturnsRemainingPot(BettingStrategy bettingStrategy)
        {
            // Arrange
            var logger                = Substitute.For <ILogger <RunAnalysis> >();
            var playHand              = new PlayHand();
            var runAnalysis           = new RunAnalysis(logger, playHand);
            var analysisConfiguration = new AnalysisConfiguration()
            {
                StartingAnte     = 1,
                BettingStrategy  = bettingStrategy,
                DeckCountPerShoe = 4,
                PlayerFunds      = 10,
                TargetFunds      = 11,
                AvailableActions = TestHelper.BuildAvailableActionsAlwaysStand()
            };

            var updateProgress = Substitute.For <IUpdateProgress>();

            // Act
            decimal result = await runAnalysis.Run(analysisConfiguration, updateProgress);

            // Assert
            Assert.True(result <= analysisConfiguration.TargetFunds + 1);
        }
Пример #10
0
 //JUST FOR TESTING
 static void TestMessagesMethod(PlayHand ph, FoolHand fh, CompHand ch)
 {
     Console.WriteLine("Current PlayHand:\n" + ph);              //just for testing
     Console.WriteLine("Player's hand is as follows:\n" + fh);   //just for testing
     Console.WriteLine("Computer's hand is as follows:\n" + ch); //just for testing
 }
Пример #11
0
        static void Main(string[] args)
        {
            const string YOU_LOSE = "You lost :(."; //Message displayed at the end of the game when someone loses
            Deck         deck     = new Deck();     //New deck instance

            deck.Shuffle();

            Card trumpCard = deck.DetermineTrump(); //Determining and displaying a trump (trump suit) card and placing it at the bottom of the deck

            Console.WriteLine("Determine a trump card.  The trump is: " + trumpCard);

            FoolHand player   = new FoolHand();
            CompHand computer = new CompHand();
            PlayHand playHand = new PlayHand();

            deck.DealCards(player, computer); //Dealing 6 cards to each player in an alternating pattern

            do
            {
                player.SortCards(player, trumpCard); //sorting cards
                Console.WriteLine("Player's hand is as follows:\n" + player);

                computer.CompSortCards(computer, trumpCard);
                Console.WriteLine("\nComputers's hand is as follows:\n" + computer);

                bool playerTurn = true; //starting the game with the human player


                //PLAYER'S TURN
                do
                {
                    int  cardIndex = -1;
                    bool canAttack = true;

                    Console.WriteLine("\nPlease enter the Card number you would like to attack with or enter 'n' to end your turn: ");
                    string input = Console.ReadLine();
                    //cardIndex = InputValidation(input, player);
                    if (input == "n")
                    {
                        playerTurn = false;
                        canAttack  = false;
                    }
                    else
                    {
                        cardIndex = InputValidation(input, player); //^^^^SOMETHING IS OFF IN THE LINES ABOVE ^^^^^
                    }
                    //if (cardIndex == player.NumCards + 1) //entering 1 more than the total number in a hand terminates player's turn
                    //    playerTurn = false;

                    Card attckCard = player.Attack(cardIndex, player);



                    while (canAttack) // playHand is empty - needs more checking     ***|| playHand.IsEmpty || !player.IsEmpty***
                    {
                        if (playHand.Contains(attckCard))
                        {
                            Console.WriteLine("If you attack more than once, please make sure you attack with a card which value macthes any of the ones that are currently in play.");
                            canAttack  = false;
                            playerTurn = false;
                        }
                        else
                        {
                            Console.WriteLine("Player's card to attack with is: " + attckCard);
                            playHand.AddCardToPlayHand(playHand, computer, attckCard);
                            Thread.Sleep(2000);
                            //check if computer can defend
                            Card defCard = computer.CompDefend(computer, attckCard, trumpCard);
                            Console.WriteLine("Computer's card to defend with is: " + defCard);

                            if (defCard != null)
                            {
                                playHand.AddCard(defCard);

                                TestMessagesMethod(playHand, player, computer); //TEST

                                Console.WriteLine("\nPlease enter the Card number you would like to attack with or enter 'n' to end your turn: ");
                                input = Console.ReadLine();
                                //cardIndex = InputValidation(input, player);
                                if (input == "n")
                                {
                                    playerTurn = false;
                                }
                                else
                                {
                                    cardIndex = InputValidation(input, player);
                                }


                                //if (cardIndex == player.NumCards + 1) //entering 1 more than the total number in a hand terminates player's turn
                                //    playerTurn = false;

                                canAttack = player.CanAttackAgain(cardIndex, player, playHand); //PROBLEM SOMEWHERE HERE

                                if (canAttack)
                                {
                                    attckCard = player.AttackWithCard(player, cardIndex);
                                }
                                TestMessagesMethod(playHand, player, computer); //TEST
                            }
                            else if (!computer.CanDefend(computer, attckCard, trumpCard))
                            {
                                computer.PickUpCards(computer, playHand);
                                playHand.DiscardAll();
                                player.DrawUpToSixCards(player, deck, trumpCard);
                                player.SortCards(player);
                                computer.CompSortCards(computer, trumpCard);
                                //Console.WriteLine("Player's current hand is:\n" + player);
                                TestMessagesMethod(playHand, player, computer); //TEST

                                Console.WriteLine("\nPlease enter the Card number you would like to attack with: ");
                                input     = Console.ReadLine();
                                cardIndex = InputValidation(input, player);


                                if (cardIndex == player.NumCards + 1) //entering 1 more than the total number in a hand terminates player's turn
                                {
                                    playerTurn = false;
                                }

                                canAttack = player.CanAttackAgain(cardIndex, player, playHand); //PROBLEM SOMEWHERE HERE

                                if (canAttack)
                                {
                                    attckCard = player.AttackWithCard(player, cardIndex);
                                }
                            }
                        }
                    }

                    string doneWithTurn = EndTurn();

                    if (doneWithTurn == "y" && playHand.NumCards % 2 == 0)
                    {
                        playHand.DiscardAll();
                        playerTurn = false;
                    }
                    else if (doneWithTurn == "y" && playHand.NumCards % 2 != 0)
                    {
                        computer.PickPlayHandCards(computer, playHand);
                        Console.WriteLine("Computer picked up because it could not defend the attack.  Computer's hand is currently:\n" + computer);
                        computer.CompSortCards(computer, trumpCard);
                        player.DrawUpToSixCards(player, deck, trumpCard);
                        Console.WriteLine("Player's hand is as follows:\n" + player); //just for testing
                    }

                    Console.WriteLine("Current PlayHand:\n" + playHand.NumCards);
                } while (playerTurn);

                EndOfTurnMaintenance(deck, trumpCard, player, computer);
                TestMessagesMethod(playHand, player, computer); //TEST

                //COMPUTER'S TURN
                do
                {
                    bool canAttack      = true;
                    bool canAttackAgain = false;

                    Console.WriteLine("\nNow, it's computer's turn to attack.");
                    Card compAttack = new Card();

                    while (canAttack) // playHand is empty - needs more checking   || playHand.IsEmpty || !computer.IsEmpty
                    {
                        if (playHand.IsEmpty)
                        {
                            compAttack = computer.Attack(0, computer);
                            playHand.AddCard(compAttack);
                        }
                        else if (canAttackAgain || (canAttack && !playHand.IsEmpty))
                        {
                            compAttack = computer.AttackAgain(computer, playHand);
                            playHand.AddCard(compAttack);
                        }

                        Console.WriteLine("Computer attacks with: " + compAttack);

                        bool canDefend = false; //bool that gets assigned based on whether or not player can defend

                        Console.WriteLine("\nPlease enter the Card number you would like to defend with, or press 'p' to pick up the card(s): ");
                        string input = Console.ReadLine();

                        if (input == "p")
                        {
                            player.PickPlayHandCards(player, playHand);
                            computer.OffLoadAttackCards(compAttack, computer, playHand);
                            player.PickPlayHandCards(player, playHand);
                            computer.DrawUpToSixCards(computer, deck, trumpCard);
                            computer.CompSortCards(computer, trumpCard);
                            player.SortCards(player);
                            canAttack = true;
                            TestMessagesMethod(playHand, player, computer); //TEST
                        }
                        else
                        {
                            int cardIndex = InputValidation(input, player);

                            Card defCard = player.GetCard(cardIndex);
                            canDefend = player.CanDefendWithSpecificCard(compAttack, defCard, trumpCard);

                            Console.WriteLine("Checking if a player can defend (true/false): " + canDefend);
                            Console.WriteLine("Player is defending with: " + defCard);


                            if (canDefend)
                            {
                                player.DefendWithCard(defCard, player);
                                playHand.AddCard(defCard);
                                canAttackAgain = computer.CanAttackAgain(computer, playHand);
                                canAttack      = computer.CanAttackAgain(computer, playHand);
                                TestMessagesMethod(playHand, player, computer); //TEST
                            }
                            else
                            {
                                Console.WriteLine("You cannot defend with this card.");
                                //player.PickUpCards(player, playHand);
                                //player.SortCards(player);
                                //computer.DrawUpToSixCards(computer, deck, trumpCard);
                                //computer.CompSortCards(computer, trumpCard);

                                computer.OffLoadAttackCards(compAttack, computer, playHand);
                                player.PickPlayHandCards(player, playHand);
                                computer.DrawUpToSixCards(computer, deck, trumpCard);
                                computer.CompSortCards(computer, trumpCard);
                                player.SortCards(player);
                                canAttack = true;
                            }
                        }
                    }

                    playHand.DiscardAll();

                    //TestMessagesMethod(playHand, player, computer); //TEST

                    playerTurn = true;
                } while (!playerTurn);

                EndOfTurnMaintenance(deck, trumpCard, player, computer);
            } while (!deck.IsEmpty);

            //CHECK FOR LOSER
        }