Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numbering of words #13

Merged
merged 3 commits into from
Sep 6, 2022
Merged

Fix numbering of words #13

merged 3 commits into from
Sep 6, 2022

Conversation

wom-bat
Copy link
Contributor

@wom-bat wom-bat commented Aug 14, 2022

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 [email protected]

@wom-bat
Copy link
Contributor Author

wom-bat commented Aug 14, 2022

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
Copy link
Contributor Author

wom-bat commented Aug 15, 2022

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

@wom-bat
Copy link
Contributor Author

wom-bat commented Aug 15, 2022

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
Copy link
Contributor Author

wom-bat commented Aug 15, 2022

The latest commit prevents word reuse.

@pmaher86
Copy link
Owner

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
Copy link
Contributor Author

wom-bat commented Aug 21, 2022

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.

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.

Signed-off-by: Peter Chubb <[email protected]>
The previous change fixed the numbers, but didn't adjust
the _across and _down arrays to be correct.

SIgned-off-by: Peter Chubb <[email protected]>
Make Crossword.get_word_at_index() return None if there is
no word.  Make the matching code cope with None returns.

Signed-off-by: Peter Chubb <[email protected]>
@pmaher86
Copy link
Owner

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.

blacksquare/crossword.py Outdated Show resolved Hide resolved
@pmaher86
Copy link
Owner

Thanks for the contribution. Feel free to merge!

@pmaher86 pmaher86 merged commit 6d9a2ae into pmaher86:master Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants