Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the Card class.
 /// </summary>
 /// <param name="CardType">Type of card to create.</param>
 /// <param name="CardSuit">Suit of card to create.</param>
 public Card(CardType CardType, CardSuit CardSuit)
 {
     m_Suit = CardSuit;
     m_Type = CardType;
     m_InternalValue = (int)CardType;
     m_IsHigh = true;
 }
Exemplo n.º 2
0
 public Card(CardSuit suit, CardValue value, Image front, Image back)
 {
     Suit = suit;
     Value = value;
     FrontFace = front;
     BackFace = back;
 }
Exemplo n.º 3
0
        public Card GetCardWithSuitThatEnemyDoesNotHave(bool enemyHasATrumpCard, CardSuit trumpSuit, ICollection<Card> playerCards)
        {
            if (!enemyHasATrumpCard)
            {
                // In case the enemy does not have any trump cards and Stalker has a trump, he should throw a trump.
                var myTrumpCards = playerCards.Where(c => c.Suit == trumpSuit).ToList();
                if (myTrumpCards.Count() > 0)
                {
                    return myTrumpCards.OrderBy(c => c.GetValue()).LastOrDefault();
                }
            }

            var orderedCards = playerCards.OrderBy(c => c.GetValue());
            foreach (var card in orderedCards)
            {
                if (this.cardHolder.EnemyCards.All(c => c.Suit != card.Suit))
                {
                    if (enemyHasATrumpCard)
                    {
                        return playerCards.Where(c => c.Suit == card.Suit).OrderBy(c => c.GetValue()).FirstOrDefault();
                    }

                    return playerCards.Where(c => c.Suit == card.Suit).OrderByDescending(c => c.GetValue()).FirstOrDefault();
                }
            }

            return null;
        }
Exemplo n.º 4
0
        public void CardValueTest(CardValue value1, CardSuit suit1, CardValue value2, CardSuit suit2, int expected)
        {
            Card card1 = new Card(value1, suit1);
            Card card2 = new Card(value2, suit2);

            Assert.AreEqual(expected, card1.CompareTo(card2));
        }
        public ICollection<Card> GetOpponentCards(ICollection<Card> myCards, ICollection<Card> playedCards, Card activeTrumpCard, CardSuit suit)
        {
            var playerCards = new CardCollection
                                  {
                                      new Card(suit, CardType.Nine),
                                      new Card(suit, CardType.Jack),
                                      new Card(suit, CardType.Queen),
                                      new Card(suit, CardType.King),
                                      new Card(suit, CardType.Ten),
                                      new Card(suit, CardType.Ace),
                                  };

            foreach (var card in myCards.Where(x => x.Suit == suit))
            {
                playerCards.Remove(card);
            }

            foreach (var card in playedCards.Where(x => x.Suit == suit))
            {
                playerCards.Remove(card);
            }

            if (activeTrumpCard != null)
            {
                playerCards.Remove(activeTrumpCard);
            }

            return playerCards;
        }
Exemplo n.º 6
0
 // Обращение к карте по ее типу и масти
 public Card this[CardType type, CardSuit suit]
 {
     get
     {
         return list.Find(c => (c.Type == type) && (c.Suit == suit));
     }
 }
Exemplo n.º 7
0
 // Метод создания бонуса - ему присваиваются тип, младшая карта, а также опционно для бонусов типа "последовательность" - масть
 public Bonus(BonusType Type, CardType HighCard, bool IsTrump, CardSuit Suit = CardSuit.C_NONE)
 {
     this.Type = Type;
     this.HighCard = HighCard;
     this.Suit = Suit;
     this.IsTrump = IsTrump;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Card"/> class.
 /// </summary>
 /// <param name="cardIndex">Index of the card.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="sequenceNumber">The sequence number.</param>
 public Card(int cardIndex, CardMode mode, int sequenceNumber)
 {
     this._suit = GetSuitFromCardIndex(cardIndex, mode);
     this._rank = GetRankFromIndex(cardIndex, mode);
     this._sequence = sequenceNumber;
     this._cardIndex = cardIndex;
 }
Exemplo n.º 9
0
 public Order(OrderType Type, int Size, CardSuit Trump)
 {
     this.Type = Type;
     this.Size = Size;
     this.Trump = Trump;
     this.Team = BeloteTeam.TEAM_NONE;
 }
Exemplo n.º 10
0
 public static ICard Of(CardSuit cardSuit)
 {
     var jack = new Jack
     {
         _CardSuit = cardSuit
     };
     return jack;
 }
Exemplo n.º 11
0
 public Card(CardSuit suit, CardRank rank, Image frontImage) : this(suit, rank)
 {
     this.FrontImage = frontImage;
     //Can we make it to private readonly or const?
     this.BackCardPath = "..\\..\\Resources\\Cards\\Back.png";
     this.BackImage = Image.FromFile(BackCardPath);
     this.CardPictureBox = new PictureBox();
 }
Exemplo n.º 12
0
        private double GetFailureProbabilityForSuit(int cards, int discards, CardSuit suit)
        {
            int cardSet = BitwiseCardHelper.GetCardSet(cards, suit);
            int discardsCount = BitwiseCardHelper.GetSuitCount(discards, suit);
            int otherSuitsDistribution = CardSuitDistribution.GetDistribution(cards, discards, suit);

            return MisereProbabilities.GetFailureProbability(cardSet, discardsCount, otherSuitsDistribution, IsFirstHand);
        }
Exemplo n.º 13
0
 public static ICard Of(CardSuit cardSuit)
 {
     var king = new King
     {
         _CardSuit = cardSuit
     };
     return king;
 }
Exemplo n.º 14
0
 public Card( int rank, CardSuit suit, CardOrientation orientation = CardOrientation.FaceDown )
 {
     if ( rank < (int)CardRank.Ace || rank > (int)CardRank.King )
      {
     throw new ArgumentException( "Invalid card rank" );
      }
      InitCard( (CardRank) rank, suit, orientation );
 }
Exemplo n.º 15
0
 /// <summary>
 /// checks the hand if it has the passed suit or not
 /// </summary>
 /// <param name="suit">Suit of the card to check.</param>
 /// <param name="hand">Hand of the player to check in.</param>
 /// <returns></returns>
 public static bool hasSuit(CardSuit suit, Hand hand)
 {
     foreach (SpadesCard card in hand.CardPile)
     {
         if (Card.SuitFromCardIndex(card.CardIndex) == suit) return true;
     }
     return false;
 }
Exemplo n.º 16
0
Arquivo: Deck.cs Projeto: Adamsons/21
 private Card CreateCard(int value, CardSuit suit, CardType type)
 {
     return new Card()
     {
         Value = value,
         Suit = suit,
         Type = type
     };
 }
Exemplo n.º 17
0
        public void ChangeTrumpCardTest(CardSuit suit, CardType type)
        {
            var newCard = new Card(suit, type);
            var deck = new Deck();

            deck.ChangeTrumpCard(newCard);

            Assert.AreNotEqual(0, deck.CardsLeft, "Change card doesn't work");
        }
Exemplo n.º 18
0
        public Bid(int tricks, CardSuit? trump)
            : this(BidType.Tricks)
        {
            if ((tricks < 6) || (tricks > 10))
                throw new ArgumentOutOfRangeException("tricks");

            mTricks = tricks;
            mTrump = trump;
        }
Exemplo n.º 19
0
 protected Card(Game game, int id, CardType type, CardSuit suit, CardRank rank)
 {
     this.game = game;
     this.id = id;
     this.type = type;
     this.suit = suit;
     this.rank = rank;
     color = GetColor(type);
     empty = new EmptyCard(this);
 }
Exemplo n.º 20
0
 /// <summary>
 /// constructor of spades card
 /// </summary>
 /// <param name="i">Card Index</param>
 public SpadesCard(int i)
     : base()
 {
     if (i < 0 || i > 52)
     {
         throw new ApplicationException("Wrong value for card initilization.");
     }
        _cardindex = i;
        Suit = Card.SuitFromCardIndex(i);
        Rank = Card.RankFromCardIndex(i);
 }
Exemplo n.º 21
0
 public PlayingCardWidget(int id, CardType type, CardRank rank, CardSuit suit)
 {
     layout = new Pango.Layout(Gdk.PangoHelper.ContextGet());
     layout.FontDescription = Pango.FontDescription.FromString("Angleterre Book, Librarian bold 32");
     this.id = id;
     this.type = type;
     this.rank = rank;
     this.suit = suit;
     Card = CardManager.GetCard(type);
     UpdateMarkup();
 }
Exemplo n.º 22
0
 public void EqualsShouldWorkCorrectly(
     bool expectedValue,
     CardSuit firstCardSuit,
     CardType firstCardType,
     CardSuit secondCardSuit,
     CardType secondCardType)
 {
     var firstCard = new Card(firstCardSuit, firstCardType);
     var secondCard = new Card(secondCardSuit, secondCardType);
     Assert.AreEqual(expectedValue, firstCard.Equals(secondCard));
     Assert.AreEqual(expectedValue, secondCard.Equals(firstCard));
 }
Exemplo n.º 23
0
 /* Helper method to convert CardSuit enum value into a char */
 public static Char CardSuitToChar(CardSuit s)
 {
     switch (s)
     {
         case CardSuit.Spades: return 'S';
         case CardSuit.Clubs: return 'C';
         case CardSuit.Diamonds: return 'D';
         case CardSuit.Hearts: return 'H';
         default:
             Trace.Assert(false, "Invalid cardsuit detected during conversion to char: " + s);
             return 'H'; // Never to be executed
     }
 }
Exemplo n.º 24
0
 // Метод создания бонуса - ему присваиваются тип, младшая карта, а также опционно для бонусов типа "последовательность" - масть
 public Bonus(BonusType Type, CardType HighCard, bool IsTrump, CardSuit Suit = CardSuit.C_NONE)
 {
     Cards = new BaseCardList();
     this.Type = Type;
     this.HighCard = HighCard;
     this.Suit = Suit;
     this.IsTrump = IsTrump;
     Cost = CalculateCost();
     #if DEBUG
     Debug.WriteLine("{0} Создан бонус: Тип - {1}, Старшая карта - {2}, Масть - {3}, Козырь - {4}, Стоимость - {5}",
         DateTime.Now.ToString(), Type, HighCard, Suit, IsTrump, Cost);
     #endif
 }
Exemplo n.º 25
0
 public void TestChangeTrumpCardShouldProperlyUpdateBothTrumpCardAndDeckTopCard(CardSuit suit, CardType type)
 {
     Deck deck = new Deck();
     Card newTrumpCard = new Card(suit, type);
     deck.ChangeTrumpCard(newTrumpCard);
     int cardsCount = deck.CardsLeft;
     Card topCard = deck.GetNextCard();
     for (int i = 1; i < cardsCount; i++)
     {
         topCard = deck.GetNextCard();
     }
     Assert.AreEqual(topCard, newTrumpCard);
 }
Exemplo n.º 26
0
        public int HowMuchTrumpsAreInPlay(CardSuit trumpSuit)
        {
            int count = 0;

            for (int j = 0; j < 6; j++)
            {
                if (usedCards[(int)trumpSuit, j] == false)
                {
                    count++;
                }
            }

            return count;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Generates all 13 cards of the same suit
        /// </summary>
        /// <param name="suit"></param>
        /// <returns></returns>
        protected Deck SingleSuit(CardSuit suit)
        {
            Deck ToReturn = new Deck();
            Card ToAdd;

            for(int i = 0; i < 13; i++)
            {
                ToAdd = new Card(suit, (CardValue)i);
                ToReturn.Add(ToAdd);
                if (i == 0) ToReturn.FirstCard = ToAdd;
                if (i == 13) ToReturn.LastCard = ToAdd;
            }

            return ToReturn;
        }
Exemplo n.º 28
0
        public static string ConvertToString(CardSuit cardSuit)
        {
            switch (cardSuit)
            {
                case CardSuit.Spades:
                    return "s";
                case CardSuit.Hearts:
                    return "h";
                case CardSuit.Diamonds:
                    return "d";
                case CardSuit.Clubs:
                    return "c";
            }

            throw Utility.GetUnknownEnumValueException(cardSuit);
        }
Exemplo n.º 29
0
        public void IsTwoPairTestValid(CardFace face1, CardSuit suit1, CardFace face2, CardSuit suit2, CardFace face3, CardSuit suit3, CardFace face4, CardSuit suit4, CardFace face5, CardSuit suit5)
        {
            // Didn't found better way to implement many cards with NUnit
            var cards = new List<ICard>()
            {
                new Card(face1, suit1),
                new Card(face2, suit2),
                new Card(face3, suit3),
                new Card(face4, suit4),
                new Card(face5, suit5),
            };

            var hand = new Hand(cards);

            Assert.IsTrue(this.checker.IsOnePair(hand));
        }
Exemplo n.º 30
0
 private string CheckCardSuite(CardSuit cardSuit)
 {
     switch (cardSuit)
     {
         case CardSuit.Clubs:
             return "♣"; break;
         case CardSuit.Diamonds:
             return "♦"; break;
         case CardSuit.Hearts:
             return "♥"; break;
         case CardSuit.Spades:
             return "♠"; break;
         default:
             throw new ArgumentException("Invalid Card suite!"); break;
     }
 }
Exemplo n.º 31
0
 public IncompatibleCardSuitException(CardSuit expectedSuit, CardSuit actualSuit)
     : base($"Card has incompatible suit. Expected: {expectedSuit}, actual: {actualSuit}")
 {
     ExpectedSuit = expectedSuit;
     ActualSuit   = actualSuit;
 }
Exemplo n.º 32
0
 public override Card GetCard(CardFigure figure, CardSuit suit)
 {
     return(new GraphicCard(figure, suit));
 }
Exemplo n.º 33
0
 public Card OfHearts()
 {
     this.Suit = CardSuit.Hearts;
     return(this);
 }
Exemplo n.º 34
0
 public Card(CardRank rank, CardSuit suit)
 {
     Rank = rank;
     Suit = suit;
 }
Exemplo n.º 35
0
 public Card(int id, CardSuit suit, int value)
 {
     Id    = id;
     Suit  = suit;
     Value = value;
 }
Exemplo n.º 36
0
 /// <summary>
 /// Returns true if this suit is the same suit as the provided suit.
 /// </summary>
 /// <param name="s">The suit to compare with.</param>
 /// <returns>Returns true if the two suits are the same and false otherwise.</returns>
 public bool Equals(CardSuit s)
 {
     return(ToString() == s.ToString());
 }
Exemplo n.º 37
0
 // Constructor
 public Card(CardKind kind, CardSuit suit)
 {
     mSuit = suit;
     mKind = kind;
 }
Exemplo n.º 38
0
 public Card OfSpades()
 {
     this.Suit = CardSuit.Spades;
     return(this);
 }
Exemplo n.º 39
0
 public Card(CardSuit suit, CardRank rank)
 {
     this.suit = suit;
     this.rank = rank;
 }
Exemplo n.º 40
0
 public Card(int value, CardSuit suite) : this(unchecked ((char)value), suite)
 {
 }
Exemplo n.º 41
0
 public Card(byte value, CardSuit suite) : this((char)value, suite)
 {
 }
Exemplo n.º 42
0
 public Card(CardValue value, CardSuit suit)
 {
     Value     = value;
     Suit      = suit;
     CardValue = (int)Value;
 }
Exemplo n.º 43
0
 public Card(CardRank rank, CardSuit suit)
 {
     this.Suit  = suit;
     this.Rank  = rank;
     this.Power = (int)suit + (int)rank;
 }
Exemplo n.º 44
0
 public Card(string rank, string suit)
 {
     this.rank = this.GetRankIfValid(rank);
     this.suit = this.GetSuitIfValid(suit);
 }
Exemplo n.º 45
0
 public Card OfDiamonds()
 {
     this.Suit = CardSuit.Diamonds;
     return(this);
 }
Exemplo n.º 46
0
        public HandType GetHandType()
        {
            if (Cards.Count < MaxCardsInHand)
            {
                return(HandType.Undefined);
            }
            if (_handType == HandType.Undefined)
            {
                int[] values = new int[_handHistogram.Values.Count];
                _handHistogram.Values.CopyTo(values, 0);
                Array.Sort(values);
                int maxRankCount = values[values.Length - 1];

                // Check if the hand is quads or boat
                if (_handHistogram.Count < 3)
                {
                    if (maxRankCount == 4)
                    {
                        return(HandType.FourOfAKind);
                    }
                    else
                    {
                        return(HandType.FullHouse);
                    }
                }
                else if (_handHistogram.Count == 3)
                {
                    if (maxRankCount == 3)
                    {
                        return(HandType.ThreeOfAKind);
                    }
                    else
                    {
                        return(HandType.TwoPair);
                    }
                }
                else if (_handHistogram.Count == 4)
                {
                    return(HandType.OnePair);
                }

                bool isFlush    = false;
                bool isStraight = false;
                // Check if the hand is flush
                CardSuit firstCardSuit = Cards[0].Suit;
                int      sameSuitCount = 0;
                foreach (Card card in Cards)
                {
                    if (card.Suit == firstCardSuit)
                    {
                        sameSuitCount++;
                    }
                }
                isFlush = (sameSuitCount == Cards.Count);

                Card[] cardsArray = new Card[Cards.Count];
                Cards.CopyTo(cardsArray, 0);
                Array.Sort(cardsArray);

                // Check if the hand is straight
                CardValue topCardRank          = cardsArray[MaxCardsInHand - 1].Value;
                CardValue nextToTheTopCardRank = cardsArray[MaxCardsInHand - 2].Value;
                CardValue bottomCardRank       = cardsArray[0].Value;
                if ((nextToTheTopCardRank == CardValue.Five &&
                     topCardRank == CardValue.Ace &&
                     nextToTheTopCardRank - bottomCardRank == 3) ||
                    (topCardRank - bottomCardRank == 4))
                {
                    isStraight = true;
                }
                if (isStraight && isFlush)
                {
                    return(HandType.StraightFlush);
                }
                else if (isStraight)
                {
                    return(HandType.Straight);
                }
                else if (isFlush)
                {
                    return(HandType.Flush);
                }
                _handType = HandType.HighCard;
            }
            return(_handType);
        }
 public Card(CardName name, CardSuit suit)
 {
     _name = name;
     _suit = suit;
 }
Exemplo n.º 48
0
        /// <summary>
        /// Funkcja liczaca ktory z graczy wygral lewe.
        /// </summary>
        /// <returns>Numer gracza ktory wygral lewe.</returns>
        static public int TrickWinner(Card first, Card second, Card third, Card fourth, CardSuit trump, int wistNumber)
        {
            Card        winnerCard;
            int         winnerIndex = 1;
            List <Card> trickCards  = new List <Card>();

            // 1 2 3 4 1 2 3 <- dzieki temu nie musze sie bawic w sprawdzanie
            trickCards.Add(first); trickCards.Add(second); trickCards.Add(third); trickCards.Add(fourth); trickCards.Add(first); trickCards.Add(second); trickCards.Add(third);

            winnerIndex = CompareCards(trickCards[wistNumber - 1], trickCards[wistNumber], trump, out winnerCard) ? wistNumber : wistNumber + 1;
            winnerIndex = CompareCards(winnerCard, trickCards[wistNumber + 1], trump, out winnerCard) ? winnerIndex : wistNumber + 2;
            winnerIndex = CompareCards(winnerCard, trickCards[wistNumber + 2], trump, out winnerCard) ? winnerIndex : wistNumber + 3;

            //zrob modulo zeby wynik byl w przedziale [1,4]
            return((winnerIndex - 1) % 4 + 1);
        }
Exemplo n.º 49
0
 public Card(CardNumber cardNumber, CardSuit cardSuit)
 {
     CardNumber = cardNumber;
     CardSuit   = cardSuit;
 }
Exemplo n.º 50
0
 public Card(int value, int gameValue, CardSuit suit)
 {
     this.Value     = value;
     this.Suit      = suit;
     this.GameValue = gameValue;
 }
Exemplo n.º 51
0
 public Card(CardRank Rank, CardSuit Suit)
 {
     this._rank = Rank;
     this._suit = Suit;
 }
Exemplo n.º 52
0
 public Card OfClubs()
 {
     this.Suit = CardSuit.Clubs;
     return(this);
 }
Exemplo n.º 53
0
 public Card(int id, CardSuit suit)
 {
     _id   = id;
     _suit = suit;
 }
Exemplo n.º 54
0
 public Card(CardType type, CardSuit suit)
     : this()
 {
     this.Type = type;
     this.Suit = suit;
 }
Exemplo n.º 55
0
 public Card(CardSuit aSuite, CardValue aValue)
 {
     suit  = aSuite;
     value = aValue;
 }
Exemplo n.º 56
0
 public Card(CardSuit suit, CardType type)
 {
     this.Suit = suit;
     this.Type = type;
 }
Exemplo n.º 57
0
 private Card(CardSuit suit, CardValue value, bool isFaceDown)
 {
     Suit       = suit;
     Value      = value;
     IsFaceDown = isFaceDown;
 }
Exemplo n.º 58
0
 public Card(CardSuit suit, CardValue value)
 {
     Suit  = suit;
     Value = value;
 }
Exemplo n.º 59
0
 public Card(CardFace face, CardSuit suit)
 {
     this.Face = face;
     this.Suit = suit;
 }
Exemplo n.º 60
0
 public Card(CardSuit s, int cardNum)
 {
     this.Suit   = s;
     this.Number = cardNum;
 }