Esempio n. 1
0
 private AkinatorAnswer SupposeInternal(CharacterEntry character)
 {
     _characterToSuppose = character;
     return(new AkinatorAnswer
     {
         AkinatorAnswerType = AkinatorAnswerType.Answer,
         Message = "Предпологаю, что это " + character.Name,
         CharacterToSuppose = character
     });
 }
Esempio n. 2
0
        public void AddCharacter(CharacterEntry character)
        {
            _charactersWithProbability.Add(new CharacterWithProbability
            {
                Character   = character,
                Probability = 0.5
            });

            RecalculateEnd(character);
        }
Esempio n. 3
0
        private int GetBestQuestion(CharacterEntry bestCharacter)
        {
            var questions = bestCharacter.Questions
                            .Where(x => _history.All(y => y.QuestionId != x.Id))
                            .ToArray();
            var maxP = questions.Max(x => x.Probability);
            var ids  = questions.Where(x => x.Probability >= maxP)
                       .Select(x => x.Id).ToArray();

            if (ids.Length == 1)
            {
                return(ids[0]);
            }
            return(ids[_random.Next(ids.Length - 1)]);
        }
Esempio n. 4
0
        private void RecalculateEnd(CharacterEntry character)
        {
            if (character == null)
            {
                return;
            }

            foreach (var question in _history)
            {
                var characterQuestion = character.Questions.First(x => x.Id == question.QuestionId);
                var yes = question.UserAnswer == UserAnswer.Yes;
                characterQuestion.Probability =
                    (characterQuestion.Count * characterQuestion.Probability + (yes ? 1 : 0))
                    / (characterQuestion.Count + 1);
                if (yes)
                {
                    characterQuestion.Count++;
                }
            }

            character.Count++;
        }