I'm trying to animate Dancing Links by Donald Knuth, using the Eight Queens Puzzle
The clever choice of options ordering is too smart in QUEENS-DLX by Knuth. No backtracking occurs below n=16. I decided to start with a naive order. Now backtracking happens a lot even for n=8.
Mandatory. All rows and all columns must be covered exactly once
- RA..RH rows (8)
- CA..CH columns (8)
Not mandatory. Diagonals can be covered at most once
- AA..AO left diagonals (15)
- BA..BO right diagonals (15)
The four corner diagonals, AA, AO, BA and BO have only one option, so they are actually not needed. No risk for two queens on these.
- a1..h1 first row, RA
- a8..h8 last row, RH
- a1..a8 first column, CA
- h1..h8 last column, CH
- a1..a1 first left diagonal, AA
- h8..h8 last left diagonal, AO
- a8..a8 first right diagonal, BA
- h1..h1 last right diagonal, BO
When all queens are placed on the board and in legal positions, the first solution has been found. This viewer only shows the first solution.
- Texts in yellow are mouse aware
- Hold the mouse over item names, e.g. CA
- Hold the mouse over a chess square, e.g. a1
- Click on one of the snapshots in the list to the right
- Down Arrow: go to next snapshot
- Up Arrow: go to previous snapshot
- Space: Compact or Expanded View
8queens.json is generated by 037-DLX. Simplified extract:
options: "a1 a2 a3 a4 a5 a6 a7 a8 b1 b2 b3 b4 b5 b6 b7 b8 c1 c2 c3 c4 c5 c6 c7 c8 d1 d2 d3 d4 d5 d6 d7 d8 e1 e2 e3 e4 e5 e6 e7 e8 f1 f2 f3 f4 f5 f6 f7 f8 g1 g2 g3 g4 g5 g6 g7 g8 h1 h2 h3 h4 h5 h6 h7 h8"
items: "CA CB CC CD CE CF CG CH R1 R2 R3 R4 R5 R6 R7 R8 AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO"
snapshots:
choices: "" entries: {...}
choices: "a1" entries: {...}
choices: "a1 b3" entries: {...}
choices: "a1 b3 c5" entries: {AE:"d2" AF:"e2" AH:"e4 g2" AI:"f4 h2" ...}
...