Exemple #1
0
        public void TestCPUPick()
        {
            List<Card> cards = new List<Card>();
            Card c = new Card('H', "10");
            cards.Add(c);
            Card c1 = new Card('C', "K");
            cards.Add(c1);
            Card c2 = new Card('D', "K");
            cards.Add(c2);
            Card c3 = new Card('S', "9");
            cards.Add(c3);

            Hand hand = new Hand(cards);
            CPU cpu = new CPU();
            cpu.hand = hand;

            Assert.AreEqual(cpu.pickCard().compare(c), 0, "Pick() not default to index 0.");

            Assert.AreEqual(cpu.pickCard(new Card('H', "9")), c, "Pick(higher) not correct for H9.");
            Assert.AreEqual(cpu.pickCard(new Card('C', "J")), c1, "Pick(higher) not correct for CJ.");
            Assert.AreEqual(cpu.pickCard(new Card('S', "K")), c3, "Pick(higher) not correct for SK.");
            Assert.AreEqual(cpu.pickCard(new Card('C', "A")), c3, "Pick(higher) not correct for CA.");

            cpu.hand.removeCard(c3);
            cpu.hand.removeCard(c2);

            Assert.AreEqual(cpu.pickCard(new Card('D', "9")), c, "Pick(higher) not correct for D9.");
        }
Exemple #2
0
        /// <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];
        }
Exemple #3
0
        /// <summary>
        /// Removes a specified card from the hand.
        /// </summary>
        /// <param name="card"></param>
        /// <returns>True if successful, False if not.</returns>
        public bool removeCard(Card card)
        {
            if (cards.Contains(card))
            {
                cards.Remove(card);
                return true;
            }

            return false;
        }
Exemple #4
0
 /// <summary>
 /// Compares the card to another card.
 /// </summary>
 /// <param name="card"></param>
 /// <returns>Returns -1 if smaller than card, 0 if equal to card, and 1 if greater than card. Takes into account trump suit 'S'</returns>
 public int compare(Card card)
 {
     if (suit.Equals('S') && !card.suit.Equals('S'))
         return 1;
     else if (!suit.Equals('S') && card.suit.Equals('S'))
         return -1;
     else
     {
         try
         {
             return indexOf(face) - indexOf(card.face);
         }
         catch(Exception e)
         {
             throw new Exception("Index Error");
         }
     }
 }
Exemple #5
0
        public void TestDrawHand()
        {
            List<Card> cards = new List<Card>();
            Card c = new Card('H', "10");
            cards.Add(c);
            Card c1 = new Card('C', "K");
            cards.Add(c1);
            Card c2 = new Card('D', "K");
            cards.Add(c2);
            Card c3 = new Card('S', "9");
            cards.Add(c3);

            Hand hand = new Hand(cards);
            Board board = new Board();
            board.clearButtons();
            board.drawHand(hand);

            List<Button> buttons = board.getHand();

            Assert.IsTrue(buttons[0].Text.Length > 0, "Button 0 card not loaded.");
            Assert.IsTrue(buttons[1].Text.Length > 0, "Button 1 card not loaded.");
            Assert.IsTrue(buttons[2].Text.Length > 0, "Button 2 card not loaded.");
            Assert.IsTrue(buttons[3].Text.Length > 0, "Button 3 card not loaded.");
            Assert.IsTrue(buttons[4].Text.Length == 0, "Button 4 card loaded.");
            Assert.IsTrue(buttons[5].Text.Length == 0, "Button 5 card loaded.");

            cards.Add(c3);
            cards.Add(c3);

            hand = new Hand(cards);
            board.drawHand(hand);
            buttons = board.getHand();

            Assert.IsTrue(buttons[5].Text.Length > 0, "Button 5 card not loaded.");

            cards.Clear();

            hand = new Hand(cards);
            board.drawHand(hand);
            buttons = board.getHand();

            Assert.IsTrue(buttons[0].Text.Length == 0, "Button 0 wrongly loaded.");
            Assert.IsTrue(buttons[5].Text.Length == 0, "Button 5 wrongly loaded.");
        }
Exemple #6
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.");
        }
Exemple #7
0
        public void TestHand()
        {
            List<Card> cards = new List<Card>();
            Card c = new Card('H', "10");
            cards.Add(c);
            Card c1 = new Card('A', "9");
            cards.Add(c1);
            Card c2 = new Card('D', "K");
            cards.Add(c2);
            Hand hand = new Hand(cards);

            //Test to make sure all cards made it into the hand.
            Assert.IsTrue(hand.getCards().Contains(c), "Hand.GetCards.Contains failed for first card.");
            Assert.IsTrue(hand.getCards().Contains(c1), "Hand.GetCards.Contains failed for second card.");
            Assert.IsTrue(hand.getCards().Contains(c2), "Hand.GetCards.Contains failed for third card.");

            //Test to make sure a removed item no longer exists, but the others still do.
            hand.removeCard(c);
            Assert.IsTrue(hand.getCards().Contains(c) == false, "Hand.GetCards.Contains failed for removed card.");
            Assert.IsTrue(hand.getCards().Contains(c1), "Hand.GetCards.Contains failed for first remaining card.");
            Assert.IsTrue(hand.getCards().Contains(c2), "Hand.GetCards.Contains failed for second remaining card.");
        }
Exemple #8
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (button6.Text.Length > 0)
            {
                if (button6.Text.Length == 3)
                    card = new Card(button6.Text[0], button6.Text[1].ToString() + button6.Text[2].ToString());
                else
                    card = new Card(button6.Text[0], button6.Text[1].ToString());

                picked = true;
                disenableCards();
                this.Close();
            }
        }
Exemple #9
0
 public void removeCard(Card card)
 {
     throw new System.NotImplementedException();
 }
Exemple #10
0
 public void addToField(Card card)
 {
     field.Add(card);
 }
Exemple #11
0
 /// <summary>
 /// Removes the card from the CPU's hand.
 /// </summary>
 /// <param name="card"></param>
 public void pickAccepted(Card card)
 {
     hand.removeCard(card);
 }