Beispiel #1
0
        public frmMain()
        {
            InitializeComponent();

            Deck = new Deck();
            Deck.CreateDefaultDeck(false);
        }
Beispiel #2
0
        private List<Hand> hands()
        {
            Deck deck = new Deck (0);
            var cards = deck.ShuffledList;
            var hand1 = new List<Card> ();
            var hand2 = new List<Card> ();
            var hand3 = new List<Card> ();
            var hand4 = new List<Card> ();
            for (int i = 0; i < cards.Count; i+=4) {
                hand1.Add (cards [i]);
            }
            for (int i = 1; i < cards.Count; i+=4) {
                hand2.Add (cards [i]);
            }
            for (int i = 2; i < cards.Count; i+=4) {
                hand3.Add (cards [i]);
            }
            for (int i = 3; i < cards.Count; i+=4) {
                hand4.Add (cards [i]);
            }
            var hands = new List<Hand> ();
            hands.Add (new Hand (hand1));
            hands.Add (new Hand (hand2));
            hands.Add (new Hand (hand3));
            hands.Add (new Hand (hand4));

            return hands;
        }
        public void TestDeckToHave24CardsAtStart()
        {
            int expectedNumberOfCards = 24;
            var deck = new Deck();

            Assert.AreEqual(expectedNumberOfCards, deck.CardsLeft, "Initial number of cards is not correct");
        }
        public void TestIfTrumpCardReturnsACard()
        {
            var deck = new Deck();
            var card = deck.GetTrumpCard;

            Assert.IsInstanceOf(typeof(Card), card, "The method does not return an instace of Card class");
        }
 public void TestDeckWhenHaveNoMoreCardsLeftToThrow(int cardsToDraw)
 {
     var deck = new Deck();
     for (int i = 0; i < cardsToDraw; i++)
     {
         deck.GetNextCard();
     }
 }
 public void TestIfDeckChangesTheTrumpCard()
 {
     var deck = new Deck();
     var initialTrumpCard = deck.GetTrumpCard;
     var newCard = deck.GetNextCard();
     deck.ChangeTrumpCard(newCard);
     Assert.AreNotSame(initialTrumpCard, deck.GetTrumpCard, "The deck does not change trump card");
 }
Beispiel #7
0
        public void HandToString()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            Hand h = new Hand(hands[0]);

            Debug.WriteLine(h.ToString());
        }
Beispiel #8
0
        public void HandToString()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            Hand h = new Hand(hands[0]);

            Assert.AreEqual(10, h.Points());
            Assert.AreEqual(2, h.ExtraPoints());
        }
        public void TestDeckToHaveCorrectNumberOfCardsAfterDrawing()
        {
            int expectedNumberOfCards = 20;
            var deck = new Deck();
            for (int i = 0; i < 4; i++)
            {
                deck.GetNextCard();
            }

            Assert.AreEqual(expectedNumberOfCards, deck.CardsLeft, "Number of cards during game is not correct");
        }
Beispiel #10
0
        public void Deck_Deal4HandsEachWith0Cards()
        {
            Deck deck = new Deck();

            IHand[] hands = deck.Deal(0, 4);

            Assert.AreEqual(4, hands.Length);
            Assert.AreEqual(0, hands[0].Count);
            Assert.AreEqual(0, hands[1].Count);
            Assert.AreEqual(0, hands[2].Count);
            Assert.AreEqual(0, hands[3].Count);
        }
Beispiel #11
0
        public void Deck_Deals4HandsEachContains13Cards()
        {
            Deck deck = new Deck();

            IHand [] hands = deck.Deal(13, 4);

            Assert.AreEqual(4, hands.Length);
            Assert.AreEqual(13, hands[0].Count);
            Assert.AreEqual(13, hands[1].Count);
            Assert.AreEqual(13, hands[2].Count);
            Assert.AreEqual(13, hands[3].Count);
        }
Beispiel #12
0
        public void Hand_CalcPointsPerSuite()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            IHand h = hands[0];

            Assert.AreEqual(6, h.Spades.Points());
            Assert.AreEqual(1, h.Hearts.Points());
            Assert.AreEqual(3, h.Diamonds.Points());
            Assert.AreEqual(0, h.Clubs.Points());
        }
Beispiel #13
0
        static void Main()
        {
            var isAce = new AceCardSpecification();
            var isHighCard = new HighCardSpecification();
            var isRedCard = new RedSuitSpecification();

            var blackRoyalFlushesCards = isHighCard.Or(isAce).And(isRedCard.Not());

            var royalFlushes = new Deck().Cards
                .Where(card => blackRoyalFlushesCards.IsSatisfiedBy(card))
                .GroupBy(card => card.Suit)
                .Select((royalFlush) => string.Join(", ", royalFlush));

            Console.WriteLine(string.Join(Environment.NewLine, royalFlushes));
        }
Beispiel #14
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.view_cards);

            newDeck = new Deck (2);
            cardList = newDeck.ShuffledList;

            LL = FindViewById<LinearLayout> (Resource.Id.myMain);
            pic = FindViewById<ImageView> (Resource.Id.imageView1);
            picL = FindViewById<ImageView> (Resource.Id.imageViewL);
            picR = FindViewById<ImageView> (Resource.Id.imageViewR);
            var tv = FindViewById<TextView> (Resource.Id.textView1);
            pic.Click += delegate {
                getInfo (pic);
                getInfo (picL);
                getInfo (picR);
                if (count < newDeck.Count) {
                    var card = cardList [count];
                    var id = card.Display;
                    if (count > 0) {
                        var cardL = cardList [count+1];
                        var cardR = cardList [count-1];
                        idL = cardL.Display;
                        idR = cardR.Display;
                    }
                    RunOnUiThread (() => {
                        pic.SetImageResource (id);
                        if (count > 0) {
                            picL.SetImageResource (idL);
                            picR.SetImageResource (idR);
                        }
                        var color = card.Color?"Red":"Black";

                        tv.Text = String.Format ("{0}\n{1}\n{2} - {3} - {4}\n{5}",
                                                 54-count,card.Name, card.Value, card.Suit, color, card.Display);
                    });

                } else {
                    RunOnUiThread (() => pic.SetImageResource (Resource.Drawable.back));
                    count = 0;
                    newDeck = null;
                    newDeck = new Deck (2);
                    cardList = newDeck.ShuffledList;
                    Console.WriteLine ("NEW_GAME");
                }
            };
        }
Beispiel #15
0
        //int height, oldX, oldY, X, Y;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.card_table);

            group = (ViewGroup)FindViewById (Resource.Id.Main);
            ivBottom = FindViewById<ImageView> (Resource.Id.ivBottom);
            ivRight = FindViewById<ImageView> (Resource.Id.ivRight);
            ivTop = FindViewById<ImageView> (Resource.Id.ivTop);
            ivLeft = FindViewById<ImageView> (Resource.Id.ivLeft);
            lp = (RelativeLayout.LayoutParams)ivBottom.LayoutParameters;
            layoutParams = new RelativeLayout.LayoutParams (lp.Width, lp.Height);
            image = new ImageView (this);
            RunOnUiThread (() => {
                image.SetBackgroundResource (Resource.Drawable.blank_small);
                image.SetImageResource (Resource.Drawable.back);
                //image.Click += Remove_OnTouch;
                image.SetOnTouchListener (this);
                image.LayoutParameters = layoutParams;
                group.AddView (image);
            });
            MyAnimationListener.AnimationEnded += AnimationEndedHandler;

            Deck deck = new Deck (0);
            cards = deck.ShuffledStack;
            //card = cards.Pop ();
        }
Beispiel #16
0
        /// <summary>
        /// initialize game and other thigs such as player,graphics animation timer etc
        /// </summary>
        /// <returns></returns>
        public bool Initialize()
        {
            gameDeck = new Deck();

            this.gameStateManager = new GameStateManager(null);
            this.animationTimer.Tick += new EventHandler(animationTimer_Tick);
            this.animationTimer.Interval = 5;

            // initialize graphic class
            //initialize score array to null
            // score array

            // for 5 rounds and 4 player
            float[,] score = new float[5, 4];

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    score[i, j] = 0; // initialize score to null
                }

            }

            gameData.CurrentRound = 1;
            gameData.ActivePlayerId = 0;
            gameData.HandCounter = 0;
            gameData.score = score;
            gameData.HandWinnerID = 0;
            gameData.RoundStarter = 0;
            gameData.GameState = GameState.INTRO;
            gameData.WastePile = new Pile();
            gameData.CurrentPlayerList = new List<player>();
            gameData.CurrentPot = new Pot();
            initializePlayers();
            SpadesGui.Initialize(ref gameData);
            gameData.CurrentPot.PotAdd += new PotAddEventHandler(Pot_PotAdd);
            initializePlayerBoardsPosition();
            return true;
        }
Beispiel #17
0
        /// <summary>
        /// This method initializes PlayerHands  and initializes round
        /// TO DO :: SET ACTIVE PLAYER ID TO START THE ROUND
        /// </summary>
        /// <param name="round">Round Index</param>
        /// <returns></returns>
        public bool startRound(int round)
        {
            gameData.ActivePlayerId = gameData.RoundStarter;
            this.gameRoundStatusLabel.Text = "Round : " + gameData.CurrentRound;
            gameData.HandCounter = 0;
            gameData.CurrentPot.ClearPot();

            gameDeck = new Deck();
            gameDeck.Shuffle();

            Hand[] hand = new Hand[4];

            int counter = 0;
            for (int j = 0; j < 4; j++)
            {
                hand[j] = new Hand();

                for (int i = counter; i < counter + 13; i++)
                {
                    hand[j].AddCard((SpadesCard)gameDeck.CardPile[i]);
                }

                counter = counter + 13;
                hand[j].sort();

            }

            // initialize 4 players hand
            int k = 0;
            foreach (player p in gameData.CurrentPlayerList)
            {
                p.Hand = hand[k];
                k++;
                p.TotalBid = 0;
                p.TotalTrick = 0;
            }

            gameData.GameState = GameState.BIDDING;
            updateGameState(gameData);
            return true;
        }
Beispiel #18
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gameDeck = new Deck();
            playerName = "";
            gameStateManager.switchState(new IntroState(ref playerName));//SpadesPlayer));
            gameStateManager.Process();
            initializePlayerBoardsPosition(); // re position
            int i = 0;
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey("Software\\Games\\CallBreak");
            foreach (player p in gameData.CurrentPlayerList)
            {
                string key = "AIPlayer" + i.ToString();
                if (i == 0) p.Name = playerName;
                else p.Name = regKey.GetValue(key, "AI - I").ToString();
                i++;
            }

            startGame();
        }
Beispiel #19
0
        private static void Stats()
        {
            int maxRoyalFlush = 10;

            Console.Write("Royal Flushes to get: ");
            maxRoyalFlush = Console.ReadLine().ToIntegerOrDefault(-1);

            Deck deck = new Deck();
            deck.CreateDefaultDeck(false);
            deck.Shuffle();

            var cards = deck.Draw(7).ToList();
            int tryCount = 0;

            int highCard = 0;
            int pair = 0;
            int twoPair = 0;
            int threeKind = 0;
            int fullHouse = 0;
            int straight = 0;
            int flush = 0;
            int straightFlush = 0;
            int fourKind = 0;
            int royalFlush = 0;

            DateTime startTime = DateTime.Now;

            while (royalFlush < maxRoyalFlush)
            {
                tryCount++;
                //for (int i = 0; i < cards.Count; i++)
                //{
                //    Console.Write(cards[i].ToString());

                //    if (i < cards.Count - 1)
                //    {
                //        Console.Write(',');
                //    }
                //    else
                //    {
                //        Console.WriteLine();
                //    }
                //}

                switch (Poker.GetHand(cards))
                {
                    case Poker.Hands.Flush:
                        flush++;
                        break;
                    case Poker.Hands.FourKind:
                        fourKind++;
                        break;
                    case Poker.Hands.FullHouse:
                        fullHouse++;
                        break;
                    case Poker.Hands.Pair:
                        pair++;
                        break;
                    case Poker.Hands.RoyalFlush:
                        royalFlush++;
                        break;
                    case Poker.Hands.Straight:
                        straight++;
                        break;
                    case Poker.Hands.StraightFlush:
                        straightFlush++;
                        break;
                    case Poker.Hands.ThreeKind:
                        threeKind++;
                        break;
                    case Poker.Hands.TwoPair:
                        twoPair++;
                        break;
                    case Poker.Hands.HighCard:
                        highCard++;
                        break;
                }

                Console.SetCursorPosition(0, 0);
                Console.WriteLine(string.Format("Pairs: {0} ({1})\r\n2 Pairs: {2} ({3})\r\nPairs of 3: {4} ({5})\r\nPairs of 4: {6} ({7})\r\nFull Houses: {8} ({9})\r\nFlushes: {10} ({11})\r\nStraights: {12} ({13})\r\nStraight Flushes: {14} ({15})\r\nRoyal Flushes: {16} ({17})\r\nHigh Card: {18} ({19})",
                    pair, ((decimal)pair / (decimal)tryCount).ToString("P9"), twoPair, ((decimal)twoPair / (decimal)tryCount).ToString("P9"), threeKind, ((decimal)threeKind / (decimal)tryCount).ToString("P9"), fourKind, ((decimal)fourKind / (decimal)tryCount).ToString("P9"),
                    fullHouse, ((decimal)fullHouse / (decimal)tryCount).ToString("P9"), flush, ((decimal)flush / (decimal)tryCount).ToString("P9"), straight, ((decimal)straight / (decimal)tryCount).ToString("P9"), straightFlush, ((decimal)straightFlush / (decimal)tryCount).ToString("P9"), royalFlush, ((decimal)royalFlush / (decimal)tryCount).ToString("P9"), highCard, ((decimal)highCard / (decimal)tryCount).ToString("P9")));

                deck.Shuffle();
                cards = deck.Draw(7).ToList();
            }

            TimeSpan difference = DateTime.Now - startTime;

            Console.WriteLine(string.Format("Took {0} tries.", tryCount));

            Console.WriteLine(string.Format("Took {0} seconds ({1}/second)", difference.TotalSeconds, ((decimal)tryCount / (decimal)difference.TotalSeconds).ToString("F5")));

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("Pairs: {0} ({1})\r\n2 Pairs: {2} ({3})\r\nPairs of 3: {4} ({5})\r\nPairs of 4: {6} ({7})\r\nFull Houses: {8} ({9})\r\nFlushes: {10} ({11})\r\nStraights: {12} ({13})\r\nStraight Flushes: {14} ({15})\r\nRoyal Flushes: {16} ({17})\r\nHigh Card: {18} ({19})",
                pair, ((decimal)pair / (decimal)tryCount).ToString("P9"), twoPair, ((decimal)twoPair / (decimal)tryCount).ToString("P9"), threeKind, ((decimal)threeKind / (decimal)tryCount).ToString("P9"), fourKind, ((decimal)fourKind / (decimal)tryCount).ToString("P9"),
                fullHouse, ((decimal)fullHouse / (decimal)tryCount).ToString("P9"), flush, ((decimal)flush / (decimal)tryCount).ToString("P9"), straight, ((decimal)straight / (decimal)tryCount).ToString("P9"), straightFlush, ((decimal)straightFlush / (decimal)tryCount).ToString("P9"), royalFlush, ((decimal)royalFlush / (decimal)tryCount).ToString("P9"), highCard, ((decimal)highCard / (decimal)tryCount).ToString("P9")));
            sb.Append("\r\n").Append(string.Format("Took {0} tries.", tryCount)).Append("\r\n");
            sb.Append(string.Format("Took {0} seconds ({1}/second)", difference.TotalSeconds, ((decimal)tryCount / (decimal)difference.TotalSeconds).ToString("F5"))).Append("\r\n\r\n");

            SaveFile(sb.ToString());
        }
Beispiel #20
0
 public void Deck_newDrawsOneContains51Cards()
 {
     Deck deck = new Deck();
     deck.Draw();
     Assert.AreEqual(51, deck.CardsInDeck);
 }
Beispiel #21
0
 void New_Game()
 {
     newDeck = new Deck (0);
     cards = newDeck.ShuffledStack;
     count = 0;
     score = 0;
     RunOnUiThread (() => {
         pic.SetImageResource (Resource.Drawable.back);
         picR.SetImageResource (Resource.Drawable.back);
         tvScore.Text = "0";
     });
 }
 public void TestInitializeValidDeckNotToThrow()
 {
     var deck = new Deck();
 }
Beispiel #23
0
 public void Deck_Empty_ctor_Generates52Cards()
 {
     Deck deck = new Deck();
     Assert.AreEqual(52, deck.CardsInDeck);
 }
Beispiel #24
0
 private void PrepareHands()
 {
     Deck deck = new Deck();
     deck.Shuffle();
     this.myHands = deck.Deal(myGame.NumberPlayers);
     if (deck.Cards.Length > 0) {
         //TODO create a kitty and notify players
     }
     myGame.PlayerControllers.ForEach(pc => pc.HandReady());
 }