Exemple #1
0
        public void TestCase1()
        {
            Card card1 = new Card (Rank.Ace, Suit.Spades);
            Card card2 = new Card (Rank.Eight, Suit.Spades);
            Card card3 = new Card (Rank.Ace, Suit.Hearts);
            Card card4 = new Card (Rank.Ace, Suit.Spades);

            Assert.AreNotEqual (card1, card2);
            Assert.AreNotEqual (card1, card3);
            Assert.AreEqual (card1, card4);
        }
Exemple #2
0
 public void HighPointTests()
 {
     Card ace = new Card(Rank.Ace, Suit.Spades);
     Card king = new Card(Rank.King, Suit.Hearts);
     Card queen = new Card(Rank.Queen, Suit.Spades);
     Card jack = new Card(Rank.Jack, Suit.Hearts);
     Card ten = new Card(Rank.Ten, Suit.Spades);
     Card nine = new Card(Rank.Nine, Suit.Hearts);
     Card[] cards = new Card[]{ace, king, queen, jack, ten, nine};
     Assert.AreEqual(cards.HighCardPoints(), 10);
     Assert.AreEqual(cards.HighCardPoints(Suit.Hearts), 4);
     Assert.AreEqual(cards.HighCardPoints(Suit.Spades), 6);
     Assert.AreEqual(cards.HighCardPoints(Suit.Clubs), 0);
     Assert.AreEqual((new Card[]{}).HighCardPoints(), 0);
     Assert.AreEqual(cards.HighestInSuit(Suit.Hearts).Rank, Rank.King);
     Assert.AreEqual(cards.HighestInSuit(Suit.Spades).Rank, Rank.Ace);
     Assert.AreEqual(cards.LongestSuit(), Suit.Spades);
 }
Exemple #3
0
 public Seat WhoPlayed(Card card)
 {
     if (!_cards.Contains(card))
         throw new Exception("Card is not in this trick");
     return _players[_cards.IndexOf(card)];
 }
Exemple #4
0
 public bool IsLegalPlay(Card card, Hand hand)
 {
     return !Done && (IsEmpty ||
                      Suit == card.Suit ||
                      hand.VoidOfSuit(Suit));
 }
Exemple #5
0
        public void AddCard(Card card, Seat player)
        {
            if (Done)
                throw new Exception("Trick is done, cannot add more cards.");
            if (_cards.Contains(card))
                throw new Exception("Card is already in the trick.");

            //FIXME - add check for player has already played
            //FIXME - add check for card is added by the right player (clockwise around table)

            _cards.Add(card);
            _players.Add(player);

            _winner = GetWinner();
            if (Suit == Suit.None)
                Suit = card.Suit;
        }
Exemple #6
0
 public bool Trumps(Card other, Suit trump)
 {
     //a trump doesn't trump a trump (two trumps will be compared by rank)
     return this.Suit == trump && other.Suit != trump;
 }
Exemple #7
0
 public bool HasSameSuitAs(Card other)
 {
     return this.Suit == other.Suit;
 }
Exemple #8
0
 public bool HasGreaterRankThan(Card other)
 {
     return this.Rank > other.Rank;
 }
Exemple #9
0
 public bool Beats(Card other, Suit trump)
 {
     return this.Trumps(other, trump) ||
           (this.HasSameSuitAs(other) && this.HasGreaterRankThan(other));
 }
Exemple #10
0
 public bool Contains(Card card)
 {
     return _cards.Contains(card);
 }
Exemple #11
0
 //tests: Must be a card (enforced by compiler), must be unique, cannot add more than 13
 private void Add(Card card)
 {
     if (_cards.Contains(card))
         throw new ArgumentException("The card is already in the hand","card");
     if (_cards.Count == MaxSize)
         throw new InvalidOperationException("Cannot add more than "+MaxSize+" cards to the hand.");
     _cards.Add(card);
 }
Exemple #12
0
 public void Remove(Card card)
 {
     if (!_cards.Contains(card))
         throw new ArgumentException("The card is not in the hand","card");
     _cards.Remove(card);
 }