jonadsimon / wonder-words-generator

Generates WonderWords puzzles
Apache License 2.0
2 stars 0 forks source link

Add check for too-long words #53

Closed jonadsimon closed 2 years ago

jonadsimon commented 2 years ago

It's possible for a word within an otherwise-valid wordset to be longer than the size of the board. This breaks everything, and such cases should raise an exception early-on and terminate. See here:

> python make_puzzle_v2.py caligraphy --packing-constant=1.1 --strategy=median --optimize-words

Removed too-similar words (superstring): paintbrush

Pre-optimization word stats:
    num_words: 26
    packing_level: 1.036
    word_len (mean/max): 8.96 / 18
    collision_avoidance_prob (min/mean): -0.368889 / 0.668540

Ended optimization with loop_cnt=0

Words removed:
Words added:

Post-optimization word stats:
    num_words: 26
    packing_level: 1.036
    word_len (mean/max): 8.96 / 18
    collision_avoidance_prob (min/mean): -0.368889 / 0.668540

['logo', 'font', 'ming', 'lama', 'tibet', 'brush', 'islam', 'vellum', 'scapula', 'secular', 'document', 'bastarda', 'light-box', 'hiragana', 'katakana', 'buddhism', 'plastrons', 'ethiopian', 'typography', 'visual arts', 'testimonial', 'graphic design', 'ink and wash painting', 'western calligraphy', 'lindisfarne gospels', 'wedding invitations']

{10: 'caligraphy', 21: 'vietnamese calligraphy', 18: 'chinese calligraphy', 19: 'japanese calligraphy', 17: 'korean calligraphy', 14: 'korean language', 8: 'typeface', 7: 'writing', 11: 'inscription', 16: 'tigrinya language', 9: 'parchment', 13: 'greek language', 12: 'religious art'}

Traceback (most recent call last):
  File "/Users/jonsimon/Code/wonder-words-generator/make_puzzle_v2.py", line 385, in <module>
    make_puzzle(args.topic, args.board_size, args.packing_constant, args.strategy, args.optimize_words, args.relatedness_cutoff)
  File "/Users/jonsimon/Code/wonder-words-generator/make_puzzle_v2.py", line 311, in make_puzzle
    covered_up_words, doubled_up_words, deltas = find_words_in_board(board, word_tuples_to_fit)
  File "/Users/jonsimon/Code/wonder-words-generator/make_puzzle_v2.py", line 228, in find_words_in_board
    raise ValueError(f"word '{wt.board}' does not appear in the board, something has gone HORRIBLY wrong")
ValueError: word 'LOGO' does not appear in the board, something has gone HORRIBLY wrong
jonadsimon commented 2 years ago

Added check in https://github.com/jonadsimon/wonder-words-generator/commit/a9fc1f8fae2388a133d9bdc9835139085080b934