public void AskEachPlayerAboutTrump(IGameState gameState, Func <ISuit> humanChooseSuit) { for (var i = 0; i < gameState.Players.Count(); i++) { gameState.AdvanceToNextPlayer(); ISuit trumpSelected = null; if (gameState.CurrentPlayer.IsHuman) { trumpSelected = humanChooseSuit(); } else { trumpSelected = gameState.CurrentPlayer.PlayerStrategy.SecondRoundTrumpChoice(gameState); } if (trumpSelected != null) { gameState.Trump = trumpSelected; gameState.OrderingUpPlayer = gameState.CurrentPlayer; OnAiChoseTrump?.Invoke(this, new AiChoseTrumpEventArgs(gameState.CurrentPlayer, trumpSelected)); break; } } }
public Card(string name, ISuit suit, int value) { Name = (value == CardValues.ACE || value == CardValues.ACE_HIGH) ? CardNames.ACE : name; Abbreviation = Name.Substring(0, 1); Suit = suit; Value = value; }
public virtual ISuit SecondRoundTrumpChoice(IGameState gameState) { //if I have at least 3 trump of any suit, order up if the sum of the ranks over a certain amt var validSuits = CardHelper.GetSuitsToChooseFrom(gameState.TurnedUpCard.Suit); var rankTotal = 0; ISuit suitToOrderUp = null; foreach (var suit in validSuits) { var suitRankTotal = gameState.CurrentPlayer.Cards.Where(x => x.Suit == suit).Sum(x => x.Rank.Value); var thisSuit = suit; //provide a boost for any bowers if (CardHelper.ContainsLeft(suit, gameState.CurrentPlayer.Cards)) { suitRankTotal += 4; } if (CardHelper.ContainsRight(suit, gameState.CurrentPlayer.Cards)) { suitRankTotal += 5; } if (suitRankTotal > 43 && suitRankTotal > rankTotal) { rankTotal = suitRankTotal; suitToOrderUp = suit; } } return(suitToOrderUp); }
public static List <ISuit> GetSuitsToChooseFrom(ISuit turnedUpCardSuit) { var newDeck = new EuchreDeck(); var allSuits = newDeck.Cards.Select(x => x.Suit).Distinct(); return(allSuits.Where(x => x != turnedUpCardSuit).ToList()); }
private int CompareSuit(ISuit x, ISuit y) { if (_suitAscending) { return(x.AsEnum() - y.AsEnum()); } return(y.AsEnum() - x.AsEnum()); }
public Card Deal(ISuit suit) { // Do NOT use card.Suit == suit (the operator== is a STATIC overload and is NOT found) var result = _cards.FirstOrDefault(card => card.Suit.Equals(suit)); Remove(result); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="Card"/> class. /// </summary> /// <param name="id">Card Id.</param> /// <param name="suit">Suit.</param> /// <param name="rank">Rank.</param> public Card( Guid id, ISuit suit, IRank rank) { this.Id = id; this.Suit = suit ?? throw new ArgumentNullException(nameof(suit)); this.Rank = rank ?? throw new ArgumentNullException(nameof(rank)); }
private ICard GetNewCard(IFaceValue faceValue, ISuit suit) { var card = this.dependencyResolver.Get <ICard>(); card.FaceValue = faceValue; card.Suit = suit; return(card); }
/// <inheritdoc cref="IEquatable{T}"/> public bool Equals(ISuit other) { if (other == null) { return(false); } return(other.AsCharacter() == AsCharacter() && other.AsEnum() == AsEnum() && other.NextSuit() == NextSuit()); }
public IHand ConstructFlush(ISuit suit) { IHand result = ConstructCrappyHand(); foreach (var card in result.Cards) { card.Suit = suit; } return(result); }
public IHand ConstructRoyalFlush(ISuit suit) { IHand result = new TexasHoldemHand(); result.Add(new Card(suit, CardValues.TEN)); result.Add(new Card(suit, CardValues.KING)); result.Add(new Card(suit, CardValues.JACK)); result.Add(new Card(suit, CardValues.ACE)); result.Add(new Card(suit, CardValues.QUEEN)); return(result); }
/// <inheritdoc/> public void CreateSuit(ISuit suit) { SuitDto suitDto = SuitDto.ToDto(suit); this.Context.Suits.Add(suitDto); int count = this.Context.SaveChanges(); if (count != 1) { throw new ApplicationException($"Unexpectedly created {count} rows"); } }
public static bool ContainsLeft(ISuit trumpSuit, List <ICard> cards) { var jacks = cards.Where(x => x.Rank.Symbol.ToUpper() == StandardRank.JackSymbol).ToList(); if (!jacks.Any()) { return(false); } var oppositeSuit = GetOppositeSuit(trumpSuit); return(jacks.Any(x => x.Suit.Equals(oppositeSuit))); }
/// <summary> /// Converts domain object to DTO. /// </summary> /// <param name="suit">The suit.</param> /// <returns>Suit DTO.</returns> public static SuitDto ToDto(ISuit suit) { if (suit == null) { throw new ArgumentNullException(nameof(suit)); } return(new SuitDto( id: suit.Id, code: suit.Code, name: suit.Name, sortOrder: suit.SortOrder)); }
public static Bitmap GetBitmap(int cardNumber, ISuit suit) { Assembly dll = typeof(Utils).Assembly; string[] names = dll.GetManifestResourceNames(); foreach (string imageName in names) { if (imageName.Contains(suit.GetType().Name + "." + cardNumber.ToString() + ".png")) { return new Bitmap(dll.GetManifestResourceStream(imageName)); } } return null; }
public static ICard GetHighestTrump(ISuit trumpSuit, List <ICard> cards) { if (ContainsRight(trumpSuit, cards)) { return(cards.First(x => x.IsTheRight(trumpSuit))); } if (ContainsLeft(trumpSuit, cards)) { return(cards.First(x => x.IsTheLeft(trumpSuit))); } return(cards.OrderByDescending(x => x.Rank.Value).FirstOrDefault(x => x.Suit == trumpSuit)); }
public static bool IsGreaterThan(this ICard card, ICard otherCard, ISuit trumpSuit) { if (otherCard == null) { return(true); } if (card.IsTrump(trumpSuit) && !otherCard.IsTrump(trumpSuit)) { return(true); } if (!card.IsTrump(trumpSuit) && otherCard.IsTrump(trumpSuit)) { return(false); } //handle bowers if (card.IsTrump(trumpSuit) && otherCard.IsTrump(trumpSuit)) { if (card.IsTheRight(trumpSuit)) { return(true); } if (otherCard.IsTheRight(trumpSuit)) { return(false); } if (card.IsTheLeft(trumpSuit) && !otherCard.IsTheRight(trumpSuit)) { return(true); } if (!card.IsTheRight(trumpSuit) && otherCard.IsTheLeft(trumpSuit)) { return(false); } } //we need to compare ranks if (card.Suit == otherCard.Suit) { return(card.Rank.Value > otherCard.Rank.Value); } //we should get here if we compare two non-trump suits return(false); }
public IHand ConstructStraightFlush(ISuit suit, int highValue) { IHand result = new TexasHoldemHand(); if (highValue < 5) { throw new Exception($"The '{nameof(highValue)}' of {highValue} should be 5 or greater."); } result.Add(new Card(suit, highValue - 1)); result.Add(new Card(suit, highValue - 3)); result.Add(new Card(suit, highValue)); result.Add(new Card(suit, highValue - 2)); result.Add(new Card(suit, highValue - 4)); return(result); }
public static ISuit GetOppositeSuit(ISuit suit) { if (suit.Equals(StandardSuit.Clubs)) { return(StandardSuit.Spades); } if (suit.Equals(StandardSuit.Spades)) { return(StandardSuit.Clubs); } if (suit.Equals(StandardSuit.Hearts)) { return(StandardSuit.Diamonds); } return(StandardSuit.Hearts); }
public static Card[] GetCardsFromSuit(ISuit suit) { List<Card> cards = new List<Card>(); Type card = typeof(Card); PropertyInfo[] properties = typeof(ISuit).GetProperties(); foreach (PropertyInfo property in properties) { if (property.PropertyType == card) { object value = property.GetValue(suit, null); Card cardValue = (Card)value; cards.Add(cardValue); } } return cards.ToArray(); }
public static IEnumerable <ICard> GetValidCards(ISuit leadSuit, ISuit trumpSuit, List <ICard> cards) { var validCards = new List <ICard>(); //if there is a lead card AND current player has one of these cards, only offer one of these if (leadSuit != null && leadSuit != trumpSuit && cards.Any(x => x.Suit == leadSuit) ) { validCards.AddRange(GetAllNonTrump(trumpSuit, cards).Where(x => x.Suit == leadSuit)); } else if (trumpSuit == leadSuit) { validCards.AddRange(GetAllTrump(trumpSuit, cards)); } if (!validCards.Any()) { //otherwise, any card validCards.AddRange(cards); } return(validCards); }
public Card(int num, ISuit suit) { Number = num; Suit = suit; }
public Card(string name, Bitmap image, ISuit suit) { _name = name; _image = image; _suit = suit; }
public IValueCompare Compare(ISuit champion, ISuit challenger) => throw new System.Exception("SuitValueCompare NoOp was hit");
public static List <ICard> GetAllNonTrump(ISuit trumpSuit, List <ICard> cards) { return(cards.Where(x => x.Suit != trumpSuit && !x.IsTheLeft(trumpSuit)).ToList()); }
public static bool IsTheLeft(this ICard card, ISuit trumpSuit) { return(card.Rank.Symbol == StandardRank.JackSymbol && card.Suit == CardHelper.GetOppositeSuit(trumpSuit)); }
public static bool IsTrump(this ICard card, ISuit trumpSuit) { return(card.Suit == trumpSuit); }
public static bool IsTheRight(this ICard card, ISuit trumpSuit) { return(card.Rank.Symbol == StandardRank.JackSymbol && card.Suit == trumpSuit); }
public static bool ContainsRight(ISuit trumpSuit, List <ICard> cards) { var jacks = cards.Where(x => x.Rank.Symbol.ToUpper() == StandardRank.JackSymbol).ToList(); return(jacks.Any() && jacks.Any(x => x.Suit.Equals(trumpSuit))); }
public Card(ISuit suit, int value) : this(value.ToString(), suit, value) { Suit = suit; Value = value; }
protected CardBase(ISuit suit, IRank rank) { Suit = suit; Rank = rank; }
public IEnumerable <char> GetValidIndexes(ISuit leadSuit, ISuit trumpSuit, List <ICard> cards) { var validCards = CardHelper.GetValidCards(leadSuit, trumpSuit, cards); return(validCards.Select(card => cards.IndexOf(card)).Select(index => Convert.ToChar(49 + index)).ToList()); }
/// <summary> /// Constructor for Trump Hand Sorter /// </summary> /// <param name="trumpSuit"></param> /// <param name="suitAscending"></param> /// <param name="rankAscending"></param> public TrumpHandSorter(ISuit trumpSuit, bool suitAscending, bool rankAscending) { _trumpSuit = trumpSuit; _suitAscending = suitAscending; _rankAscending = rankAscending; }
public AiChoseTrumpEventArgs(IPlayer player, ISuit suit) { Player = player; Suit = suit; }