/// <summary> /// Returns card in deck that matches an ambiguous card where suit is missing. /// </summary> /// <exception cref="CardNotPresentException">No cards that match this value.</exception> /// <exception cref="AmbiguousCardException">Several cards match this value.</exception> private static byte GetCardByValue(byte cardWithNoSuit, List <byte> deckToCheckAgainst) { byte card = 0; CardVals ambiCardVal = Defs.GetCardValue(cardWithNoSuit); foreach (byte deckCard in deckToCheckAgainst) { if (Defs.GetCardValue(deckCard) == ambiCardVal) { if (card == 0) { card = deckCard; } else { throw new AmbiguousCardException("Card suit must be specified, as the card referral is ambiguous.", cardWithNoSuit); } } } if (card == 0) { throw new CardNotPresentException("Card was specified by value, but no such value exists in this grouping of cards.", cardWithNoSuit); } return(card); }
private static byte ExtractCardFromString(string cmd) { cmd = cmd.Replace("10", "T"); cmd = cmd.ToLower(); if (cmd.Length < 1 || cmd.Length > 2) { throw new UnparseableMoveException(Errorstr.CardFormat(), cmd); } CardVals value = CardVals.NONE; CardSuits suit = CardSuits.NONE; char cmdValue = cmd[0]; char cmdSuit = '\0'; if (cmd.Length == 2) { cmdSuit = cmd[1]; } foreach (CardVals val in Enum.GetValues(typeof(CardVals))) { char valabbr = char.ToLower(GetCardValAbbr((byte)val, true)[0]); if (valabbr == cmdValue) { value = val; break; } } if (value == CardVals.NONE) { throw new UnparseableMoveException(Errorstr.CardFormat(), cmd); } if (cmdSuit != '\0') { cmdSuit = char.ToLower(cmdSuit); foreach (CardSuits suitf in Enum.GetValues(typeof(CardSuits))) { char suitabbr = GetCardSuitAbbr((byte)suitf, true); if (suitabbr == cmdSuit) { suit = suitf; break; } } if (suit == CardSuits.NONE) { throw new UnparseableMoveException("Invalid suit provided to a card", cmd); } } byte result = GetCardDigit(value, suit); return(result); }
/// <summary> /// Gets cards in hand by value. /// </summary> public List <byte> GetCardsByValue(CardVals value) { List <byte> result = new List <byte>(); foreach (byte card in Hand) { if (GetCardValue(card) == value) { result.Add(card); } } return(result); }
public static bool CardIsPictureCard(byte card) { CardVals value = GetCardValue(card); switch (value) { case CardVals.Jack: case CardVals.Queen: case CardVals.King: return(true); default: return(false); } }
/// <summary> /// Use this method at round end. Will assign point values and summary to players themselves. /// </summary> public void ScoreRound(byte currentRound) { if (_roundHasBeenScored) { throw new Exception(Errorstr.DuplicateRoundScore()); } List <ScoreableAttributes> p1Captures, p2Captures; p1Captures = new List <ScoreableAttributes>(); p2Captures = new List <ScoreableAttributes>(); SetActivePlayer(Players.One); /*STATIC VALUES*/ List <ScoreableAttributes> staticScoreables = CardNumberByStaticAttribute.Select(x => x.Key).ToList(); /*DYNAMIC VALUES*/ int p1CardCount, p2CardCount, p1SpadeCount, p2SpadeCount; p1SpadeCount = p2SpadeCount = 0; p1CardCount = p1.LocalDeck.CardCount; p2CardCount = p2.LocalDeck.CardCount; /*EVALUATE CARDS*/ do { Player player = GetActivePlayer(); List <ScoreableAttributes> captures = new List <ScoreableAttributes>(); CardVals value = CardVals.NONE; CardSuits suit = CardSuits.NONE; while (player.LocalDeck.CardCount > 0) { byte card = player.LocalDeck.DrawCards(1)[0]; value = GetCardValue(card); suit = GetCardSuit(card); /*STATIC*/ staticScoreables.Where(attr => CardNumberByStaticAttribute[attr].Equals(card)).ToList() .ForEach(attr => { captures.Add(attr); }); staticScoreables.RemoveAll(attr => captures.Contains(attr)); //efficiency reasons /*DYNAMIC*/ if (TURN == Players.One) { p1SpadeCount += (suit == CardSuits.Spades) ? 1 : 0; } if (TURN == Players.Two) { p2SpadeCount += (suit == CardSuits.Spades) ? 1 : 0; } } if (TURN == Players.One) { p1Captures.AddRange(captures); } else { p2Captures.AddRange(captures); } FlipActivePlayer(); } while (TURN != Players.One); /* EVAL DYNAMICS */ if (p1CardCount > p2CardCount) { p1Captures.Add(ScoreableAttributes.MostCards); } else if (p2CardCount > p1CardCount) { p2Captures.Add(ScoreableAttributes.MostCards); } if (p1SpadeCount > p2SpadeCount) { p1Captures.Add(ScoreableAttributes.MostSpades); } else if (p2SpadeCount > p1SpadeCount) { p2Captures.Add(ScoreableAttributes.MostSpades); } /* Conclusion - scores are evaluated by player */ p1.AddNewScoreLogEntry(p1Captures); p2.AddNewScoreLogEntry(p2Captures); _roundHasBeenScored = true; }
public static byte GetCardDigit(CardVals value, CardSuits suit) { return((byte)((byte)value + (byte)suit)); }