sfuhrm / sudoku

A very fast Java Sudoku library implementation along with a command line client
GNU Lesser General Public License v3.0
19 stars 8 forks source link

When creating full 4x4 sudokus, sometimes invalid sudokus are created and sometimes an AssertionError is thrown... #8

Closed Lemkinator closed 1 year ago

Lemkinator commented 1 year ago

Expected Behavior

Creator.createFull(GameSchemas.SCHEMA_4X4)

should return a valid 4x4 Sudoku.

Actual Behavior

Creator.createFull(GameSchemas.SCHEMA_4X4)

(1) returns an invalid Sudoku: Example in Kotlin: invalid sudoku


Creator.createFull(GameSchemas.SCHEMA_4X4)

(2) throws an AssertionError: Example in Java: Arguments: -t -e Both -s S4x4 JVM-Options: -ea assertion error

Steps to Reproduce the Problem

  1. Enable AssertionErrors in JVM-Options -> -ea
  2. Call Creator.createFull(GameSchemas.SCHEMA_4X4) multiple times.
Lemkinator commented 1 year ago

More Background information: I'm using this Lib in my Android App and the App sometimes crashes because of that AssertionError. When i catch the AssertionError and just retry creating the sudoku everything works fine, except in some rare cases where an invalid sudoku is created (and no AssertionError is thrown)...

Creating 9x9 or larger Sudokus seems to be fine...

sfuhrm commented 1 year ago

Thank you very much for the helpful bug report! I could reproduce and solve the problem with that. Solution validated with unit test inspired by your reproduce instructions.

Background: In case of a dead-end sudoku, the do-loop in Creator.createFull() did not clear riddle again. Because of that the new initialization failed.

Fix is in release 5.0.1.