コード例 #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
ファイル: Clue.cs プロジェクト: IvanovAndrew/Hanabi
        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());
        }
コード例 #5
0
 public OnlyClueExistsSituation(IPlayerContext playerContext, ClueType clueType)
 {
     _playerContext = playerContext;
     _clueType      = clueType;
 }
コード例 #6
0
ファイル: Clue.cs プロジェクト: IvanovAndrew/Hanabi
 private Clue(ClueType type, IReadOnlyCollection <CardInHand> cards)
 {
     Cards = cards;
     Type  = type;
 }