Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
BaseBoard.h
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 #ifndef __BaseBoard__
27 #define __BaseBoard__
28 
29 #include "Includes.h"
30 #include "Defines.h"
31 #include "Structs.h"
32 #include "Helpers.h"
33 
66 
67 #include "Random.h"
68 
69 class CBaseBoard{
70  protected:
72 
73  UINT m_nWidth = 0;
75  UINT m_nSize = 0;
76 
77  int* m_nMove = nullptr;
78  int* m_nMove2 = nullptr;
79 
80  //helper functions
81 
82  bool CellIndexInRange(int index);
83  bool InRangeX(int x);
84  bool InRangeY(int y);
85 
86  bool IsMove(int i, int j);
87  int GetDest(int i, const MoveDelta& delta);
88 
89  UINT GetTourneyIds(int*& id);
90 
91  public:
92  CBaseBoard();
93  CBaseBoard(UINT n);
94  CBaseBoard(UINT w, UINT h);
95  CBaseBoard(int move[], UINT w, UINT h);
96 
97  ~CBaseBoard();
98 
99  void Clear();
100 
101  void MakeDirected();
102  void MakeUndirected();
103 
104  bool IsTour();
105  bool IsTourney();
106 
107  bool IsDirected();
108  bool IsUndirected();
109 
110  bool IsKnightMove(int i, int j);
111  bool IsUnused(int index);
112  bool IsUnused(int pos, const MoveDelta& delta);
113  bool IsOnBoard(int pos, const MoveDelta& delta);
114 
115  int GetAvailableMoveCount(int index);
116 
117  bool InsertUndirectedMove(int src, int dest);
118  bool InsertDirectedMove(int src, int dest);
119  bool DeleteMove(int src, int dest);
120 
121  void Save(std::string& name);
122  void SaveToSVG(std::string& name);
123 
124  int GetMoveIndex(int src, int dest);
125 
126  void CopyToSubBoard(CBaseBoard& b, int x, int y);
127 
128  int GetWidth();
129  int GetHeight();
130  int GetSize();
131 
132  int operator[](int index);
133 }; //CBaseBoard
134 
135 #endif
136 
bool InsertDirectedMove(int src, int dest)
Insert a directed move.
Definition: BaseBoard.cpp:501
int GetHeight()
Get height.
Definition: BaseBoard.cpp:801
int GetMoveIndex(int src, int dest)
Get move index.
Definition: BaseBoard.cpp:408
bool IsUnused(int index)
Test for unused cell.
Definition: BaseBoard.cpp:161
Base chessboard.
Definition: BaseBoard.h:69
Defines, enumerated types, and typedefs.
bool CellIndexInRange(int index)
Index in range test.
Definition: BaseBoard.cpp:102
bool DeleteMove(int src, int dest)
Delete a move.
Definition: BaseBoard.cpp:528
bool IsDirected()
Directed board test.
Definition: BaseBoard.cpp:319
UINT GetTourneyIds(int *&id)
Get tourney identifier for each cell.
Definition: BaseBoard.cpp:599
int GetDest(int i, const MoveDelta &delta)
Get destination of move.
Definition: BaseBoard.cpp:393
void MakeDirected()
Make into a directed board.
Definition: BaseBoard.cpp:335
Useful includes.
bool IsUndirected()
Undirected board test.
Definition: BaseBoard.cpp:327
int GetSize()
Get size.
Definition: BaseBoard.cpp:808
UINT m_nSize
Board size in cells.
Definition: BaseBoard.h:75
std::pair< int, int > MoveDelta
Move delta for a knight's move.
Definition: Helpers.h:42
Header for the structs CSearchRequest, CSearchResult, and CRect.
bool IsKnightMove(int i, int j)
Knight's move test.
Definition: BaseBoard.cpp:138
Header for helper functions.
int * m_nMove2
Secondary move table.
Definition: BaseBoard.h:78
bool IsOnBoard(int pos, const MoveDelta &delta)
Move stays on board.
Definition: BaseBoard.cpp:190
unsigned int UINT
Abbreviation for unsigned integer.
Definition: Defines.h:84
bool InRangeY(int y)
Y coordinate in range test.
Definition: BaseBoard.cpp:118
void Save(std::string &name)
Save board to a text file.
Definition: BaseBoard.cpp:571
bool IsTourney()
Tourney test.
Definition: BaseBoard.cpp:268
int GetAvailableMoveCount(int index)
Get number of moves from a cell.
Definition: BaseBoard.cpp:205
Pseudorandom number generator (PRNG for short).
Definition: Random.h:38
bool IsMove(int i, int j)
Move test.
Definition: BaseBoard.cpp:127
int * m_nMove
Primary move table.
Definition: BaseBoard.h:77
Header for the pseudo-random number generator CRandom.
UINT m_nHeight
Board height in cells.
Definition: BaseBoard.h:74
CBaseBoard()
Constructor.
Definition: BaseBoard.cpp:36
void CopyToSubBoard(CBaseBoard &b, int x, int y)
Copy to sub-board.
Definition: BaseBoard.cpp:443
int operator[](int index)
Get a move from the board.
Definition: BaseBoard.cpp:232
bool IsTour()
Knight's tour test.
Definition: BaseBoard.cpp:240
~CBaseBoard()
Destructor.
Definition: BaseBoard.cpp:81
void MakeUndirected()
Make into an undirected board.
Definition: BaseBoard.cpp:351
void SaveToSVG(std::string &name)
Save to an SVG file.
Definition: BaseBoard.cpp:641
UINT m_nWidth
Board width in cells.
Definition: BaseBoard.h:73
CRandom m_cRandom
PRNG.
Definition: BaseBoard.h:71
int GetWidth()
Get width.
Definition: BaseBoard.cpp:794
bool InsertUndirectedMove(int src, int dest)
Insert an undirected move.
Definition: BaseBoard.cpp:482
void Clear()
Clear the board of moves.
Definition: BaseBoard.cpp:89
bool InRangeX(int x)
X coordinate in range test.
Definition: BaseBoard.cpp:110