Words with length < 1 are now rejected.
Words of length 2, I'm looking at you.
This commit is contained in:
parent
792383a5d4
commit
4490328154
1 changed files with 4 additions and 5 deletions
|
@ -130,15 +130,15 @@ def draw_words(words, n_words=100):
|
|||
while len(selected_words) < n_words:
|
||||
# Choose candidate randomly
|
||||
candidate = words.pop(random.randint(0, len(words)-1))
|
||||
# Append candidate if it's not already there
|
||||
if candidate not in selected_words:
|
||||
# Append candidate if its length is acceptable
|
||||
if len(candidate) > 1:
|
||||
selected_words.append(candidate)
|
||||
|
||||
# ... and return the list
|
||||
return selected_words
|
||||
|
||||
# Basic Functions
|
||||
def read_word_list(filename, n_words=100):
|
||||
def read_word_list(filename):
|
||||
""" This function reads the file and returns the words read. It expects a
|
||||
file where each word is in a line.
|
||||
"""
|
||||
|
@ -154,7 +154,6 @@ def read_word_list(filename, n_words=100):
|
|||
return words
|
||||
|
||||
|
||||
|
||||
def generate_grid(words, dim):
|
||||
""" This function receives a list of words and creates a new grid, which
|
||||
represents our puzzle. The newly-created grid is of dimensions
|
||||
|
@ -219,7 +218,7 @@ def generate_grid(words, dim):
|
|||
# Generate new possibilities, if needed
|
||||
while len(possibilities) < 30:
|
||||
print("Getting new words!")
|
||||
sample = draw_words(words)
|
||||
sample = draw_words(words, 1000)
|
||||
possibilities.extend(generate_possibilities(sample, dim))
|
||||
possibilities = [x for x in possibilities if is_valid(x, grid) and x["word"] != new["word"]]
|
||||
|
||||
|
|
Loading…
Reference in a new issue