Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
Rail.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 #include "Defines.h"
27 #include "Includes.h"
28 #include "Helpers.h"
29 
30 #include "Rail.h"
31 
32 extern MoveDeltas g_vecDeltas;
33 
44 
45 CRail::CRail(int src0, int dest0, int src1, int dest1, UINT w):
46  m_nSrc0(src0), m_nDest0(dest0), m_nSrc1(src1), m_nDest1(dest1), m_nWidth(w){
47 } //constructor
48 
54 
55 bool CRail::IsKnightMove(int i, int j){
56  for(MoveDelta delta: g_vecDeltas){
57  const int x = i%m_nWidth + delta.first;
58  const int y = i/m_nWidth + delta.second;
59 
60  if(j == y*m_nWidth + x)
61  return true;
62  } //for
63 
64  return false;
65 } //IsKnightMove
66 
70 
71 void CRail::GetEdge0(int& src, int& dest){
72  src = m_nSrc0;
73  dest = m_nDest0;
74 } //GetEdge0
75 
79 
80 void CRail::GetEdge1(int& src, int& dest){
81  src = m_nSrc1;
82  dest = m_nDest1;
83 } //GetEdge1
Defines, enumerated types, and typedefs.
int m_nDest0
Index of cell at the other end of first edge.
Definition: Rail.h:44
Useful includes.
std::pair< int, int > MoveDelta
Move delta for a knight's move.
Definition: Helpers.h:42
int m_nWidth
Width of chessboard.
Definition: Rail.h:49
Header for helper functions.
void GetEdge0(int &src, int &dest)
Get first edge.
Definition: Rail.cpp:71
unsigned int UINT
Abbreviation for unsigned integer.
Definition: Defines.h:84
bool IsKnightMove(int i, int j)
Knight's move test.
Definition: Rail.cpp:55
void GetEdge1(int &src, int &dest)
Get second edge.
Definition: Rail.cpp:80
int m_nSrc1
Index of cell at one end of second edge.
Definition: Rail.h:46
Header for CRail.
int m_nSrc0
Index of cell at one end of first edge.
Definition: Rail.h:43
MoveDeltas g_vecDeltas
Move deltas for all possible knight's moves.
Definition: Helpers.cpp:68
int m_nDest1
Index of cell at the other end of second edge.
Definition: Rail.h:47
std::vector< MoveDelta > MoveDeltas
Move deltas for knight's moves.
Definition: Helpers.h:43
CRail(int src0, int dest0, int src1, int dest1, UINT w)
Constructor.
Definition: Rail.cpp:45