Optimal Algorithm for Winning Hangman

后端 未结 7 1473
庸人自扰
庸人自扰 2021-02-04 03:18

In the game Hangman, is it the case that a greedy letter-frequency algorithm is equivalent to a best-chance-of-winning algorithm?

Is there ever a case where it\'s worth

7条回答
  •  轮回少年
    2021-02-04 04:13

    About your idea to try and guess the word instead of trying to guess letters, there sure may be some isolated cases where you guess the word from the first try or something like that, but this doesn't make that algorithm better on the average case. It's about expected probability.

    Some improvement that could be done to that algorithm (in the version posted by Lajos) is some more informed pick of letter to be tried.
    This could be achieved by adding one more weight: consider the usage of each word the vocabulary of the language.

    For example, technical, medical, juridical etc. words would have much lower chances.

    Take this dictionary (with some example usage weights):

    frost    6
    guilt    5
    genes    1
    fever    2
    meter    1
    

    Here e is the most frequent letter, so it would get chosen. This would mean leaving only the medical terms, which are very unlikely. But if the decision is taken by:

    weight(letter) = w * frequency +
                  (1 - w) * sum( usage_weight(word) where letter in word )
    

    then, most probably t would be chosen.


    Because (let's say w = 0.2):

    weight(e) = 0.2 * 3   +   0.8 * (1 + 2 + 1)
              = 3
    weight(r) = 0.2 * 3   +   0.8 * (1 + 2 + 6)
              = 7.8
    weight(t) = 0.2 * 3   +   0.8 * (1 + 5 + 6)
              = 10.2
    

    Note: We should, of course use normalized weights, like frequency / num_words to get accurate weight measuring.

    Note: This algorithm can and should be adapted to the opponent:

    • when playing against human, more usual words get higher weight
    • when playing against AI, it depends on the difficulty level:
      • on easy level aim for usual words
      • on hard level aim for unusual words

提交回复
热议问题