generateComplete's canPlace only checked two of three Takuzu rules (no triples, equal count) but not the unique-lines constraint. This produced complete grids with duplicate rows/columns. generatePuzzle's countSolutions — which does check uniqueness — then returned 0 for the original grid, rejecting every cell removal and yielding fully-filled puzzles with no empty cells. canPlace now temporarily places the value and checks row/column uniqueness whenever the placement would complete a row or column.
- commit
- a4dbb523bbf45a5ec96c8948519584458b5b4a0d
- parent
- ae51f4c6834d1aaea12035c7d2af0e510bf0ecc8
- author
- Dami <dami.etoile@gmail.com>
| M | takuzu/ | 40 | ++++++++++++++++++++++++++++++ |
@@ -81,6 +81,46 @@ func canPlace(g grid, size, x, y int, val rune) bool {
8181 return false8282 }8383 84+ // If this placement would complete the row, check uniqueness against other complete rows.85+ g[y][x] = val86+ if rowFilled(g, y, size) {87+ for other := range size {88+ if other != y && rowFilled(g, other, size) && rowEqual(g[y], g[other]) {89+ g[y][x] = emptyCell90+ return false91+ }92+ }93+ }94+95+ // If this placement would complete the column, check uniqueness against other complete columns.96+ if colFilled(g, x, size) {97+ for other := range size {98+ if other != x && colFilled(g, other, size) && colEqual(g, size, x, other) {99+ g[y][x] = emptyCell100+ return false101+ }102+ }103+ }104+ g[y][x] = emptyCell105+106+ return true107+}108+109+func rowFilled(g grid, y, size int) bool {110+ for x := range size {111+ if g[y][x] == emptyCell {112+ return false113+ }114+ }115+ return true116+}117+118+func colFilled(g grid, x, size int) bool {119+ for y := range size {120+ if g[y][x] == emptyCell {121+ return false122+ }123+ }84124 return true85125 }86126