예제 #1
0
        public GameData(int opponents, int numDecks)
        {
            _opponentsHand = new CrazyEightsHand[opponents];
            for (int i = 0; i < opponents; i++)
            {
                _opponentsHand[i] = new CrazyEightsHand();
            }

            deckManager = new CrazyEightDeckManager(numDecks);
        }
예제 #2
0
        private static MoveInfo GetCardChoice(CrazyEightDeckManager deckManager, CrazyEightsHand hand, CardSuit wildSuit)
        {
            // super simple rules here
            // 1. Check top card of table
            // 2. Check for Crazy 8
            // 3. Find number of rank matches
            // 4. Find number of suit matches
            // 5. if( have crazy eight ) then
            //      play crazy eight
            //    else if( rank matches > suit matches ) then
            //      play matching rank
            //    else if( suit matches > rank matches ) then
            //      play matching suit
            //    else
            //      play random matching suit or rank
            MoveInfo info = new MoveInfo();

            info.DrawCard = false;
            info.WildCardUsed = false;
            info.SelectedCard = null;

            Card topCard = deckManager.Table[deckManager.Table.Count - 1];

            CardSuit matchSuit = wildSuit == CardSuit.None ? topCard.Suit : wildSuit;
            Card eightCard = hand.FindEight();
            Card duece = hand.FindRank(CardRank.Two);

            // rules change if top card is an eight
            if (topCard.Rank == CardRank.Eight)
            {
                // if we can match rank, do so
                // that will force a play of an eight
                if (eightCard != null)
                {
                    info.SelectedCard = eightCard;
                }
                else if (hand.GetSuitCount(matchSuit) > 0)
                {
                    // get matching suit (order by rank)
                    info.SelectedCard = hand.Cards.Where(c => c.Suit == matchSuit).OrderBy(c1 => c1.Rank).FirstOrDefault();
                }
                else
                {
                    info.DrawCard = true;
                }
            }
            else if (topCard.Rank == CardRank.Two && duece != null)
            {
                // play the duece on a draw two
                info.SelectedCard = duece;
            }
            else
            {
                // get suit count, without eights
                var suitCount = hand.Cards.Count(c => c.Suit == matchSuit && c.Rank != CardRank.Eight);
                var rankCount = hand.Cards.Count(c => c.Rank == topCard.Rank);

                // no eight, free to play as you wish
                if (suitCount > rankCount)
                {
                    // get matching suit (order by rank)
                    info.SelectedCard =
                        hand.Cards
                        .Where(c => c.Suit == matchSuit && c.Rank != CardRank.Eight)
                        .OrderBy(c1 => c1.Rank)
                        .FirstOrDefault();
                }
                else if (rankCount > 0)
                {
                    // get matching rank
                    info.SelectedCard =
                        hand.Cards
                        .Where(c => c.Rank == topCard.Rank)
                        .FirstOrDefault();
                }
                else
                {
                    // no matches above
                    // see if we have an eight
                    if (hand.Cards.Count(c => c.Rank == CardRank.Eight) > 0)
                    {
                        // get first eight
                        info.SelectedCard = hand.Cards.Where(c => c.Rank == CardRank.Eight).FirstOrDefault();
                    }
                    else
                    {
                        info.DrawCard = true;
                    }
                }
            }

            if (info.SelectedCard != null)
            {
                if (info.SelectedCard.Rank == CardRank.Eight)
                {
                    info.WildCardUsed = true;
                    info.OverrideSuit = SelectOverrideSuit(hand);
                }
            }

            return info;
        }
예제 #3
0
        private static CardSuit SelectOverrideSuit(CrazyEightsHand hand)
        {
            CardSuit overrideSuit = CardSuit.Diamonds;

            int clubCount = hand.GetSuitCount(CardSuit.Clubs);
            int heartCount = hand.GetSuitCount(CardSuit.Hearts);
            int spadeCount = hand.GetSuitCount(CardSuit.Spades);
            int diamondCount = hand.GetSuitCount(CardSuit.Diamonds);

            if (clubCount >= heartCount && clubCount >= spadeCount && clubCount >= diamondCount)
            {
                overrideSuit = CardSuit.Clubs;
            }
            else if (heartCount >= clubCount && heartCount >= spadeCount && heartCount >= diamondCount)
            {
                overrideSuit = CardSuit.Hearts;
            }
            else if (spadeCount >= clubCount && spadeCount >= heartCount && spadeCount >= diamondCount)
            {
                overrideSuit = CardSuit.Spades;
            }
            else if (diamondCount >= clubCount && diamondCount >= heartCount && diamondCount >= spadeCount)
            {
                overrideSuit = CardSuit.Diamonds;
            }

            return overrideSuit;
        }
예제 #4
0
 internal static MoveInfo EvaluateMove(CrazyEightDeckManager deckManager, CrazyEightsHand hand, CardSuit wildSuit)
 {
     return GetCardChoice(deckManager, hand, wildSuit);
 }
예제 #5
0
        private void PlayCard(Card cardToPlay, CrazyEightsHand hand)
        {
            // put card onto table
            _data.DeckManager.Table.Add(cardToPlay);

            // remove from player hand
            //_data.OpponentsHands[_currentPlayer - 1].Cards.Remove(cardToPlay);
            hand.Cards.Remove(cardToPlay);

            if (_undoPointer < _lastCardsPlayed.Count - 1)
            {
                // prune list past _redoPointer
                _lastCardsPlayed.RemoveRange(_undoPointer + 1, _lastCardsPlayed.Count - (_undoPointer + 1));
            }

            _lastCardsPlayed.Add(cardToPlay);
            _undoPointer = _lastCardsPlayed.Count - 1;

            if (cardToPlay.Rank == CardRank.Ace)
            {
                if (_direction == Hand.PlayDirection.Forward)
                {
                    _direction = Hand.PlayDirection.Reverse;
                }
                else
                {
                    _direction = Hand.PlayDirection.Forward;
                }
            }
            else if (cardToPlay.Rank == CardRank.Two && !_data.DeckManager.IsEmpty)
            {
                _playerHasDrawn = false;

                // increment the two's count
                _dueceCount++;

                // draw two
                int nextPlayer = NextPlayer();

                // get hand of next player
                CrazyEightsHand nextPlayerHand = null;
                if (nextPlayer == 0)
                {
                    nextPlayerHand = _data.PlayerHand;
                }
                else
                {
                    nextPlayerHand = _data.OpponentsHands[nextPlayer - 1];
                }

                if (nextPlayerHand.Cards.Find(c => c.Rank == CardRank.Two) == null)
                {
                    _lastDrawnCards.Clear();

                    for (int i = 0; i < _dueceCount; i++)
                    {
                        Card drawCard;

                        DrawCard(nextPlayer, out drawCard);

                        _lastDrawnCards.Add(drawCard);

                        DrawCard(nextPlayer, out drawCard);

                        _lastDrawnCards.Add(drawCard);
                    }

                    _playerHasDrawn = true;

                    // if next is player and player doesn't have any two's
                    if (nextPlayer == 0)
                    {
                        ShowDrawTwoDialog();
                    }

                    _dueceCount = 0;
                }
            }
            else if (cardToPlay.Rank == CardRank.Queen)
            {
                // trick here, increment player so when
                // we increment next player, it will skip
                _skipFlag = true;
            }

            //_redoPointer = _lastCardsPlayed.Count;
        }