Пример #1
0
        public s_hint_score score_hint(string hint)
        {
            // For each potential answer, See how small the answer list would become for a given hint.
            // Score the hint based on the largest (worst-case) resulting answers list.

            int   max_score = -1;
            float sum_score = 0;

            Dictionary <UInt64, int> guesses = new Dictionary <UInt64, int>();

            // Find the score for each potential answer being the real answer.
            foreach (string answer in m_answers)
            {
                c_guess guess = new c_guess(hint, answer);

                // Optimization: If two hint/answer pairs produce the same feedback, only do work once.
                UInt64 guess_encoded = guess.encode();
                if (!guesses.ContainsKey(guess_encoded))
                {
                    // See how big the resulting answers list would be.
                    int score = m_answers.Count(word => guess.matches(word));

                    // Debug-friendly score computation
                    // List<string> matches = m_answers.Where(word => guess.matches(word)).ToList();
                    // int score = matches.Count();

                    guesses.Add(guess_encoded, score);

                    // record the largest score.
                    if (score > max_score || (score > 0 && max_score == -1))
                    {
                        max_score = score;
                    }

                    sum_score += score;
                }
                else
                {
                    sum_score += guesses[guess_encoded];
                }
            }

            if (max_score == -1)
            {
                max_score = int.MaxValue;
            }

            bool hint_is_possible_answer = m_answers.Contains(hint);

            return(new s_hint_score(max_score, sum_score / m_answers.Count, hint_is_possible_answer));
        }
Пример #2
0
 public void apply(c_guess guess)
 {
     m_answers = m_answers.Where(word => guess.matches(word)).ToList();
 }
Пример #3
0
        public c_dictionary apply(c_guess guess)
        {
            List <string> filtered_words = m_words.Where(word => guess.matches(word)).ToList();

            return(new c_dictionary(filtered_words));
        }