Skip to content

Commit

Permalink
Update scoring function.
Browse files Browse the repository at this point in the history
Fixes bug in the handling of "wrong word" subgroup, and adds a
"promote branching" term.
  • Loading branch information
isomer committed Dec 6, 2015
1 parent 213d670 commit 9b2785d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hangman.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ def group_by_patterns(words, ch):
Entry = namedtuple('Entry', ['pattern', 'is_leaf', 'value'])
Section = namedtuple('Section', ['id', 'pattern', 'wrong', 'guess', 'entries'])

def empty_pattern(pattern):
return u'_' * len(pattern)

def score_grouping(subgroups, pattern):
wrong_words = subgroups.get(empty_pattern(pattern), ())
return (
# len(subgroups.get(pattern, ())),
sum(word_ranks[word] for word in subgroups.get(pattern, ())),
max(len(v) for v in subgroups.values())
len(wrong_words), # Minimise number of wrong words
sum(word_ranks[word] for word in wrong_words), # Avoid popular wrong words
-len(subgroups), # Maximise branching factor
# max(len(v) for v in subgroups.values()), # Maximum number of words in any group
)

def build_graph(pattern, words, letters, wrong=0):
Expand Down Expand Up @@ -91,7 +95,7 @@ def augment_graph(graph, words):
"""Adds any words to the graph that can be added without inserting new sections."""
added = []
for word in words:
pattern = u'_' * len(word)
pattern = empty_pattern(word)
node = graph[pattern]
while node.guess != '':
pattern = combine_patterns(pattern, make_pattern(word, node.guess))
Expand Down

0 comments on commit 9b2785d

Please sign in to comment.