From ad8bdfd0fdb1fa47d13e4606594e40ccb6813c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20S=2E=20Martins?= Date: Wed, 18 May 2016 13:18:19 +0100 Subject: [PATCH] Further refinements to the exclusion rules. --- crossword_generator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crossword_generator.py b/crossword_generator.py index 0ad2e3c..3c44113 100755 --- a/crossword_generator.py +++ b/crossword_generator.py @@ -73,16 +73,20 @@ def is_valid(possibility, grid): return False # Proximity if grid[i+k][j] != letter: - if (j < len(grid[0]) - 1 and grid[i+k][j+1] != 0) or (i > 0 and grid[i+k][j-1] != 0): + if (j < len(grid[0]) - 1 and grid[i+k][j+1] != 0) or (j > 0 and grid[i+k][j-1] != 0): return False # Start and End if D is "E": if j > 0 and grid[i][j-1] != 0: return False + if grid[i][j+len(word)] != 0: + return False if D is "S": if i > 0 and grid[i-1][j] != 0: return False + if grid[i+len(word)][j] != 0: + return False # Detect proximity #for k, letter in enumerate(list(word)):