/// <summary> /// The method sort the card in the hand by suit and in ascending order per suit type. /// </summary> public void Sort() { int counter = 0; for (int i = 0; i <= 3; i++) { List <Card> suit = cards.Where(card => card.Suit == (Suit)i).ToList(); CardsEvaluator.ArrageCardsFacevalue(suit); foreach (Card card in suit) { cards.Remove(card); } for (int c = 0; c < suit.Count; c++) { cards.Insert(counter, suit[c]); counter += 1; } } }
/// <summary> /// The method returns the list of card in the straight combo. /// </summary> /// <returns></returns> public List <Card> GetStraightCards() { List <int> comboList = GroupCardsSuit(cards); List <Card> comboCards = new List <Card>(); foreach (int i in comboList) { List <Card> cardsList = cards.Where(c => c.Suit == (Suit)i).ToList(); CardsEvaluator.ArrageCardsFacevalue(cardsList); if (CardsEvaluator.Straight(cardsList)) { foreach (Card card in cardsList) { comboCards.Add(card); cards.Remove(card); } } } return(comboCards); }
/// <summary> /// Method selects what card to dump. This is for the computer player mostly or if the human /// player went "time'up". /// </summary> /// <param name="deck"></param> /// <returns></returns> public Card CardToDump(Deck deck) { Card cardToDiscard; List <Card> cardsToKeep = new List <Card>(); List <Card> cardsToDiscard = new List <Card>(); //Checks for 2 of a kind card,puts the card in the card to keep list for (int i = 0; i < 12; i++) { if (cards.Where(c => c.FaceValue == (FaceValue)i).ToList().Count == 2) { cards.Where(c => c.FaceValue == (FaceValue)i).ToList().ForEach(c => cardsToKeep.Add(c)); } } //Checks for cards that can possible form straight combo, puts the card in the card to keep list for (int i = 0; i < 4; i++) { List <Card> cardsStraight = new List <Card>(); if (cards.Where(c => c.Suit == (Suit)i).ToList().Count >= 2) { cards.Where(c => c.Suit == (Suit)i).ToList().ForEach(c => cardsStraight.Add(c)); } CardsEvaluator.ArrageCardsFacevalue(cardsStraight); if (cardsStraight.Count > 0) { for (int d = 0; d < cardsStraight.Count; d++) { if (d == 0) { if (cardsStraight[d].FaceValue + 2 == cardsStraight[d + 1].FaceValue) { cardsToKeep.Add(cardsStraight[d]); } } else if (d == cardsStraight.Count - 1) { if (cardsStraight[d].FaceValue - 2 == cardsStraight[d - 1].FaceValue) { cardsToKeep.Add(cardsStraight[d]); } } else if (cardsStraight[d].FaceValue + 2 == cardsStraight[d + 1].FaceValue || cardsStraight[d].FaceValue - 2 == cardsStraight[d - 1].FaceValue) { cardsToKeep.Add(cardsStraight[d]); } } } } //puts cards in the hand that are not in the cards to keep list to the discard list cards.Where(c => !cardsToKeep.Contains(c)).ToList().ForEach(c => cardsToDiscard.Add(c)); //arrange card by facevalue points, if the deck has 6 cards remaining or there is no card in the discard list , it will return the highest valued card, //otherwise,it will return the highest valued card in the discard list CardsEvaluator.ArrageCardsFacevalue(cardsToDiscard); if (cardsToDiscard.Count == 0 || deck.Count <= 6) { CardsEvaluator.ArrageCardsFacevalue(cards); return(cardToDiscard = cards.Last()); } return(cardToDiscard = cardsToDiscard.Last()); }