public bool IsCorrectAnswer(string answer, Question question)
        {
            // multi choice
            if (question.Answers.Count > 1)
            {
                char correctLetterAnswer = question.GetCorrectAnswerLetter();
                if (answer.ToLower().StartsWith(correctLetterAnswer + ".")
                    || answer.Split(new[] { ' ' })[0].ToLower().Equals(correctLetterAnswer.ToString(), StringComparison.CurrentCultureIgnoreCase))
                {
                    return true;
                }
            }

            string[] answerArray = RemoveInsignificants(answer.ToLower().Split(new[] { ' ' }));
            string[] correctAnswerArray = RemoveInsignificants(question.GetCorrectAnswer().AnswerText.ToLower().Split(new[] { ' ' }));

            List<string> usedWords = new List<string>();
            foreach (var word in answerArray)
            {
                var cleanedUserWord = RemovePunctuation(word);
                foreach (var cword in correctAnswerArray)
                {
                    var cleanedRealWord = RemovePunctuation(cword);
                    if (cleanedUserWord.Equals(cleanedRealWord) && !usedWords.Contains(cleanedUserWord))
                    {
                        usedWords.Add(cleanedUserWord);
                    }
                }
            }

            if (Convert.ToDouble(usedWords.Count) / correctAnswerArray.Length > TriviaPlugin.PercentageToBeCorrect
                && Convert.ToDouble(usedWords.Count) / correctAnswerArray.Length < TriviaPlugin.HighPercentageToBeCorrect
                && answerArray.Length < correctAnswerArray.Length + 5)
                return true;

            string s1 = string.Empty, s2 = string.Empty;
            s1 = answerArray.Aggregate(s1, (current, a) => current + " " + a);
            s2 = correctAnswerArray.Aggregate(s2, (current, a) => current + " " + a);

            double calc = Convert.ToDouble(LevenshteinDistance.Compute(s1, s2)) / Convert.ToDouble(s1.Length + s2.Length);

            return calc <= .5;
        }
Exemple #2
0
 public void GotoNextQuestion()
 {
     Timer.Stop();
     UsersAttempted.Clear();
     CurrentQuestion = GetQuestion();
     if (CurrentQuestion != null && GameStarted)
     {
         PrintQuestion(CurrentQuestion);
         Timer.Start();
     }
 }
Exemple #3
0
        public void PrintQuestion(Question question)
        {
            SendMessage(Channel, string.Format("Question {0}: {1}", CurrentQuestionNum, question.QuestionText));

            if (question.Answers.Count > 1)
            {
                char answerLetter = 'a';
                foreach (var answer in question.Answers)
                {
                    SendMessage(Channel, string.Format("{0}. {1}", answerLetter, answer.AnswerText));
                    answerLetter++;
                }
            }
        }