pmaher86 / blacksquare

A Python package for crossword creators.
MIT License
40 stars 13 forks source link

Fix numbering of words #13

Closed wom-bat closed 2 years ago

wom-bat commented 2 years ago

The algorithm used to look for black squares to the left or above a possible word. This patch checks that the resulting word is longer than one character.

This fixes bug #12

Signed-off-by: Peter Chubb peter@chubb.wattle.id.au

wom-bat commented 2 years ago

Please note, it appears that the fill() method does not work if there are unchecked lights. Simplest test case:

from blacksquare import *
xw = Crossword(3)
xw[(1,1)] = BLACK
xw.fill().pprint()

Without the changes yields a grid full of J; with the changes yields a python backtrace.

wom-bat commented 2 years ago

The latest commit fixes the fill() backtrace. The remaining problem is that sometimes words are repeated in the grid.

wom-bat commented 2 years ago

Please note, it appears that the fill() method does not work if there are unchecked lights. Simplest test case:

from blacksquare import *
xw = Crossword(3)
xw[(1,1)] = BLACK
xw.fill().pprint()

This case now works, but repeats the word 'Wax'

wom-bat commented 2 years ago

The latest commit prevents word reuse.

pmaher86 commented 2 years ago

Thanks for the contribution! This gets to a bigger distinction though: the differences between cryptic and non-cryptic crosswords. Because they have different rules and expected structure, I think it would be preferable to have this behavior controlled via either a property of the Crossword class (cryptic=True) or by subclassing the Crossword class.

wom-bat commented 2 years ago

It's not just cryptic crosswords. Any crossword can have black squares anywhere. In British parlance, a non-cryptic crossword is a 'quick' crossword --- see, e.g., https://www.theguardian.com/crosswords/quick/16314

Please note --- grids with all lights checked will still work. There's no change in behaviour there.

pmaher86 commented 2 years ago

Any crossword can have black squares anywhere.

This is not true of American crosswords; they require that all words are at least three letters and all cells are checked. In any case, I agree this numbering logic is compatible with those as well. More work may be needed if/when grid validation is implemented.

pmaher86 commented 2 years ago

Thanks for the contribution. Feel free to merge!