Example #1
0
        public void TestBlackjackIsRaisedWhenHandIsBlackjack()
        {
            bool blackjackCalled = false;
            Hand hand = new Hand();
            hand.Blackjack += () => blackjackCalled = true;

            hand.Add(new Card(Rank.Jack, Suit.Diamonds));
            hand.Add(new Card(Rank.Ace, Suit.Diamonds));

            Assert.IsTrue(blackjackCalled);
        }
Example #2
0
        public void TestBustRaisesHandBustEvent()
        {
            bool bustedCalled = false;
            Hand hand = new Hand();
            hand.Busted += () => bustedCalled = true;

            hand.Add(new Card(Rank.Ten, Suit.Diamonds));
            hand.Add(new Card(Rank.Ten, Suit.Diamonds));

            Assert.IsFalse(bustedCalled);
            hand.Add(new Card(Rank.Ten, Suit.Diamonds));
            Assert.IsTrue(bustedCalled);
        }
Example #3
0
 public void AddTest()
 {
     Hand a = new Hand();
     Card c = Card.Joker;
     a.Add(c);
     Assert.AreEqual(a[0], c);
 }
        public void Test_CheckThreeKindHand_ShouldPass()
        {
            var card1 = new SimpleCard(CardType.Ace, Suit.Clubs);
            var card2 = new SimpleCard(CardType.Ace, Suit.Diamonds);
            var card3 = new SimpleCard(CardType.Ace, Suit.Hearts);
            var card4 = new SimpleCard(CardType.Eight, Suit.Spades);
            var card5 = new SimpleCard(CardType.Nine, Suit.Diamonds);
            var hand = new Hand();
            hand.Add(card1);
            hand.Add(card2);
            hand.Add(card3);
            hand.Add(card4);
            hand.Add(card5);
            var sortedHand = hand.Sort();
            var firstHand = new HandEvaluator(sortedHand);
            var result = firstHand.EvaluateHand();

            Assert.AreEqual(HandStrength.ThreeKind, result);
        }
Example #5
0
        private void btnHandValue_Click(object sender, EventArgs e)
        {
            int index = lbMain.SelectedIndex;
            AIPlayer currentPlayer = (AIPlayer)pokerTable[index];
            Stopwatch timer = new Stopwatch();
            timer.Start();
            Hand hand = new Hand();
            hand.Add(new Card(RANK.TWO, SUIT.SPADES));
            hand.Add(new Card(RANK.FOUR, SUIT.DIAMONDS));
            currentPlayer.CalculateHandValue(playerAmount);
            timer.Stop();
            pokerTable[index] = currentPlayer;
            rtbOutput.Text = currentPlayer.HandValue.ToString() + Environment.NewLine + timer.Elapsed.TotalMilliseconds;

            lbMain.Items.Clear();
            foreach (Player player in pokerTable)
            {
                lbMain.Items.Add(player.Name);
            }
            lbMain.SelectedIndex = index;
        }
Example #6
0
 public void Discard_CardInHand_CardOnBottomOfLibrary()
 {
     bool cardDiscardedEventTriggered = false;
     GameLibrary lib = new GameLibrary();
     SelectableLinkedList<GameCard> cards = new SelectableLinkedList<GameCard>();
     for (int i = 0; i < 29; i++)
         cards.AddFirst(new MockCard());
     lib.Add(cards);
     Hand h = new Hand();
     cards = new SelectableLinkedList<GameCard>();
     cards.AddFirst(new MockCardWithData(42));
     h.Add(cards);
     Player p = new Player(lib, h, null,null);
     p.EventManager = this.EventManager;
     this.EventManager.Register(new Trigger<CardDiscardedEvent>(_ => cardDiscardedEventTriggered = true));
     Engine.AddActor(lib);
     p.Discard(0);
     GameCard c = p.Library.TakeCardAt(29);
     Assert.IsTrue(cardDiscardedEventTriggered);
     Assert.IsTrue(((MockCardWithData)c).data == 42);
 }
Example #7
0
        // If the player cannot draw destination cards or claim a route, they need to draw train cards
        // First, the player looks at the available draw cards
        // If two of them are their desired colors, they take them both
        // If only one is a desired color, they will take that and one from the deck
        // If there are no desired colors showing, but there is a locomotive, they will take that
        // If no desired colors and no locomotives are showing, they will take two off the deck
        private void DrawCards()
        {
            // If the player wants a grey route, they will also be able to take whatever they have the most of already
            if (DesiredColors.Contains(TrainColor.Grey))
            {
                var mostPopularColor = Hand.GetMostPopularColor(DesiredColors);
                DesiredColors.Add(mostPopularColor);
                DesiredColors.Remove(TrainColor.Grey);
            }

            // Check the desired colors against the shown cards
            var shownColors    = Board.ShownCards.Select(x => x.Color);
            var matchingColors = DesiredColors.Intersect(shownColors).ToList();

            var desiredCards = Board.ShownCards.Where(x => DesiredColors.Contains(x.Color));

            if (matchingColors.Count() >= 2)
            {
                // Take te cards and add them to the hand
                var cards = desiredCards.Take(2).ToList();

                foreach (var card in cards)
                {
                    Console.WriteLine(Name + " takes the shown " + card.Color + " card.");

                    Board.ShownCards.Remove(card);
                    Hand.Add(card);
                }
            }
            else if (matchingColors.Count() == 1)
            {
                // Take the shown color
                var card = desiredCards.First();
                Board.ShownCards.Remove(card);
                Hand.Add(card);

                Console.WriteLine(Name + " takes the shown " + card.Color + " card.");

                // Also take one from the deck
                var deckCard = Board.Deck.Pop(1).First();
                Hand.Add(deckCard);

                Console.WriteLine(Name + " also draws one card from the deck.");
            }
            else if (!matchingColors.Any() && Board.ShownCards.Any(x => x.Color == TrainColor.Locomotive))
            {
                Console.WriteLine(Name + " takes the shown locomotive.");

                // Take the locomotive card
                var card = Board.ShownCards.First(x => x.Color == TrainColor.Locomotive);
                Board.ShownCards.Remove(card);
                Hand.Add(card);
            }
            else
            {
                Console.WriteLine(Name + " draws two cards from the deck.");

                //Take two cards from the deck
                var cards = Board.Deck.Pop(2);
                Hand.AddRange(cards);
            }

            Board.PopulateShownCards();
        }
Example #8
0
        //determine the hole cards of the player and the community cards to be dealt
        //determines who will win the showdown at the end
        public void CalculateHandValueHard(Hand otherHand,Deck deck)
        {
            Hand knownCommunityCards = new Hand();
            Hand remainingCommunityCards = new Hand();
            //add known community cards
            for (int i = 2; i < myHand.Count(); i++)
            {
                knownCommunityCards.Add(myHand[i]);
            }
            //generate remaining community cards
            if (knownCommunityCards.Count() < 5)
            {
                remainingCommunityCards.Add(deck.Deal());
                if (knownCommunityCards.Count() < 4)
                {
                    remainingCommunityCards.Add(deck.Deal());
                    if (knownCommunityCards.Count() < 3)
                    {
                        remainingCommunityCards.Add(deck.Deal());
                        remainingCommunityCards.Add(deck.Deal());
                        remainingCommunityCards.Add(deck.Deal());
                    }
                }
            }
            //add the remaining cards
            this.AddToHand(remainingCommunityCards);
            otherHand += remainingCommunityCards;
            otherHand += knownCommunityCards;

            //compare hands
            if (HandCombination.getBestHandEfficiently(new Hand(myHand)) > HandCombination.getBestHandEfficiently(new Hand(otherHand)))
                handValue = 1;
            else if (HandCombination.getBestHandEfficiently(new Hand(myHand)) < HandCombination.getBestHandEfficiently(new Hand(otherHand)))
                handValue = 0;
            else
                handValue = 0.5;
            for (int i = 0; i < remainingCommunityCards.Count(); i++)
            {
                myHand.Remove(remainingCommunityCards[i]);
            }
        }
Example #9
0
 public void addCard(GameObject card)
 {
     hand.Add(card.GetComponent <AdventureCard>());
 }
Example #10
0
 public void DrawFromDeck(Game g)
 {
     Hand.Add(g.Deck.DrawCard());
 }
        public void Test_CheckHighCardHand_ShouldPass()
        {
            var card1 = new SimpleCard(CardType.Three, Suit.Clubs);
            var card2 = new SimpleCard(CardType.Two, Suit.Diamonds);
            var card3 = new SimpleCard(CardType.Seven, Suit.Hearts);
            var card4 = new SimpleCard(CardType.Five, Suit.Spades);
            var card5 = new SimpleCard(CardType.Nine, Suit.Diamonds);
            var hand = new Hand();

            hand.Add(card1);
            hand.Add(card2);
            hand.Add(card3);
            hand.Add(card4);
            hand.Add(card5);

            var sortedHand = hand.Sort();
            var firstHand = new HandEvaluator(sortedHand);
            firstHand.EvaluateHand();

            bool highCard = firstHand.HandValue.HighCard.Equals((int)card5.Type);

            Assert.IsTrue(highCard);
        }
Example #12
0
 public void DrawPrizeCard(Card prizeCard)
 {
     Hand.Add(prizeCard);
     PrizeCards.Remove(prizeCard);
 }
Example #13
0
 public void AddCardToHand(PowerCard card)
 {
     Hand.Add(card);
 }
Example #14
0
        public static void Test1()
        {
            Piece p = Piece.GOLD;

            Console.WriteLine(p.Pretty());
            Console.WriteLine(p.ToUsi());
            Piece p2 = Shogi.Core.Util.MakePiecePromote(Color.WHITE, p);

            Console.WriteLine(p2.ToUsi());

#if false
            // Squareのテスト
            Square sq = Square.SQ_56;
            //Console.WriteLine(sq.ToFile().ToUSI() + sq.ToRank().ToUSI());
            Console.WriteLine(sq.ToUsi());
            Console.WriteLine(sq.Pretty());
#endif

            Move m = Shogi.Core.Util.MakeMove(Square.SQ_56, Square.SQ_45);
            Console.WriteLine(m.ToUsi());

            Move m2 = Shogi.Core.Util.MakeMoveDrop(Piece.SILVER, Square.SQ_45);
            Console.WriteLine(m2.ToUsi());

            Move m3 = Shogi.Core.Util.MakeMovePromote(Square.SQ_84, Square.SQ_83);
            Console.WriteLine(m3.ToUsi());

            Move m4 = Shogi.Core.Util.FromUsiMove("8h2b+");
            Console.WriteLine(m4.Pretty());

            Move m5 = Shogi.Core.Util.FromUsiMove("G*3b");
            Console.WriteLine(m5.Pretty());

            Move m6 = Shogi.Core.Util.FromUsiMove("7g7f");

            Hand h = Hand.ZERO;
            h.Add(Piece.PAWN, 5);
            h.Add(Piece.KNIGHT, 1);
            Console.WriteLine(h.Pretty());
            Console.WriteLine(h.ToUsi(Color.BLACK));
            Console.WriteLine(h.ToUsi(Color.WHITE));

            var pos = new Position();
            //pos.UsiPositionCmd("startpos moves 7g7f 3c3d 8h3c+");

            pos.InitBoard(BoardType.NoHandicap);
            MoveGen.GenTest(pos);

            pos.UsiPositionCmd("sfen lnsgkgsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL w - 1 moves 5a6b 7g7f 3a3b");

            Console.WriteLine(pos.Pretty());

#if false
            // UndoMove()のテスト
            pos.UndoMove();
            Console.WriteLine(pos.Pretty());

            pos.UndoMove();
            Console.WriteLine(pos.Pretty());

            pos.UndoMove();
            Console.WriteLine(pos.Pretty());
            Console.WriteLine(pos.PrettyPieceNo());
#endif

            // 駒番号のテスト
            //Console.WriteLine(pos.PrettyPieceNo());

            //  Console.WriteLine(pos.Pieces().Pretty());
            //  Console.WriteLine(pos.Pieces(Color.BLACK).Pretty());


#if false
            // Bitboard(Square)のテスト
            for (Square sq = Square.ZERO; sq < Square.NB; ++sq)
            {
                Console.WriteLine("sq = " + sq.Pretty());
                Bitboard b = new Bitboard(sq);
                Console.WriteLine(b.Pretty());
            }
#endif

#if false
            // 角・馬の利きのテスト
            Bitboard occupied = new Bitboard(Square.SQ_33);
            Console.WriteLine(occupied.Pretty());
            Bitboard bb = Bitboard.BishopEffect(Square.SQ_55, occupied);
            Console.WriteLine(bb.Pretty());

            Bitboard bb2 = Bitboard.BishopStepEffect(Square.SQ_56);
            Console.WriteLine(bb2.Pretty());

            Bitboard bb3 = Bitboard.BishopEffect(Square.SQ_56, Bitboard.AllBB());
            Console.WriteLine(bb3.Pretty());

            Bitboard bb4 = Bitboard.HorseEffect(Square.SQ_55, occupied);
            Console.WriteLine(bb4.Pretty());
#endif

#if false
            // 飛車・龍の利きのテスト
            Bitboard occupied = new Bitboard(Square.SQ_53);
            Console.WriteLine(occupied.Pretty());
            Bitboard bb = Bitboard.RookEffect(Square.SQ_55, occupied);
            Console.WriteLine(bb.Pretty());

            Bitboard bb2 = Bitboard.RookStepEffect(Square.SQ_56);
            Console.WriteLine(bb2.Pretty());

            Bitboard bb3 = Bitboard.RookEffect(Square.SQ_56, Bitboard.AllBB());
            Console.WriteLine(bb3.Pretty());

            Bitboard bb4 = Bitboard.DragonEffect(Square.SQ_55, occupied);
            Console.WriteLine(bb4.Pretty());
#endif

#if false
            // 香りの利きのテスト
            Bitboard occupied = new Bitboard(Square.SQ_53);
            Bitboard bb       = Bitboard.LanceEffect(Color.BLACK, Square.SQ_55, occupied);
            Console.WriteLine(bb.Pretty());

            Bitboard bb3 = Bitboard.LanceStepEffect(Color.BLACK, Square.SQ_56);
            Console.WriteLine(bb3.Pretty());
#endif

#if false
            // 歩、桂、銀、金、玉の利きのテスト
            Bitboard bb = Bitboard.PawnEffect(Color.BLACK, Square.SQ_55);
            Console.WriteLine(bb.Pretty());

            Bitboard bb2 = Bitboard.KnightEffect(Color.BLACK, Square.SQ_55);
            Console.WriteLine(bb2.Pretty());

            Bitboard bb3 = Bitboard.SilverEffect(Color.BLACK, Square.SQ_55);
            Console.WriteLine(bb3.Pretty());

            Bitboard bb4 = Bitboard.GoldEffect(Color.BLACK, Square.SQ_55);
            Console.WriteLine(bb4.Pretty());

            Bitboard bb5 = Bitboard.KingEffect(Square.SQ_55);
            Console.WriteLine(bb5.Pretty());
#endif

#if false
            // EffectsFrom()のテスト
            var bb = Bitboard.EffectsFrom(Piece.W_DRAGON, Square.SQ_54, pos.Pieces());
            Console.WriteLine(bb.Pretty());

            var bb2 = Bitboard.EffectsFrom(Piece.W_GOLD, Square.SQ_54, pos.Pieces());
            Console.WriteLine(bb2.Pretty());
#endif

#if false
            // BitboardのPop()のテスト
            for (Square sq = Square.ZERO; sq < Square.NB; ++sq)
            {
                Console.Write("sq = " + sq.Pretty() + " ");
                Bitboard b = new Bitboard(sq);
                Square   r = b.Pop();
                Console.WriteLine(r.Pretty());
            }
#endif

#if false
            // 駒落ちの局面のテスト
            pos.InitBoard(BoardType.Handicap2); // 2枚落ち
            Console.WriteLine(pos.Pretty());

            pos.InitBoard(BoardType.Handicap10); // 10枚落ち
            Console.WriteLine(pos.Pretty());
#endif

#if false
            pos.SetSfen(Position.SFEN_HIRATE);
            Console.WriteLine(pos.ToSfen());
            Console.WriteLine(pos.Pretty());
            pos.DoMove(m6);
            Console.WriteLine(pos.Pretty());
#endif

#if false
            // sfen化して、setしてhash keyが変わらないかのテスト
            //pos.SetSfen(pos.ToSfen());
            //Console.WriteLine(pos.Pretty());
#endif

#if false
            // 指し手生成祭りの局面
            pos.SetSfen("l6nl/5+P1gk/2np1S3/p1p4Pp/3P2Sp1/1PPb2P1P/P5GS1/R8/LN4bKL w RGgsn5p 1");
            Console.WriteLine(pos.ToSfen());
            Console.WriteLine(pos.Pretty());
#endif

#if false
            // 駒番号のデバッグ
            Console.WriteLine(pos.PrettyPieceNo());

            //            Console.WriteLine(pos.Pieces().Pretty());
            //           Console.WriteLine(pos.Pieces(Color.BLACK).Pretty());
#endif

#if false
            // BitweenBB()のテスト
            var bb = Bitboard.BetweenBB(Square.SQ_77, Square.SQ_33);
            Console.WriteLine(bb.Pretty());

            var bb2 = Bitboard.BetweenBB(Square.SQ_58, Square.SQ_52);
            Console.WriteLine(bb2.Pretty());
#endif

#if false
            // 乱数テスト
            var rand = new PRNG(1234);
            Console.WriteLine(rand.Rand());
            Console.WriteLine(rand.Rand());
            Console.WriteLine(rand.Rand());

            var key_side = Zobrist.Side;
            Console.WriteLine(key_side.ToString());
#endif

#if false
            // serialization test

            var csa        = new Model.CsaConnectData();
            var serializer = new DataContractJsonSerializer(typeof(Model.CsaConnectData));
            var ms         = new MemoryStream();
            serializer.WriteObject(ms, csa);
            var json = Encoding.UTF8.GetString(ms.ToArray());
            MessageBox.Show(json);
#endif

#if false
            // UsiPositionCmdのテスト。非合法手が混じっているパターン

            var pos2 = new Position();
            try
            {
                pos2.UsiPositionCmd("startpos moves 7g7f 3c4d 2g2f "); // 2手目が非合法手
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
#endif

#if false
            {
                // 千日手の引き分けのテスト
                var pos2 = new Position();
                pos.UsiPositionCmd("startpos moves");

                var moves = new[] {
                    Util.MakeMove(Square.SQ_59, Square.SQ_58),
                    Util.MakeMove(Square.SQ_51, Square.SQ_52),
                    Util.MakeMove(Square.SQ_58, Square.SQ_59),
                    Util.MakeMove(Square.SQ_52, Square.SQ_51),
                };

                int ply = 0;
                for (int j = 0; j < 5; ++j)
                {
                    for (int i = 0; i < moves.Length; ++i)
                    {
                        pos.DoMove(moves[i]);
                        var rep = pos.IsRepetition();

                        ply++;
                        Console.WriteLine(string.Format("ply = {0} , rep = {1} ", ply, rep.ToString()));

                        // 16手目を指した局面(17手目)が先手番で千日手引き分けの局面になるはず
                    }
                }
            }
#endif

#if false
            {
                // 連続王手の千日手の負けのテスト
                var pos2 = new Position();
                pos.UsiPositionCmd("startpos moves 7g7f 5c5d 8h3c 5a6b");

                var moves = new[] {
                    Util.MakeMove(Square.SQ_33, Square.SQ_44),
                    Util.MakeMove(Square.SQ_62, Square.SQ_51),
                    Util.MakeMove(Square.SQ_44, Square.SQ_33),
                    Util.MakeMove(Square.SQ_51, Square.SQ_62),
                };

                int ply = 4;
                for (int j = 0; j < 5; ++j)
                {
                    for (int i = 0; i < moves.Length; ++i)
                    {
                        pos.DoMove(moves[i]);
                        //Console.WriteLine(pos.Pretty());
                        //Console.WriteLine(pos.State().checkersBB.Pretty());

                        var rep = pos.IsRepetition();

                        ply++;
                        Console.WriteLine(string.Format("ply = {0} , rep = {1} ", ply, rep.ToString()));

                        // 19手目の局面(を指した直後の局面=20手目,後手番)で、ここで後手勝ちになるはず。
                    }
                }
            }
#endif

#if false
            //  UndoMove()でcapture,promoteが戻るかのテスト
            var pos2 = new Position();
            pos2.UsiPositionCmd("startpos moves 7g7f 3c3d 8h2b+");
            Console.WriteLine(pos2.Pretty());
            pos2.UndoMove();
            Console.WriteLine(pos2.Pretty());
            pos2.UndoMove();
            Console.WriteLine(pos2.Pretty());
            pos2.UndoMove();
            Console.WriteLine(pos2.Pretty());
            Console.WriteLine(pos2.PrettyPieceNo());
#endif

#if true
            {
                // -- 局面の合法性のチェック

                // 平手
                pos.SetSfen("lnsgkgsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 先手2歩
                pos.SetSfen("lnsgkgsnl/9/9/P8/9/9/P8/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 後手2歩
                pos.SetSfen("lnsgkgsnl/9/8p/8p/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 玉なし
                pos.SetSfen("lnsg1gsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSG1GSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 片玉
                pos.SetSfen("lnsg1gsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 片玉(詰将棋時) これは合法
                pos.SetSfen("lnsg1gsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine("詰将棋片玉 : " + pos.IsValid(true));

                // 先手玉が2枚
                pos.SetSfen("lnsgKgsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 玉3枚
                pos.SetSfen("lnsgkksnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 非手番側に王手
                pos.SetSfen("lnsgkgsnl/9/ppppppBpp/9/9/9/PPPPPPPPP/25R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());

                // 行き場の無い駒
                pos.SetSfen("Lnsgkgsnl/9/pppppp1pp/9/9/9/PPPPPPPPP/25R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());
                pos.SetSfen("l1sgkgsnl/N8/pppppp1pp/9/9/9/PPPPPPPPP/25R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());
                pos.SetSfen("P1sgkgsnl/9/pppppp1pp/9/9/9/9/25R1/LNSGKGSNL b - 1");
                Console.WriteLine(pos.IsValid());
                pos.SetSfen("2sgkgsnl/9/9/9/9/9/9/25R1/LNSGKGSNp b - 1");
                Console.WriteLine(pos.IsValid());
            }
#endif
        }
Example #15
0
 public override void StartTurn()
 {
     base.StartTurn();
     Hand.Add(Deck.Draw());
 }
Example #16
0
        public void TestIsEmpty()
        {
            Assert.AreEqual(empty.Count, 0);
            Assert.True(empty.IsEmpty());

            Domino d13 = new Domino(1, 3);

            empty.Add(d13);

            Assert.False(empty.IsEmpty());
        }
Example #17
0
 public void Deal(Card card)
 {
     Hand.Add(card);
     UpdateText();
 }
Example #18
0
 // drawFromDeck method is used by gameManager to take a card from the shuffled deck and add it to the players Hand
 public void DrawFromDeck(Card card)
 {
     Hand.Add(card);
 }
Example #19
0
        static void Main(string[] args)
        {
            bool control;

            do
            {
                Console.Clear();
                int opponents;
                do
                {
                    Console.Write("Number of opponents: ");
                } while (!int.TryParse(Console.ReadLine(), out opponents));
                Console.WriteLine();
                var  hand      = new Hand("Me", opponents);
                var  boardHand = new Hand();
                Card card;

                for (int i = 1; i <= 2; i++)
                {
                    Console.WriteLine("Card {0}:", i);
                    card = GetCard();
                    hand.Add(card);
                }
                Console.WriteLine();

                Console.WriteLine("Flop:");
                for (int i = 0; i < 3; i++)
                {
                    card = GetCard();
                    hand.Add(card);
                    boardHand.Add(card);
                }
                hand = TwoPlusTwo.Evaluate(hand, boardHand);
                Console.WriteLine();
                PrintHandStrength(hand, opponents + 1);

                Console.WriteLine("Turn:");
                card = GetCard();
                hand.Add(card);
                boardHand.Add(card);
                hand = TwoPlusTwo.Evaluate(hand, boardHand);
                Console.WriteLine();
                PrintHandStrength(hand, opponents + 1);

                Console.WriteLine("River:");
                card = GetCard();
                hand.Add(card);
                boardHand.Add(card);
                Console.WriteLine();
                hand = TwoPlusTwo.Evaluate(hand, boardHand);
                PrintHandStrength(hand, opponents + 1);

                Console.WriteLine("Do you want to play again? ");
                if (Console.ReadLine() == "y")
                {
                    control = true;
                }
                else
                {
                    control = false;
                }
            } while (control);
        }
Example #20
0
 public static Hand getFullHouse(Hand hand)
 {
     hand.sortByRank();
     Hand fullhouse = new Hand();
     fullhouse.setValue(7);
     bool threeofakind = false, pair = false;
     int threeofakindRank = 0;
     for (int i = 0; i <= hand.Count() - 3; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2))
         {
             threeofakind = true;
             threeofakindRank = hand.getCard(i).getRank();
             fullhouse.Add(hand.getCard(i));
             fullhouse.Add(hand.getCard(i + 1));
             fullhouse.Add(hand.getCard(i + 2));
             fullhouse.setValue(hand.getCard(i).getRank());
             break;
         }
     }
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i).getRank() != threeofakindRank)
         {
             pair = true;
             fullhouse.Add(hand.getCard(i));
             fullhouse.Add(hand.getCard(i + 1));
             fullhouse.setValue(hand.getCard(i).getRank());
             break;
         }
     }
     if (threeofakind == true && pair == true)
         return fullhouse;
     else
     {
         fullhouse.Clear();
         return fullhouse;
     }
 }
Example #21
0
 public void GiveCard(string card)
 {
     Hand.Add(card);
 }
Example #22
0
 public static Hand getOnePair(Hand hand)
 {
     hand.sortByRank();
     Hand onepair = new Hand();
     onepair.setValue(2);
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1))
         {
             onepair.setValue(hand.getCard(i).getRank());
             onepair.Add(hand.getCard(i));
             onepair.Add(hand.getCard(i + 1));
             break;
         }
     }
     return getKickers(hand, onepair);
 }
        public void BalancedMajors()
        {
            var hand = new Hand();

            hand.Add(Card.Parse("KC"));
            hand.Add(Card.Parse("AC"));
            hand.Add(Card.Parse("6C"));
            hand.Add(Card.Parse("2H"));
            hand.Add(Card.Parse("3H"));
            hand.Add(Card.Parse("QD"));
            hand.Add(Card.Parse("AD"));
            hand.Add(Card.Parse("2S"));
            hand.Add(Card.Parse("3S"));
            Assert.AreEqual(true, new Balanced().IsTrue(hand));

            hand = new Hand();
            hand.Add(Card.Parse("KC"));
            hand.Add(Card.Parse("AC"));
            hand.Add(Card.Parse("6C"));
            hand.Add(Card.Parse("AH"));
            hand.Add(Card.Parse("3H"));
            hand.Add(Card.Parse("QD"));
            hand.Add(Card.Parse("AD"));
            hand.Add(Card.Parse("2S"));
            hand.Add(Card.Parse("3S"));
            hand.Add(Card.Parse("4S"));
            hand.Add(Card.Parse("5S"));
            hand.Add(Card.Parse("6S"));
            Assert.AreEqual(false, new Balanced().IsTrue(hand));

            hand = new Hand();
            hand.Add(Card.Parse("KC"));
            hand.Add(Card.Parse("AC"));
            hand.Add(Card.Parse("6C"));
            hand.Add(Card.Parse("AH"));
            hand.Add(Card.Parse("3H"));
            hand.Add(Card.Parse("4H"));
            hand.Add(Card.Parse("5H"));
            hand.Add(Card.Parse("6H"));
            hand.Add(Card.Parse("QD"));
            hand.Add(Card.Parse("AD"));
            hand.Add(Card.Parse("2S"));
            hand.Add(Card.Parse("3S"));
            Assert.AreEqual(false, new Balanced().IsTrue(hand));
        }
Example #24
0
 //use a counter to determine with suit forms a flush
 //then get all cards from the suit
 public static Hand getFlush(Hand hand)
 {
     hand.sortByRank();
     Hand flush = new Hand();
     flush.setValue(6);
     int diamondCount = 0, clubCount = 0, heartCount = 0, spadeCount = 0;
     for (int i = 0; i < hand.Count(); i++)
     {
         if ((SUIT)hand.getCard(i).getSuit() == SUIT.DIAMONDS)
             diamondCount++;
         else if ((SUIT)hand.getCard(i).getSuit() == SUIT.CLUBS)
             clubCount++;
         else if ((SUIT)hand.getCard(i).getSuit() == SUIT.HEARTS)
             heartCount++;
         else if ((SUIT)hand.getCard(i).getSuit() == SUIT.SPADES)
             spadeCount++;
     }
     if (diamondCount >= 5)
     {
         for (int i = 0; i < hand.Count(); i++)
         {
             if (hand.getCard(i).getSuit() == 1)
             {
                 flush.Add(hand.getCard(i));
                 flush.setValue(hand.getCard(i).getRank());
             }
             if (flush.Count() == 5)
                 break;
         }
         //return flush;
     }
     else if (clubCount >= 5)
     {
         for (int i = 0; i <= hand.Count(); i++)
         {
             if (hand.getCard(i).getSuit() == 2)
             {
                 flush.Add(hand.getCard(i));
                 flush.setValue(hand.getCard(i).getRank());
             }
             if (flush.Count() == 5)
                 break;
         }
         //return flush;
     }
     else if (heartCount >= 5)
     {
         for (int i = 0; i <= hand.Count(); i++)
         {
             if (hand.getCard(i).getSuit() == 3)
             {
                 flush.Add(hand.getCard(i));
                 flush.setValue(hand.getCard(i).getRank());
             }
             if (flush.Count() == 5)
                 break;
         }
         //return flush;
     }
     else if (spadeCount >= 5)
     {
         for (int i = 0; i <= hand.Count(); i++)
         {
             if (hand.getCard(i).getSuit() == 4)
             {
                 flush.Add(hand.getCard(i));
                 flush.setValue(hand.getCard(i).getRank());
             }
             if (flush.Count() == 5)
                 break;
         }
         //return flush;
     }
     return flush;
 }
Example #25
0
 public void OnDrawCard(Card card)
 {
     Deck.CardCount--;
     Hand.Add(card);
 }
Example #26
0
 public void AddDieToHand(Dice dieIn)
 {
     Hand.Add(dieIn);
 }
Example #27
0
        static void TestClubsMeld()
        {
            Card c1 = new Card(1, 1);
            Card c2 = new Card(2, 1);
            Card c3 = new Card(3, 1);
            Card c4 = new Card(4, 1);
            Card c5 = new Card(5, 1);

            Hand h1 = new Hand();

            h1.Add(c1);
            h1.Add(c2);
            h1.Add(c3);
            h1.Add(c4);
            h1.Add(c5);
            h1.Add(c3);
            h1.Add(c2);
            h1.Add(c1);
            h1.Add(c2);
            h1.Add(c3);
            h1.Add(c4);
            h1.Add(c5);
            h1.Add(c3);
            h1.Add(c2);



            Console.WriteLine(h1.HasRunClubs());
            Console.WriteLine();
            Console.WriteLine(h1.HasNineteenPounderClubs());
            Console.WriteLine();
            Console.WriteLine(h1.HasTwentyThreePounderClubs());
            Console.WriteLine();
            Console.WriteLine(h1.HasTwentySevenPounderClubs());
            Console.WriteLine();
            Console.WriteLine(h1.HasMarriageClubs());
            Console.WriteLine();
            Console.WriteLine(h1.HasDoubleRunClubs());
            Console.WriteLine();

            Console.ReadLine();
        }
Example #28
0
 public override void HandlePreSelection(PreBoard preBoard, Hand playerHand, ref InputResult result)
 {
     this.prevPreSelect = this.preSelect;
     if (this.preSelect == -1)
     {
         this.preSelect = 0;
     }
     if (UIManager.Input.GetKey(Control.Down) && this.preSelect % 10 != 9)
     {
         this.preSelect++;
     }
     if (UIManager.Input.GetKey(Control.Up) && this.preSelect % 10 != 0)
     {
         this.preSelect--;
     }
     if (UIManager.Input.GetKey(Control.Right) && this.preSelect / 10 != 9)
     {
         this.preSelect += 10;
     }
     if (UIManager.Input.GetKey(Control.Left) && this.preSelect / 10 != 0)
     {
         this.preSelect -= 10;
     }
     if (this.prevPreSelect != this.preSelect || !this.launched)
     {
         preBoard.SetPreviewCardID(this.preSelect);
         this.launched = true;
     }
     if (UIManager.Input.GetKey(Control.LeftBumper))
     {
         preBoard.PrevCard();
         SoundEffect.Play(QuadMistSoundID.MINI_SE_CARD_MOVE);
     }
     if (UIManager.Input.GetKey(Control.RightBumper))
     {
         preBoard.NextCard();
         SoundEffect.Play(QuadMistSoundID.MINI_SE_CARD_MOVE);
     }
     if (UIManager.Input.GetKey(Control.Confirm))
     {
         if (playerHand.Count != 5 && preBoard.CountSelected() > 0)
         {
             QuadMistCard item = preBoard.RemoveSelected();
             playerHand.Add(item);
             if (playerHand.Count == 5)
             {
                 result.Used();
                 this.launched = false;
                 return;
             }
         }
         else if (playerHand.Count == 5)
         {
             result.Used();
             this.launched = false;
             return;
         }
         if (QuadMistGame.main.CardNameDialogSlider.IsShowCardName)
         {
             QuadMistGame.main.CardNameDialogSlider.ShowCardNameDialog(playerHand);
         }
         else
         {
             QuadMistGame.main.CardNameDialogSlider.HideCardNameDialog(playerHand);
         }
     }
     else if (UIManager.Input.GetKey(Control.Cancel))
     {
         Int32 num = playerHand.Count - 1;
         if (num >= 0)
         {
             preBoard.Add(playerHand[num]);
             playerHand.RemoveAt(num);
         }
         SoundEffect.Play(QuadMistSoundID.MINI_SE_CANCEL);
     }
 }
Example #29
0
        static void TestCalcPinochleandJacksMeld()
        {
            Card c1 = new Card(1, 2);
            Card c3 = new Card(1, 1);
            Card c4 = new Card(1, 3);
            Card c5 = new Card(1, 4);
            Card c2 = new Card(2, 4);
            Hand h  = new Hand();

            h.Add(c1);
            h.Add(c2);
            h.Add(c1);
            h.Add(c2);
            h.Add(c1);
            h.Add(c2);
            h.Add(c3);
            h.Add(c4);
            h.Add(c5);
            h.Add(c3);
            h.Add(c4);
            h.Add(c5);
            Console.WriteLine(h.Meld);
            Console.ReadLine();
        }
Example #30
0
 public void AddHandCard(Card c)
 {
     _hand.Add(c);
 }
Example #31
0
    public void DrawCard(CardPile pile)
    {
        // Can't draw cards if we're not the active player
        if (!activePlayer)
        {
            return;
        }

        // Can't draw a card if we have one floating
        if (currentCard != null)
        {
            return;
        }

        // Check if pile has cards
        if (pile.GetCardCount() <= 0)
        {
            // Check if we can dump the graveyard back in the deck
            if (GameMng.GetRules().infiniteDeck)
            {
                var cards = graveyard.GetCards();
                graveyard.Clear();

                if (GameMng.GetRules().reshuffleInfinite)
                {
                    ShuffleDeck(cards);
                }

                pile.Add(cards);

                if (pile.GetCardCount() <= 0)
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }

        // Check if we can draw cards (cards in hand is less than maximum allowed)
        if (hand.GetCardCount() >= GameMng.GetRules().maxCardsInHand)
        {
            return;
        }

        // Check if we've already drawn enough cards this turn
        if (drawCount >= GameMng.GetRules().drawPerTurn)
        {
            return;
        }

        drawCount++;

        // Get the first card
        CardDesc card = pile.GetFirstCard();

        // Create the card itself and pop it on the hand
        var cardObject = GameMng.CreateCard(card);

        hand.Add(cardObject);
    }
Example #32
0
 public void DrawFromTable(Game g)
 {
     Hand.Add(g.Table[g.Table.Count - 1]);
     g.Table.RemoveAt(g.Table.Count - 1);
 }
Example #33
0
 public int Hit()
 {
     Hand.Add(Deck.Draw());
     return(SumHand(Hand));
 }
Example #34
0
        //using the monte carlo method, calculate a hand value for the AI's current hand
        //this can be very hard on the computer's memory and processor and can result in lag time
        public void CalculateHandValue(int count)
        {
            double score = 0;
            PlayerList playerList = new PlayerList();
            for (int i = 0; i < count - 1; i++)
            {
                playerList.Add(new Player());
            }
            Hand bestHand = new Hand();
            int bestHandCount = 1;
            Deck deck = new Deck();
            Hand knownCommunityCards = new Hand();
            Hand remainingCommunityCards = new Hand();
            Hand myHoleCards = new Hand();
            //remove known cards from deck
            for (int i = 0; i < myHand.Count(); i++)
            {
                deck.Remove(myHand[i]);
            }
            //add known community cards
            for (int i = 2; i < myHand.Count(); i++)
            {
                knownCommunityCards.Add(myHand[i]);
            }
            myHoleCards.Add(this.getHand()[0]);
            myHoleCards.Add(this.getHand()[1]);
            //loop 100 times
            for (int i = 0; i < 100; i++)
            {
                //reset players and shuffle deck
                for (int j = 0; j < playerList.Count; j++)
                {
                    playerList[j].isbusted = false;
                    playerList[j].getHand().Clear();
                }
                myHand.Clear();
                remainingCommunityCards.Clear();
                deck.Shuffle();

                //generate remaining community cards
                if (knownCommunityCards.Count() < 5)
                {
                    remainingCommunityCards.Add(deck.Deal());
                    if (knownCommunityCards.Count() < 4)
                    {
                        remainingCommunityCards.Add(deck.Deal());
                        if (knownCommunityCards.Count() < 3)
                        {
                            remainingCommunityCards.Add(deck.Deal());
                            remainingCommunityCards.Add(deck.Deal());
                            remainingCommunityCards.Add(deck.Deal());
                        }
                    }
                }
                //add hole/community cards to the AI
                this.AddToHand(knownCommunityCards);
                this.AddToHand(remainingCommunityCards);
                this.AddToHand(myHoleCards);
                //add hole/community cards to other players
                for (int j = 0; j < playerList.Count; j++)
                {
                    playerList[j].AddToHand(knownCommunityCards);
                    if (remainingCommunityCards.Count() != 0)
                        playerList[j].AddToHand(remainingCommunityCards);
                    playerList[j].AddToHand(deck.Deal());
                    playerList[j].AddToHand(deck.Deal());
                    //if player is dealt hole cards of less than 5-5, and no pocket pairs the player drops out
                    if (playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() + playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank() <= 10 && playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() != playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank())
                    {
                        playerList[j].isbusted = true;
                    }
                }
                //add cards back to deck
                for (int j = 0; j < remainingCommunityCards.Count(); j++)
                {
                    deck.Add(remainingCommunityCards[j]);
                }
                for (int j = 0; j < playerList.Count; j++)
                {
                    deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 1]);
                    deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 2]);
                }
                //compare hands
                bestHandCount = 1;
                playerList.Add(this);
                bestHand = playerList[0].getHand();
                for (int j = 0; j <playerList.Count-1; j++)
                {
                    if (playerList[j].isbusted)
                        continue;
                    if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) > HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand())))
                    {
                        bestHandCount = 1;
                        bestHand = playerList[j+1].getHand();
                    }
                    else if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) == HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand())))
                        bestHandCount++;
                }
                playerList.Remove(this);
                //if my hand is the best, increment score
                if (myHand.isEqual(bestHand))
                    score = score + (1 / bestHandCount);
            }
            //reconstruct original hand
            myHand.Clear();
            this.AddToHand(myHoleCards);
            this.AddToHand(knownCommunityCards);
            //calculate hand value as a percentage of wins
            handValue = score / 100;
        }
Example #35
0
        private static void HandlePacket(Packet packet)
        {
            Console.WriteLine(packet.Type);

            switch (packet.Type)
            {
            case PacketType.ServerTime:
                SecondsLeft = ((ServerTime)packet).Seconds;
                break;

            case PacketType.SetStatus:
            {
                SetStatus setStatus = (SetStatus)packet;
                Players[setStatus.Id].Thinking = setStatus.TurnOver;
                break;
            }

            case PacketType.GameOver:
                Game.PushState(new GameOverScreen());
                break;

            case PacketType.InitSelectionScreen:
            {
                InitSelectionScreen initSelectionScreen = (InitSelectionScreen)packet;
                Game.PushState(new SelectionScreen(initSelectionScreen.Options));
                InMatch = false;
                break;
            }

            case PacketType.SelectCardCzar:
            {
                SelectCardCzar selectCardCzar = (SelectCardCzar)packet;
                InGame         game           = (InGame)Game.PeekFirstState();

                foreach (Player p in game.Players)
                {
                    p.Czar = false;
                }

                if (Players.ContainsKey(selectCardCzar.Id))
                {
                    Players[selectCardCzar.Id].Czar = true;
                }
                else
                {
                    game.LocalPlayer.Czar = true;
                }

                foreach (Player p in game.Entities.OfType <Player>())
                {
                    p.Thinking = !p.Czar;
                }

                break;
            }

            case PacketType.WinnerPicked:
            {
                if (Game.PeekState().GetType() != typeof(GameOverScreen))
                {
                    InMatch = true;
                    Game.PopState();

                    WinnerPicked winnerPicked = (WinnerPicked)packet;
                    InGame       game         = (InGame)Game.PeekState();

                    if (winnerPicked.Id != 0)
                    {
                        Player player = Players.ContainsKey(winnerPicked.Id) ? Players[winnerPicked.Id] : game.LocalPlayer;
                        ++player.Score;

                        Game.PushState(new WinnerScreen(player.Name, CurrentBlackCard.Info.Value, winnerPicked.Cards));
                    }
                    else
                    {
                        Game.PushState(new WinnerScreen("No one", CurrentBlackCard.Info.Value, new List <string>()));
                    }
                }
                break;
            }

            case PacketType.WhiteCard:
            {
                WhiteCard whiteCards = (WhiteCard)packet;

                foreach (CardInfo c in whiteCards.Cards)
                {
                    Card card = new Card(c)
                    {
                        Position = new Vector2f(-1024.0f, -1024.0f),
                        Scale    = new Vector2f(0.643f * 0.8f, 0.643f * 0.8f)
                    };

                    Hand.Add(card);
                    Game.PeekFirstState().Entities.Add(card);
                }

                if (Hand.Any(c => c.Info.Value.Contains("brain")) && !gotBrainTumorOnce)
                {
                    Assets.PlaySound("BrainTumorCardStart.wav");
                    gotBrainTumorOnce = true;
                }
                else if (Random.Next(100) < 5)
                {
                    Assets.PlaySound("NoBrainTumorCardStart5.wav");
                }

                break;
            }

            case PacketType.BlackCard:
            {
                BlackCard blackCard = (BlackCard)packet;

                if (CurrentBlackCard != null)
                {
                    Game.PeekFirstState().Entities.Remove(CurrentBlackCard);
                }

                CurrentBlackCard = new Card(blackCard.Card)
                {
                    Position = new Vector2f(GameOptions.Width - 256.0f + 4.0f, 48.0f + 32.0f)
                };
                Game.PeekFirstState().Entities.Add(CurrentBlackCard);
                break;
            }

            case PacketType.LobbyBeginGame:
                Game.SetState(new InGame(((Lobby)Game.PeekFirstState()).Players));
                InMatch = true;
                break;

            case PacketType.PlayerDelete:
            {
                PlayerDelete playerDelete = (PlayerDelete)packet;
                Game.PeekFirstState().Entities.Remove(Players[playerDelete.Id]);
                Players.Remove(playerDelete.Id);

                break;
            }

            case PacketType.PlayerNew:
            {
                PlayerNew playerNew = (PlayerNew)packet;
                Player    player    = new Player(playerNew.Name);
                Players.Add(playerNew.Id, player);

                Game.PeekState().Entities.Add(player);
                break;
            }

            case PacketType.ChatMessage:
            {
                ChatMessage chatMessage = (ChatMessage)packet;

                // TODO Unify chatlogs...
                if (Game.PeekFirstState().GetType() == typeof(Lobby))
                {
                    ((Lobby)Game.PeekFirstState()).ChatBacklog.Add(chatMessage.Value);
                }
                else
                {
                    ((InGame)Game.PeekFirstState()).ChatBacklog.Add(chatMessage.Value);
                }

                GameUtility.PlayTaunt(chatMessage.Value);

                Assets.PlaySound("Bubble.wav");
                break;
            }

            default:
                Console.WriteLine("Unhandled packet!");
                break;
            }
        }
Example #36
0
 //same as above except return the cards themselves
 public static Hand getFourOfAKind(Hand hand)
 {
     Hand fourofakind = new Hand();
     fourofakind.setValue(8);
     hand.sortByRank();
     for (int i = 0; i <= hand.Count() - 4; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2) && hand.getCard(i) == hand.getCard(i + 3))
         {
             fourofakind.Add(hand.getCard(i));
             fourofakind.Add(hand.getCard(i + 1));
             fourofakind.Add(hand.getCard(i + 2));
             fourofakind.Add(hand.getCard(i + 3));
             fourofakind.setValue(hand.getCard(i).getRank());
             break;
         }
     }
     return getKickers(hand,fourofakind);
 }
Example #37
0
 public static Hand getThreeOfAKind(Hand hand)
 {
     hand.sortByRank();
     Hand threeofakind = new Hand();
     threeofakind.setValue(4);
     for (int i = 0; i <= hand.Count() - 3; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2))
         {
             threeofakind.setValue(hand.getCard(i).getRank());
             threeofakind.Add(hand.getCard(i));
             threeofakind.Add(hand.getCard(i + 1));
             threeofakind.Add(hand.getCard(i + 2));
             break;
         }
     }
     return getKickers(hand, threeofakind);
 }
Example #38
0
 //get highest cards after sorting
 public static Hand getHighCard(Hand hand)
 {
     hand.sortByRank();
     Hand highcard = new Hand();
     highcard.setValue(1);
     highcard.Add(hand.getCard(0));
     highcard.setValue(hand.getCard(0).getRank());
     return getKickers(hand, highcard);
 }
Example #39
0
 //explanation below
 public static bool isStraight(Hand hand)
 {
     hand.sortByRank();
     if(hand.getCard(0).getRank()==14)
         hand.Add(new Card((int)RANK.ACE,hand.getCard(0).getSuit()));
     int straightCount=1;
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         //if 5 cards are found to be straights, break out of the loop
         if (straightCount == 5)
             break;
         int currentrank = hand.getCard(i).getRank();
         //if cards suit differ by 1, increment straight
         if (currentrank - hand.getCard(i + 1).getRank() == 1)
             straightCount++;
         //specific condition for 2-A
         else if (currentrank == 2 && hand.getCard(i + 1).getRank() == 14)
             straightCount++;
         //if cards suit differ by more than 1, reset straight to 1
         else if (currentrank - hand.getCard(i + 1).getRank() > 1)
             straightCount = 1;
         //if card suits does not differ, do nothing
     }
     if (hand.getCard(0).getRank() == 14)
         hand.Remove(hand.Count() - 1);
     //depending on the straight count, return true or false
     if (straightCount == 5)
         return true;
     return false;
 }
Example #40
0
 //get straight flush using two pointer variable and taking care of all cases
 public static Hand getStraightFlush(Hand hand)
 {
     hand.sortByRank();
     Hand straightflush = new Hand();
     straightflush.setValue(9);
     if (hand.getCard(0).getRank() == 14)
         hand.Add(new Card((int)RANK.ACE, hand.getCard(0).getSuit()));
     //int straightflushCount = 1;
     straightflush.Add(hand.getCard(0));
     int ptr1=0, ptr2=1;
     while (ptr1 < hand.Count() - 2 || ptr2 < hand.Count())
     {
         if (straightflush.Count() >= 5)
             break;
         int rank1=hand.getCard(ptr1).getRank(), rank2=hand.getCard(ptr2).getRank();
         int suit1=hand.getCard(ptr1).getSuit(), suit2=hand.getCard(ptr2).getSuit();
         if (rank1 - rank2 == 1 && suit1 == suit2)
         {
             straightflush.Add(hand.getCard(ptr2));
             ptr1 = ptr2;
             ptr2++;
         }
         else if(rank1==2&&rank2==14&&suit1==suit2)
         {
             straightflush.Add(hand.getCard(ptr2));
             ptr1 = ptr2;
             ptr2++;
         }
         else
         {
             if (rank1 - rank2 <= 1)
                 ptr2++;
             else
             {
                 straightflush.Clear();
                 straightflush.setValue(9);
                 ptr1++;
                 ptr2=ptr1+1;
                 straightflush.Add(hand.getCard(ptr1));
             }
         }
     }
     if (hand.getCard(0).getRank() == 14)
         hand.Remove(hand.Count() - 1);
     straightflush.setValue(straightflush.getCard(0).getRank());
     if (straightflush.Count() < 5)
         straightflush.Clear();
     return straightflush;
 }
Example #41
0
 public void TestAdd()
 {
     h.Add(d);
     Assert.IsTrue(h.Count.Equals(1));
 }
Example #42
0
 public static Hand getTwoPair(Hand hand)
 {
     hand.sortByRank();
     Hand twopair = new Hand();
     twopair.setValue(3);
     int pairCount = 0;
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1))
         {
             twopair.setValue(hand.getCard(i).getRank());
             twopair.Add(hand.getCard(i));
             twopair.Add(hand.getCard(i+1));
             pairCount++;
             if (pairCount == 2)
                 break;
             i++; //the pair has already been checked, i must be incremented an additional time to avoid using a card in this pair again. This prevents the program from identifying 3 of a kind as 2 pairs.
         }
     }
     if (pairCount == 2)
         return getKickers(hand,twopair);
     else
         twopair.Clear();
         return twopair;
 }
Example #43
0
 public void TestAdd()
 {
     def.Add(new Domino(1, 1));
     Assert.AreEqual(def.Count, 1);
 }
Example #44
0
 //get all remaining cards, if necessary, to form 5 cards
 private static Hand getKickers(Hand hand, Hand specialCards)
 {
     if (specialCards.Count() == 0)
         return specialCards;
     for (int i = 0; i < specialCards.Count(); i++)
     {
         hand.Remove(specialCards.getCard(i));
     }
     for (int i = 0; i < hand.Count();i++)
     {
         if (specialCards.Count() >= 5)
             break;
         specialCards.Add(hand.getCard(i));
         specialCards.setValue(hand.getCard(i).getRank());
     }
     return specialCards;
 }
Example #45
0
 //most important method in the game, controls the turns of the players
 private void TimerNextMove_Tick(object sender, EventArgs e)
 {
     timerCount++;
     //condition if everyone folds
     if (pokerTable.PlayerWon())
     {
         panelBubble.Hide();
         pokerTable.setCurrentIndex(pokerTable.incrementIndexShowdown(pokerTable.getCurrentIndex()));
         pokerTable[pokerTable.getCurrentIndex()].CollectMoney(pokerTable.getPot());
         lblBanner.Text = pokerTable[pokerTable.getCurrentIndex()].Message;
         lblBanner.Show();
         TimerNextMove.Stop();
         TimerWait3Seconds.Start();
         return;
     }
     //condition to increment player's turn
     if (pokerTable.beginNextTurn())
     {
         pokerTable.setCurrentIndex(pokerTable.incrementIndex(pokerTable.getCurrentIndex()));
         lblBanner.Hide();
         //condition to pay small/big blind
         if (timerCount == 1)
             pokerTable.PaySmallBlind();
         else if (timerCount == 2)
             pokerTable.PayBigBlind();
         //condition that the current player is not AI, show labels to player
         else if (pokerTable.getCurrentIndex() == 0)
         {
             initalizeButtons();
             TimerNextMove.Stop();
             return;
         }
         //condition for AI
         else
         {
             AIPlayer currentPlayer = (AIPlayer)pokerTable[pokerTable.getCurrentIndex()];
             if (difficulty == (int)DIFFICULTY.HARD)
             {
                 Hand holeCards=new Hand();
                 holeCards.Add(pokerTable[0].getHand()[0]);
                 holeCards.Add(pokerTable[0].getHand()[1]);
                 currentPlayer.CalculateHandValueHard(holeCards, new Deck(pokerTable.getDeck()));
             }
             currentPlayer.MakeADecision(pokerTable.getPot(), pokerTable.decrementIndex(pokerTable.getCurrentIndex()));
             pokerTable[pokerTable.getCurrentIndex()] = currentPlayer;
             //grey out form if the AI folds
             if (currentPlayer.IsFolded())
                 panelList[pokerTable.getCurrentIndex()].BackgroundImage = Image.FromFile("inactivebutton.png");
         }
         updateMove();
         if (timerCount > 2 && pokerTable.getCurrentIndex() != 0 && difficulty == 1)
         {
             timerCalculate.Start();
         }
     }
     else
     {
         //deal community cards
         pokerTable.TurnCount = 0;
         lblBanner.Show();
         panelBubble.Hide();
         if (pokerTable[0].getHand().Count() == 2)
         {
             pokerTable.DealFlop();
             lblBanner.Text = "Dealing the Flop";
             toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
         }
         else if (pokerTable[0].getHand().Count() == 5)
         {
             pokerTable.DealTurn();
             lblBanner.Text = "Dealing the Turn";
             toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
         }
         else if (pokerTable[0].getHand().Count() == 6)
         {
             pokerTable.DealRiver();
             lblBanner.Text = "Dealing the River";
             toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
         }
         else if (pokerTable[0].getHand().Count() == 7)
         {
             //start timer for showdown
             lblBanner.Text = "Showdown";
             TimerNextMove.Stop();
             TimerShowdown.Start();
             return;
         }
         //reset agressor the dealer
         int dealerPosition = pokerTable.getDealerPosition();
         pokerTable.setCurrentIndex(pokerTable.getDealerPosition());
         pokerTable.getPot().AgressorIndex = pokerTable.getDealerPosition();
         DrawToScreen();
     }
 }
Example #46
0
        public void TestHandPlayableEventIsRaisedWhenTheCardCountIsMoreThanOne()
        {
            bool handPlayableCalled = false;
            Hand hand = new Hand();
            hand.Playable += () => handPlayableCalled = true;

            hand.Add(new Card(Rank.Jack, Suit.Diamonds));
            hand.Add(new Card(Rank.Two, Suit.Diamonds));

            Assert.IsTrue(handPlayableCalled);
        }
Example #47
0
 //most important method in the game, controls the turns of the players
 private void TimerNextMove_Tick(object sender, EventArgs e)
 {
     timerCount++;
     //condition if everyone folds
     if (pokerTable.PlayerWon())
     {
         panelBubble.Hide();
         pokerTable.setCurrentIndex(pokerTable.incrementIndexShowdown(pokerTable.getCurrentIndex()));
         pokerTable[pokerTable.getCurrentIndex()].CollectMoney(pokerTable.getPot());
         lblBanner.Text = pokerTable[pokerTable.getCurrentIndex()].Message;
         lblBanner.Show();
         TimerNextMove.Stop();
         TimerWait3Seconds.Start();
         return;
     }
     //condition to increment player's turn
     if (pokerTable.beginNextTurn())
     {
         pokerTable.setCurrentIndex(pokerTable.incrementIndex(pokerTable.getCurrentIndex()));
         lblBanner.Hide();
         //condition to pay small/big blind
         if (timerCount == 1)
         {
             pokerTable.PaySmallBlind();
         }
         else if (timerCount == 2)
         {
             pokerTable.PayBigBlind();
         }
         //condition that the current player is not AI, show labels to player
         else if (pokerTable.getCurrentIndex() == 0)
         {
             initalizeButtons();
             TimerNextMove.Stop();
             return;
         }
         //condition for AI
         else
         {
             AIPlayer currentPlayer = (AIPlayer)pokerTable[pokerTable.getCurrentIndex()];
             if (difficulty == (int)DIFFICULTY.HARD)
             {
                 Hand holeCards = new Hand();
                 holeCards.Add(pokerTable[0].getHand()[0]);
                 holeCards.Add(pokerTable[0].getHand()[1]);
                 currentPlayer.CalculateHandValueHard(holeCards, new Deck(pokerTable.getDeck()));
             }
             currentPlayer.MakeADecision(pokerTable.getPot(), pokerTable.decrementIndex(pokerTable.getCurrentIndex()));
             pokerTable[pokerTable.getCurrentIndex()] = currentPlayer;
             //grey out form if the AI folds
             if (currentPlayer.IsFolded())
             {
                 panelList[pokerTable.getCurrentIndex()].BackgroundImage = Image.FromFile("inactivebutton.png");
             }
         }
         updateMove();
         if (timerCount > 2 && pokerTable.getCurrentIndex() != 0 && difficulty == 1)
         {
             timerCalculate.Start();
         }
     }
     else
     {
         //deal community cards
         pokerTable.TurnCount = 0;
         lblBanner.Show();
         panelBubble.Hide();
         if (pokerTable[0].getHand().Count() == 2)
         {
             pokerTable.DealFlop();
             lblBanner.Text = "Dealing the Flop";
             toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
         }
         else if (pokerTable[0].getHand().Count() == 5)
         {
             pokerTable.DealTurn();
             lblBanner.Text = "Dealing the Turn";
             toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
         }
         else if (pokerTable[0].getHand().Count() == 6)
         {
             pokerTable.DealRiver();
             lblBanner.Text = "Dealing the River";
             toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
         }
         else if (pokerTable[0].getHand().Count() == 7)
         {
             //start timer for showdown
             lblBanner.Text = "Showdown";
             TimerNextMove.Stop();
             TimerShowdown.Start();
             return;
         }
         //reset agressor the dealer
         int dealerPosition = pokerTable.getDealerPosition();
         pokerTable.setCurrentIndex(pokerTable.getDealerPosition());
         pokerTable.getPot().AgressorIndex = pokerTable.getDealerPosition();
         DrawToScreen();
     }
 }
Example #48
0
 public void AddCard(Card card)
 {
     Hand.Add(card);
     LastDrawnCard = card;
     UpdateValues();
 }
Example #49
0
        public void WhenHandHasStraight_WithLowAce_ShouldReturnStraightRank()
        {
            _hand.Add(new Card(Suit.Clubs, Value.Ace));
            _hand.Add(new Card(Suit.Diamonds, Value.Two));
            _hand.Add(new Card(Suit.Spades, Value.Three));
            _hand.Add(new Card(Suit.Spades, Value.Four));
            _hand.Add(new Card(Suit.Clubs, Value.Five));

            Assert.AreEqual(HandRank.Straight, HandCategoriserChain.GetRank(_hand));
        }
Example #50
0
 public void DealCard(Card card)
 {
     Hand.Add(card);
 }
Example #51
0
 /// <summary>
 /// Adds card passed as parameter to tableau passed as parameter
 /// </summary>
 /// <param name="tableau">Tableau to add card to</param>
 /// <param name="card">Card to be added to tableau</param>
 private static void AddCardToTable(Hand tableau, Card card)
 {
     tableau.Add(card);
 }