示例#1
0
        private void ApplyClue(CardInHand card, ClueType clue)
        {
            var thought = GetThoughtsAboutCard(card);

            thought.Clues.Add(clue);

            clue.Accept(thought.Guess);
        }
示例#2
0
        private int CardsToClue(ClueType clue)
        {
            if (clue == null)
            {
                throw new ArgumentNullException(nameof(clue));
            }

            return(_playerContext.Hand
                   .Select(cih => cih.Card)
                   .Where(_boardContext.GetWhateverToPlayCards().Contains)
                   .Select(card => new ClueAndCardMatcher(card))
                   .Count(clue.Accept));
        }
示例#3
0
        public static Clue Create(ClueType clueType, IEnumerable <CardInHand> hand)
        {
            if (clueType == null)
            {
                throw new ArgumentNullException(nameof(clueType));
            }

            var result = new List <CardInHand>();

            foreach (var cardInHand in hand)
            {
                var matcher = new ClueAndCardMatcher(cardInHand.Card);

                if (clueType.Accept(matcher))
                {
                    result.Add(cardInHand);
                }
            }

            var readOnlyCollection =
                new ReadOnlyCollectionBuilder <CardInHand>(result).ToReadOnlyCollection();

            return(new Clue(clueType, readOnlyCollection));
        }
示例#4
0
        public IClueSituationStrategy FindClueCandidate(IReadOnlyList <Player> players)
        {
            // поищем подсказки "на ход"

            var expectedCards = _boardContext.GetExpectedCards();

            var expectedOneRankedCards = expectedCards.Where(card => card.Rank == Rank.One);

            if (expectedOneRankedCards.Any())
            {
                var situation = FindClueToPlayOneRankedCard(players, expectedOneRankedCards);

                if (situation != null)
                {
                    return(situation);
                }
                expectedCards = expectedCards.Except(expectedOneRankedCards);
            }


            foreach (var player in players)
            {
                var      playerContext = new PlayerContext(player, player.ShowCards(_clueGiver));
                ClueType clue          = FindClueToPlay(playerContext, expectedCards);

                if (clue == null)
                {
                    continue;
                }

                return(new OnlyClueExistsSituation(playerContext, clue));
            }

            var uniqueCards = _boardContext.GetUniqueCards();

            // поищем подсказки из серии "как бы чего не вышло"
            foreach (var player in players)
            {
                var      playerContext = new PlayerContext(player, player.ShowCards(_clueGiver));
                ClueType clue          = FindClueToDiscard(playerContext, uniqueCards);

                if (clue == null)
                {
                    continue;
                }

                return(new OnlyClueExistsSituation(playerContext, clue));
            }


            // поищем подсказки из серии "на будущее"
            var whateverToPlayCards =
                _boardContext.GetWhateverToPlayCards();

            foreach (var player in players)
            {
                var      playerContext = new PlayerContext(player, player.ShowCards(_clueGiver));
                ClueType clue          = FindClueToWhateverPlay(playerContext, whateverToPlayCards);

                if (clue == null)
                {
                    continue;
                }

                return(new OnlyClueExistsSituation(playerContext, clue));
            }

            return(new ClueNotExistsSituation());
        }
 public OnlyClueExistsSituation(IPlayerContext playerContext, ClueType clueType)
 {
     _playerContext = playerContext;
     _clueType      = clueType;
 }
示例#6
0
 private Clue(ClueType type, IReadOnlyCollection <CardInHand> cards)
 {
     Cards = cards;
     Type  = type;
 }