/// <summary> /// Picks a card from the CPU's hand. Picks based on ability to beat specified card, then trump, then suit. /// </summary> /// <param name="highest"></param> /// <returns>Returns an acceptable card from the CPU's hand.</returns> public Card pickCard(Card highest) { if (highest == null) return pickCard(); foreach (Card c in hand.getCards()) { if (c.getSuit() == highest.getSuit()) { if (c.compare(highest) > 0) return c; } } foreach (Card c in hand.getCards()) { if (c.compare(highest) > 0) return c; } foreach (Card c in hand.getCards()) { if (c.getSuit() == highest.getSuit()) return c; } return hand.getCards()[0]; }
public void TestCard() { Card card = new Card('H', "10"); //Test for getter methods Assert.IsTrue(card.getFace() == "10", "Card.GetFace() error"); Assert.IsTrue(card.getSuit() == 'H', "Card.GetSuit() error"); //Test for compare for non-trump suits Assert.IsTrue(card.compare(new Card('H', "A")) < 0, "Card.Compare incorrect for greater than."); Assert.IsTrue(card.compare(new Card('C', "9")) > 0, "Card.Compare incorrect for lesser than."); Assert.IsTrue(card.compare(new Card('D', "10")) == 0, "Card.Compare incorrect for equivalent."); Assert.IsTrue(card.compare(new Card('H', "K")) > 0, "Card.Compare incorrect for greater than K."); //Test for trump suits compared to a non-trump suit Assert.IsTrue(card.compare(new Card('S', "10")) < 0, "Card.Compare incorrect for equivalent trump."); Assert.IsTrue(card.compare(new Card('S', "9")) < 0, "Card.Compare incorrect for smaller trump."); Assert.IsTrue(card.compare(new Card('S', "A")) < 0, "Card.Compare incorrect for greater trump."); }