![]() |
Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
|
Knight's tour and tourney generator using Warnsdorff's heuristic. More...
#include <Warnsdorff.h>
Public Member Functions | |
CWarnsdorff (int seed) | |
Constructor. More... | |
void | Generate (CBoard &b, CycleType t) |
Generate a tour or tourney. More... | |
Private Member Functions | |
int | RandomClosedWalk (CBoard &b, int start) |
Create closed random walk. More... | |
bool | GenerateTour (CBoard &b) |
Generate a knight's tour. More... | |
bool | GenerateTourney (CBoard &b) |
Generate a tourney. More... | |
Private Attributes | |
CRandom | m_cRandom |
PRNG. | |
Warnsdorff's Algorithm is a random walk that optimistically joins up to make one or more cycles aided by Warnsdorff's Heuristic which works. as follows Instead of choosing a random next move, it chooses a move at random from the set of moves that lead to a cell that has remaining the smallest number ofavailable moves to an unvisited square. The tourney version attempts to make a cycle as soon as possible, while the tour version holds off doing so for as long as possible. This results in distinctive patterns in the knight's tours and tourneys generated. For example, the image below shows a tourney with the cycles in color (left) and a knight's tour (right) generated by this algorithm.
See Conrad, Hindrichs, Morsy, and Wegener, "Wie es dem springer gelang schachbretter beliebiger groesse und zwischen beliebig vorgegebenen anfangs und endfeldern vollstaendig abzuschreiten", Spektrum der Wissenschaft, pages 10-14, 1992, and Conrad, Hindrichs, Morsy, and Wegener, "Solution of the knight's Hamiltonian path problem on chessboards", Discrete Applied Mathematics, 50(2):125-134, 1994.
Definition at line 57 of file Warnsdorff.h.
CWarnsdorff::CWarnsdorff | ( | int | seed | ) |
The default constructor seeds the PRNG.
seed | A random number seed. |
Definition at line 35 of file Warnsdorff.cpp.
Generate a knight's tour or tourney using Warnsdorff's algorithm.
b | [out] Board. |
t | Cycle type. |
Definition at line 265 of file Warnsdorff.cpp.
|
private |
Attempt to generate a random knight's tour.
b | [out] Board for generated tour. |
Definition at line 44 of file Warnsdorff.cpp.
|
private |
Attempt to generate a random tourney.
b | [in, out] Chessboard. |
Definition at line 137 of file Warnsdorff.cpp.
|
private |
Take a random walk and close it into a cycle at the first opportunity.
b | [in, out] Chessboard. |
start | Index of the first cell on the walk. |
Definition at line 187 of file Warnsdorff.cpp.