Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
Main.cpp
Go to the documentation of this file.
1 
4 // MIT License
5 //
6 // Copyright (c) 2019 Ian Parberry
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 
26 #ifdef _DEBUG
27  #include <vld.h> //Visual Leak Detector from http://vld.codeplex.com/
28 #endif
29 
30 #include "Includes.h"
31 #include "Defines.h"
32 #include "Input.h"
33 #include "Generator.h"
34 #include "Task.h"
35 #include "Helpers.h"
36 
40 
41 int main(){
42  const int nNumThreads =
43  std::thread::hardware_concurrency() - 1; //number of threads
44 
45  srand(timeGetTime()); //we'll use ::rand() later to seed a better PRNG
46 
47  //print banner
48 
49  printf("Ian Parberry's square tourney generator");
50  printf(" with %d concurrent threads.\n", nNumThreads);
51  printf("-------------------------------------------------------------------");
52  putchar('\n');
53 
54  //read user input and perform corresponding tasks
55 
56  bool bQuit = false; //true when the user wants to exit
57 
58  while(!bQuit){ //loop until the user types "q" to quit
59  putchar('\n');
60 
61  Task task = Task::Unknown; //task to be performed
62  bQuit = ReadTask(task); //get the task
63 
64  if(!bQuit){
65  GeneratorType gentype = GeneratorType::Unknown; //generator type
66  bool bRestart = ReadGeneratorType(gentype); //get the generator type
67 
68  if(!bRestart){
69  CycleType cycletype = CycleType::Unknown; //cycle type
70  bRestart = ReadCycleType(cycletype); //get the cycle type
71 
72  if((gentype == GeneratorType::ConcentricBraid ||
73  gentype == GeneratorType::FourCover) &&
74  cycletype == CycleType::Tour)
75  {
76  printf("Substituting joined tourney for knight's tour.\n");
77  cycletype = CycleType::TourFromTourney;
78  } //if
79 
80  if(!bRestart){
81  bool obfuscate = false; //obfuscate flag
82  bool bRestart = ReadObfuscate(obfuscate); //get the obfuscate flag
83 
84  if(!bRestart) //start the task
85  StartTask(task, CTourneyDesc(gentype, cycletype, obfuscate), nNumThreads);
86  } //if
87  } //if
88  } //while
89  } //while
90 
91  return 0; //what could possibly go wrong?
92 } //main
Header for task functions.
Defines, enumerated types, and typedefs.
Useful includes.
Tourney descriptor.
Definition: Structs.h:40
bool ReadObfuscate(bool &obfuscate)
Read obfuscate status from stdin.
Definition: Input.cpp:262
Header for the tourney and knight's tour generator CGenerator.
Header for helper functions.
bool ReadTask(Task &t)
Read the task from stdin.
Definition: Input.cpp:293
GeneratorType
Generator type.
Definition: Defines.h:47
Task
Task type.
Definition: Defines.h:68
int main()
Main.
Definition: Main.cpp:41
bool ReadGeneratorType(GeneratorType &t)
Read the generator type from stdin.
Definition: Input.cpp:152
bool StartTask(Task task, const CTourneyDesc &t, int nNumThreads)
Start task.
Definition: Task.cpp:118
Header for input functions.
CycleType
Cycle type.
Definition: Defines.h:58
UINT timeGetTime()
Something a little bit like timeGetTime for *NIX.
Definition: Helpers.cpp:52
bool ReadCycleType(CycleType &t)
Read the cycle type from stdin.
Definition: Input.cpp:216