Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
FourCover.cpp
Go to the documentation of this file.
1 
4 // MIT License
5 //
6 // Copyright (c) 2020 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 "FourCover.h"
27 
33 
35  b.InsertUndirectedMove(v[0], v[1]);
36  b.InsertUndirectedMove(v[1], v[2]);
37  b.InsertUndirectedMove(v[2], v[3]);
38  b.InsertUndirectedMove(v[3], v[0]);
39 } //Generate4Cycle
40 
44 
46  const int w = b.GetWidth(); //board width
47  const int h = b.GetHeight(); //board height
48 
49  if(w%4 != 0 || h%4 != 0)return; //width and height must be divisible by 4
50 
51  for(int i=0; i<h; i+=4)
52  for(int j=0; j<w; j+=4){
53  int v[4]; //four vertices in the cycle
54 
55  v[0] = i*w + j;
56  v[1] = v[0] + w + 2;
57  v[2] = v[1] + 2*w + 1;
58  v[3] = v[2] - w - 2;
59 
60  Generate4Cycle(b, v); //first edge
61 
62  v[0]++;
63  v[1] = v[0] + w + 2;
64  v[2] = v[1] + 2*w - 1;
65  v[3] = v[2] - w - 2;
66 
67  Generate4Cycle(b, v); //second edge
68 
69  v[0]++;
70  v[1] = v[0] + 2*w + 1;
71  v[2] = v[1] + w - 2;
72  v[3] = v[2] - 2*w - 1;
73 
74  Generate4Cycle(b, v); //third edge
75 
76  v[0]++;
77  v[1] = v[0] + 2*w - 1;
78  v[2] = v[1] + w - 2;
79  v[3] = v[2] - 2*w + 1;
80 
81  Generate4Cycle(b, v); //fourth edge
82  } //for
83 } //Generate
int GetHeight()
Get height.
Definition: BaseBoard.cpp:801
Header for the four-cover tourney generator CFourCover.
void Generate(CBoard &b)
Generate a four-cover tourney.
Definition: FourCover.cpp:45
Chessboard.
Definition: Board.h:42
void Generate4Cycle(CBoard &b, int v[4])
Generate a 4-cycle.
Definition: FourCover.cpp:34
int GetWidth()
Get width.
Definition: BaseBoard.cpp:794
bool InsertUndirectedMove(int src, int dest)
Insert an undirected move.
Definition: BaseBoard.cpp:482