public IReadOnlyList <ClueType> GetCluesAboutCard(CardInHand card) { if (card == null) { throw new ArgumentNullException(nameof(card)); } return(_thoughts .Find(thought => Equals(thought.CardInHand, card)).Clues .Distinct() .ToList().AsReadOnly()); }
/// <summary> /// /// </summary> /// <param name="player"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="InvalidOperationException">Throws if deck if empty</exception> private void AddCardToPlayer(Player player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } Card newCard = Deck.PopCard(); CardInHand cardInHand = new CardInHand(player, newCard); player.AddCard(cardInHand); }
public IReadOnlyList <ClueType> GetCluesAboutCard(CardInHand cardInHand) { if (cardInHand == null) { throw new ArgumentNullException(nameof(cardInHand)); } // TODO create more concise message if (cardInHand.Player != this) { throw new ArgumentException("cardInHand.Player != this"); } return(_memory.GetCluesAboutCard(cardInHand)); }
public bool KnowAboutNominalAndColor(CardInHand cardInHand) { if (cardInHand == null) { throw new ArgumentNullException(nameof(cardInHand)); } // TODO create more concise message if (cardInHand.Player != this) { throw new ArgumentException("cardInHand.Player != this"); } return(_memory.GetGuessAboutCard(cardInHand).KnowAboutNominalAndColor()); }
public void AddCard(CardInHand cardInHand) { if (cardInHand == null) { throw new ArgumentNullException(nameof(cardInHand)); } // TODO create more concise message if (cardInHand.Player != this) { throw new ArgumentException("cardInHand.Player != this"); } _memory.Add(cardInHand); }
/// <summary> /// Performing this action allows you to return a blue counter to the tin lid. /// The player discards a card from their hand, face-up, on to a discard pile (next to the tin). /// They then draw a new card, without looking at it, and add it to their hand. /// </summary> /// <param name="card"></param> public void DiscardCard(CardInHand card) { if (card == null) { throw new ArgumentNullException(nameof(card)); } if (card.Player != this) { throw new IncorrectDiscardActionException(); } _memory.Remove(card); _game.AddCardToDiscardPile(this, card.Card); }
/// <summary> /// The player takes a card from their hand and places it face up in front of them. /// There are then 2 possibilies: /// (*) if the card can start, or can be added to a firework, /// it is placed face-up on that firework's pile /// (*) if the card cannot be added to a firework, /// it is discarded, and the red counter is placed /// in the tin lid. /// /// In either case, the player then draws a new card, without looking at it, /// and adds it to their hand. /// </summary> /// <param name="cardInHand"></param> public void PlayCard(CardInHand cardInHand) { if (cardInHand == null) { throw new ArgumentNullException(nameof(cardInHand)); } if (cardInHand.Player != this) { throw new IncorrectPlayActionException("You can play only own cards"); } _memory.Remove(cardInHand); _game.AddCardToFirework(this, cardInHand.Card); }
public void Add(CardInHand cardInHand) { if (cardInHand == null) { throw new ArgumentNullException(nameof(cardInHand)); } var newThought = new ThoughtsAboutCard { CardInHand = cardInHand, Guess = new Guess(_provider, cardInHand), Clues = new List <ClueType>() }; _thoughts.Add(newThought); }
public IList <ClueType> GetCluesAboutCard(CardInHand cardInHand) { var result = Player.GetCluesAboutCard(cardInHand).ToList(); if (PossibleClue != null) { var clueAndCardMatcher = new ClueAndCardMatcher(cardInHand.Card); if (PossibleClue.Accept(clueAndCardMatcher)) { result.Add(PossibleClue); } else { result.Add(PossibleClue.Revert()); } } return(result); }
/// <summary> /// Возвращает подсказки, которые можно дать игроку на карту. /// Убирает подсказки, которые давали игроку ранее /// </summary> public static IList <ClueType> CreateClues(CardInHand card, IPlayerContext playerContext) { if (card == null) { throw new ArgumentNullException(nameof(card)); } if (playerContext == null) { throw new ArgumentNullException(nameof(playerContext)); } // TODO create more concise error description if (card.Player != playerContext.Player) { throw new ArgumentException("Different players"); } return(new List <ClueType> { new ClueAboutRank(card.Card.Rank), new ClueAboutColor(card.Card.Color) } .Except(playerContext.GetCluesAboutCard(card)) .ToList()); }
/// Can I play? /// See Firework pile. /// See my own guessed. /// Can I play card? /// Yes: Play (if next player has a clue) /// Otherwise: No /// Can I give a clue? /// If Yes, see the next player card and his memory. /// Can he play after my clue? public void Turn() { CardInHand cardToPlay = GetCardToPlay(); if (cardToPlay != null) { PlayCard(cardToPlay); return; } bool clueGiven = false; if (ClueCounter > 0) { LogPlayersCards(); clueGiven = OfferClue(); } if (!clueGiven) { CardInHand card = GetCardToDiscard(); DiscardCard(card); } }
private ThoughtsAboutCard GetThoughtsAboutCard(CardInHand cardInHand) { return(_thoughts.Find(thought => Equals(thought.CardInHand, cardInHand))); }
public static IList <ClueType> CreateClues(IPlayerContext playerContext, CardInHand card) { return(CreateClues(card, playerContext)); }
private CardInHand GetCardToPlay() { // cards we need to play var neededCards = FireworkPile.GetExpectedCards(); List <CardInHand> cardsToPlay = new List <CardInHand>(); if (_specialCards.Count > 0) { Logger.Log.Info("Use a subtle clue"); var cardToPlay = _specialCards.First(); _specialCards.RemoveAt(0); if (neededCards.Any(c => cardToPlay.Card == c)) { return(cardToPlay); } } // получить список карт, которые уже сброшены или находятся на руках у других игроков var excludedCards = _pilesAnalyzer.GetThrownCards(FireworkPile, DiscardPile) .Concat(GetOtherPlayersCards().Select(cardInHand => cardInHand.Card)); // поискать у себя карты из списка нужных foreach (Guess guess in Guesses) { var probability = guess.GetProbability(neededCards, excludedCards); if (probability > PlayProbabilityThreshold) { cardsToPlay.Add(_memory.GetCardByGuess(guess)); } } // эвристика: // если игрок знает, что у него есть единица, то пусть играет ей. // при условии, что ещё нужны единицы if ( FireworkPile.GetExpectedCards().Any(card => card.Rank == Rank.One) && cardsToPlay.Count == 0 && BlowCounter > 1) { CardInHand card = GetCardWithRankOneToPlay(); if (card != null) { Logger.Log.Info("I know that I have One. I'll try to play it."); cardsToPlay.Add(card); } } if (cardsToPlay.Count == 0) { return(null); } cardsToPlay = cardsToPlay .OrderBy(card => (int)card.Card.Rank) .ToList(); return(cardsToPlay.Last().Card.Rank == Rank.Five ? cardsToPlay.Last() : cardsToPlay.First()); }