Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CGenerator Class Reference

Knight's tour and tourney generator. More...

#include <Generator.h>

Inheritance diagram for CGenerator:
CSearchThreadQueues

Public Member Functions

 CGenerator (int w, int h)
 Constructor. More...
 
 CGenerator (int n)
 Constructor. More...
 
 CGenerator ()
 Default constructor. More...
 
void Generate (const CTourneyDesc &t, int nThreads)
 Generate. More...
 
void Measure (const CTourneyDesc &t, int nThreads, int n)
 Measure. More...
 
void Time (const CTourneyDesc &t, int nThreads, int n)
 Time. More...
 

Private Member Functions

void OutputStat (FILE *output, double a[8])
 Output a statistic. More...
 
void OutputTimes (FILE *output, float fCpu, float fElapsed)
 Output times. More...
 

Private Attributes

std::vector< std::thread > m_vecThreadList
 Thread list for search.
 
int m_nWidth = 0
 Board width.
 
int m_nHeight = 0
 Board height.
 
int m_nSize = 0
 Board size.
 

Additional Inherited Members

- Static Protected Attributes inherited from CSearchThreadQueues
static CThreadSafeQueue< CSearchRequestm_cSearchRequest
 Search request queue.
 
static CThreadSafeQueue< CSearchResultm_cSearchResult
 Search result queue.
 

Detailed Description

The generator constructs tourneys and knight's tours. Those that use randomized algorithms are multi-threaded. The resulting tourneys and knight's tours can either be output (single tourneys and knight's tours only), or the generation of large numbers of them can be timed, or various statistics can be measured.

Definition at line 47 of file Generator.h.

Constructor & Destructor Documentation

◆ CGenerator() [1/3]

CGenerator::CGenerator ( int  w,
int  h 
)

Create an empty rectangular chessboard.

Parameters
wBoard width.
hBoard width.

Definition at line 44 of file Generator.cpp.

◆ CGenerator() [2/3]

CGenerator::CGenerator ( int  n)

Create an empty square chessboard.

Parameters
nWidth and height of a square chessboard.

Definition at line 51 of file Generator.cpp.

◆ CGenerator() [3/3]

CGenerator::CGenerator ( )

Create a very empty chessboard.

Definition at line 37 of file Generator.cpp.

Member Function Documentation

◆ Generate()

void CGenerator::Generate ( const CTourneyDesc t,
int  nThreads 
)

Generate a single knight's tour or tourney. Fill the request queue, launch the search threads, then wait for them to terminate and output the resulting tour or tourney to a file.

Parameters
tTourney descriptor.
nThreadsNumber of search threads to use.

Definition at line 66 of file Generator.cpp.

◆ Measure()

void CGenerator::Measure ( const CTourneyDesc t,
int  nThreads,
int  n 
)

Measure statistics on multiple knight's tours or tourneys. Fill the request queue, launch the search threads, then wait for them to terminate. Count the number of occurrences of the 8 single moves and 8 double moves possible and write the results to a text file.

Parameters
tType of tour to generate.
nThreadsNumber of search threads to use.
nNumber of tours to generate.

Definition at line 165 of file Generator.cpp.

◆ OutputStat()

void CGenerator::OutputStat ( FILE *  output,
double  a[8] 
)
private

Output statistic from the generation multiple knight's tours or tourneys to a file.

Parameters
outputFile pointer.
aArray of 8 numbers.

Definition at line 282 of file Generator.cpp.

◆ OutputTimes()

void CGenerator::OutputTimes ( FILE *  output,
float  fCpu,
float  fElapsed 
)
private

Append times (cpu time and elapsed time) from the generation of multiple knight's tours or tourneys to a text file. The file name contains the tourney type.

Parameters
outputPointer to file.
fCpuCPU time in seconds.
fElapsedElapsed time in seconds.

Definition at line 351 of file Generator.cpp.

◆ Time()

void CGenerator::Time ( const CTourneyDesc t,
int  nThreads,
int  n 
)

Report the CPU and elapsed time required to generate multiple knight's tours or tourneys. Fill the request queue, launch the search threads, wait for them to terminate, then append the CPU and elapsed times to a text file.

Parameters
tTourney descriptor.
nThreadsNumber of search threads to use.
nNumber of tours to generate.

Definition at line 305 of file Generator.cpp.