HOG2
Hexagon.cpp
Go to the documentation of this file.
1 //
2 // Hexagon.cpp
3 // Hexagon
4 //
5 // Created by Nathan Sturtevant on 11/13/21.
6 // Copyright © 2021 MovingAI. All rights reserved.
7 //
8 
9 #include "Hexagon.h"
10 #include <ctype.h>
11 
12 #pragma mark -
13 #pragma mark Efficient Hexagon Search Code
14 #pragma mark -
15 
16 constexpr uint64_t bits(uint64_t a, uint64_t b, uint64_t c)
17 {
18 // const uint64_t one = 1;
19  return ((((uint64_t)1)<<a)|(((uint64_t)1)<<b)|(((uint64_t)1)<<c));
20 }
21 
22 constexpr uint64_t bits(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f)
23 {
24  return bits(a, b, c)|bits(d, e, f);
25 }
26 
27 const int rotateCWTable[54] =
28 {5,6,14,15,25,26,37,3,4,12,13,23,24,35,36,46,1,2,10,11,21,22,33,34,44,45,53,0,8,9,19,20,31,32,42,43,51,52,7,17,18,29,30,40,41,49,50,16,27,28,38,39,47,48};
29 
30 const int flipTable[54] =
31 {47,48,49,50,51,52,53,38,39,40,41,42,43,44,45,46,27,28,29,30,31,32,33,34,35,36,37,16,17,18,19,20,21,22,23,24,25,26,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6};
32 
34 {
35 // kHexagon = 0,
36  4, // no flip symmetry
37 // kButterfly = 1,
38  42, // no flip symmetry
39 // kElbow = 2,
40  72, // no symmetry
41 // kLine = 3,
42  72/2,
43 // kMountains = 4,
44  156/2,
45 // kWrench = 5,
46  156/2,
47 // kTriangle = 6,
48  144/2,
49 // kHook = 7,
50  168/2,
51 // kTrapezoid = 8,
52  126,
53 // kSnake = 9
54  72/2
55 };
56 
57 const uint64_t locations[numPieces][14*6*2+1] =
58 { // pieces
59  { // hexagon piece - symmetric in all ways
60 // 4, // count
61 // bits(0, 1, 2, 8, 9, 10), bits(2, 3, 4, 10, 11, 12),
62 // bits(9, 10, 11, 19, 20, 21), bits(20, 21, 22, 31, 32, 33)
63 
64  // re-ordered so first 4 are the ones we want. The remaining ones are used for symmetry building
65  4, // kHexagon count
66  bits(0, 1, 2, 8, 9, 10), bits(2, 3, 4, 10, 11, 12), bits(9, 10, 11, 19, 20, 21), bits(20, 21, 22, 31, 32, 33),
67  bits(7, 8, 9, 17, 18, 19), bits(11, 12, 13, 21, 22, 23), bits(13, 14, 15, 23, 24, 25), bits(4, 5, 6, 12, 13, 14),
68  bits(16, 17, 18, 27, 28, 29), bits(18, 19, 20, 29, 30, 31), bits(22, 23, 24, 33, 34, 35), bits(24, 25, 26, 35, 36, 37),
69  bits(28, 29, 30, 38, 39, 40), bits(30, 31, 32, 40, 41, 42), bits(32, 33, 34, 42, 43, 44), bits(34, 35, 36, 44, 45, 46),
70  bits(39, 40, 41, 47, 48, 49), bits(41, 42, 43, 49, 50, 51), bits(43, 44, 45, 51, 52, 53)
71 
72 
73 // 19, // count
74 // bits(0, 1, 2, 8, 9, 10), bits(2, 3, 4, 10, 11, 12), bits(4, 5, 6, 12, 13, 14),
75 // bits(7, 8, 9, 17, 18, 19), bits(9, 10, 11, 19, 20, 21), bits(11, 12, 13, 21, 22, 23), bits(13, 14, 15, 23, 24, 25),
76 // bits(16, 17, 18, 27, 28, 29), bits(18, 19, 20, 29, 30, 31), bits(20, 21, 22, 31, 32, 33), bits(22, 23, 24, 33, 34, 35), bits(24, 25, 26, 35, 36, 37),
77 // bits(28, 29, 30, 38, 39, 40), bits(30, 31, 32, 40, 41, 42), bits(32, 33, 34, 42, 43, 44), bits(34, 35, 36, 44, 45, 46),
78 // bits(39, 40, 41, 47, 48, 49), bits(41, 42, 43, 49, 50, 51), bits(43, 44, 45, 51, 52, 53)
79  },
80  { // butterfly (not in my original set) - symmetric left to right and top to bottom
81  42, // kButterfly count
82  bits(1, 2, 3, 9, 10, 11), bits(3, 4, 5, 11, 12, 13),
83  bits(8, 9, 10, 18, 19, 20), bits(10, 11, 12, 20, 21, 22), bits(12, 13, 14, 22, 23, 24),
84  bits(17, 18, 19, 28, 29, 30), bits(19, 20, 21, 30, 31, 32), bits(21, 22, 23, 32, 33, 34), bits(23, 24, 25, 34, 35, 36),
85  bits(29, 30, 31, 39, 40, 41), bits(31, 32, 33, 41, 42, 43), bits(33, 34, 35, 43, 44, 45),
86  bits(40, 41, 42, 48, 49, 50), bits(42, 43, 44, 50, 51, 52),
87  // rotated clockwise
88  bits(6, 14, 15, 12, 13, 23), bits(15, 25, 26, 23, 24, 35),
89  bits(4, 12, 13, 10, 11, 21), bits(13, 23, 24, 21, 22, 33), bits(24, 35, 36, 33, 34, 44),
90  bits(2, 10, 11, 8, 9, 19), bits(11, 21, 22, 19, 20, 31), bits(22, 33, 34, 31, 32, 42), bits(34, 44, 45, 42, 43, 51),
91  bits(9, 19, 20, 17, 18, 29), bits(20, 31, 32, 29, 30, 40), bits(32, 42, 43, 40, 41, 49),
92  bits(18, 29, 30, 27, 28, 38), bits(30, 40, 41, 38, 39, 47),
93  // rotated CCW
94  bits(16, 17, 7, 29, 18, 19), bits(7, 8, 0, 19, 9, 10),
95  bits(28, 29, 18, 40, 30, 31), bits(18, 19, 9, 31, 20, 21), bits(9, 10, 2, 21, 11, 12),
96  bits(39, 40, 30, 49, 41, 42), bits(30, 31, 20, 42, 32, 33), bits(20, 21, 11, 33, 22, 23), bits(11, 12, 4, 23, 13, 14),
97  bits(41, 42, 32, 51, 43, 44), bits(32, 33, 22, 44, 34, 35), bits(22, 23, 13, 35, 24, 25),
98  bits(43, 44, 34, 53, 45, 46), bits(34, 35, 24, 46, 36, 37)
99  },
100  { // elbow piece - note this has rotational symmetry with fliping the piece over
101  // so it has 6 30 degree rotations possible
102  12*6, // kElbow count
103  bits(0, 1, 2, 3, 7, 8), bits(2, 3, 4, 5, 9, 10),
104  bits(7, 8, 9, 10, 16, 17), bits(9, 10, 11, 12, 18, 19), bits(11, 12, 13, 14, 20, 21),
105  bits(18, 19, 20, 21, 28, 29), bits(20, 21, 22, 23, 30, 31), bits(22, 23, 24, 25, 32, 33),
106  bits(30, 31, 32, 33, 39, 40), bits(32, 33, 34, 35, 41, 42), bits(34, 35, 36, 37, 43, 44),
107  bits(41, 42, 43, 44, 48, 49),
108  // rotated 60
109  bits(1, 2, 3, 4, 12, 13), bits(3, 4, 5, 6, 14, 15),
110  bits(8, 9, 10, 11, 21, 22), bits(10, 11, 12, 13, 23, 24), bits(12, 13, 14, 15, 25, 26),
111  bits(17, 18, 19, 20, 31, 32), bits(19, 20, 21, 22, 33, 34), bits(21, 22, 23, 24, 35, 36),
112  bits(27, 28, 29, 30, 40, 41), bits(29, 30, 31, 32, 42, 43), bits(31, 32, 33, 34, 44, 45),
113  bits(40, 41, 42, 43, 51, 52),
114  // rotated 120 (elbow points right)
115  bits(15, 25, 26, 37, 36, 46), bits(24, 35, 36, 46, 45, 53),
116  bits(6, 14, 15, 25, 24, 35), bits(13, 23, 24, 35, 34, 44), bits(22, 33, 34, 44, 43, 51),
117  bits(4, 12, 13, 23, 22, 33), bits(11, 21, 22, 33, 32, 42), bits(20, 31, 32, 42, 41, 49),
118  bits(2, 10, 11, 21, 20, 31), bits(9, 19, 20, 31, 30, 40), bits(18, 29, 30, 40, 39, 47),
119  bits(0, 8, 9, 19, 18, 29),
120  // rotated 180 (elbow bottom right)
121  bits(48, 49, 50, 51, 43, 44), bits(50, 51, 52, 53, 45, 46),
122  bits(43, 44, 45, 46, 36, 37), bits(41, 42, 43, 44, 34, 35), bits(39, 40, 41, 42, 32, 33),
123  bits(32, 33, 34, 35, 24, 25), bits(30, 31, 32, 33, 22, 23), bits(28, 29, 30, 31, 20, 21),
124  bits(20, 21, 22, 23, 13, 14), bits(18, 19, 20, 21, 11, 12), bits(16, 17, 18, 19, 9, 10),
125  bits(9, 10, 11, 12, 4, 5),
126  // rotated 240 (elbow bottom left)
127  bits(47, 48, 49, 50, 38, 39), bits(49, 50, 51, 52, 40, 41),
128  bits(38, 39, 40, 41, 27, 28), bits(40, 41, 42, 43, 29, 30), bits(42, 43, 44, 45, 31, 32),
129  bits(29, 30, 31, 32, 17, 18), bits(31, 32, 33, 34, 19, 20), bits(33, 34, 35, 36, 21, 22),
130  bits(19, 20, 21, 22, 8, 9), bits(21, 22, 23, 24, 10, 11), bits(23, 24, 25, 26, 12, 13),
131  bits(10, 11, 12, 13, 1, 2),
132  // rotated 300 (elbow left)
133  bits(7, 17, 16, 27, 28, 38), bits(0, 8, 7, 17, 18, 29),
134  bits(18, 29, 28, 38, 39, 47), bits(9, 19, 18, 29, 30, 40), bits(2, 10, 9, 19, 20, 31),
135  bits(20, 31, 30, 40, 41, 49), bits(11, 21, 20, 31, 32, 42), bits(4, 12, 11, 21, 22, 33),
136  bits(22, 33, 32, 42, 43, 51), bits(13, 23, 22, 33, 34, 44), bits(6, 14, 13, 23, 24, 35),
137  bits(24, 35, 34, 44, 45, 53)
138  },
139  { // long parallelogram - symmetric left to right
140  24*3, // kLine count
141  // regular - flipped
142  bits(0, 1, 2, 3, 4, 5),
143  bits(7, 8, 9, 10, 11, 12), bits(9, 10, 11, 12, 13, 14),
144  bits(16, 17, 18, 19, 20, 21), bits(18, 19, 20, 21, 22, 23), bits(20, 21, 22, 23, 24, 25),
145  bits(28, 29, 30, 31, 32, 33), bits(30, 31, 32, 33, 34, 35), bits(32, 33, 34, 35, 36, 37),
146  bits(39, 40, 41, 42, 43, 44), bits(41, 42, 43, 44, 45, 46),
147  bits(48, 49, 50, 51, 52, 53),
148  // one clockwise rotation, flipped
149  bits(5, 6, 14, 15, 25, 26),
150  bits(3, 4, 12, 13, 23, 24), bits(12, 13, 23, 24, 35, 36),
151  bits(1, 2, 10, 11, 21, 22), bits(10, 11, 21, 22, 33, 34), bits(21, 22, 33, 34, 44, 45),
152  bits(8, 9, 19, 20, 31, 32), bits(19, 20, 31, 32, 42, 43), bits(31, 32, 42, 43, 51, 52),
153  bits(17, 18, 29, 30, 40, 41), bits(29, 30, 40, 41, 49, 50),
154  bits(27, 28, 38, 39, 47, 48),
155  // one CCW rotation, flipped
156  bits(27, 16, 17, 7, 8, 0),
157  bits(38, 28, 29, 18, 19, 9), bits(29, 18, 19, 9, 10, 2),
158  bits(47, 39, 40, 30, 31, 20), bits(40, 30, 31, 20, 21, 11), bits(31, 20, 21, 11, 12, 4),
159  bits(49, 41, 42, 32, 33, 22), bits(42, 32, 33, 22, 23, 13), bits(33, 22, 23, 13, 14, 6),
160  bits(51, 43, 44, 34, 35, 24), bits(44, 34, 35, 24, 25, 15),
161  bits(53, 45, 46, 36, 37, 26),
162  // kLine initial
163  bits(1, 2, 3, 4, 5, 6),
164  bits(8, 9, 10, 11, 12, 13), bits(10, 11, 12, 13, 14, 15),
165  bits(17, 18, 19, 20, 21, 22), bits(19, 20, 21, 22, 23, 24), bits(21, 22, 23, 24, 25, 26),
166  bits(27, 28, 29, 30, 31, 32), bits(29, 30, 31, 32, 33, 34), bits(31, 32, 33, 34, 35, 36),
167  bits(38, 39, 40, 41, 42, 43), bits(40, 41, 42, 43, 44, 45),
168  bits(47, 48, 49, 50, 51, 52),
169  // one clockwise rotation
170  bits(6, 14, 15, 25, 26, 37),
171  bits(4, 12, 13, 23, 24, 35), bits(13, 23, 24, 35, 36, 46),
172  bits(2, 10, 11, 21, 22, 33), bits(11, 21, 22, 33, 34, 44), bits(22, 33, 34, 44, 45, 53),
173  bits(0, 8, 9, 19, 20, 31), bits(9, 19, 20, 31, 32, 42), bits(20, 31, 32, 42, 43, 51),
174  bits(7, 17, 18, 29, 30, 40), bits(18, 29, 30, 40, 41, 49),
175  bits(16, 27, 28, 38, 39, 47),
176  // one CCW rotation
177  bits(16, 17, 7, 8, 0, 1),
178  bits(28, 29, 18, 19, 9, 10), bits(18, 19, 9, 10, 2, 3),
179  bits(39, 40, 30, 31, 20, 21), bits(30, 31, 20, 21, 11, 12), bits(20, 21, 11, 12, 4, 5),
180  bits(48, 49, 41, 42, 32, 33), bits(41, 42, 32, 33, 22, 23), bits(32, 33, 22, 23, 13, 14),
181  bits(50, 51, 43, 44, 34, 35), bits(43, 44, 34, 35, 24, 25),
182  bits(52, 53, 45, 46, 36, 37), },
183  { // two trapezoids on top of each other [kMountain] (note some are removed because they leave unfillable gaps
184  52*3, // kMountains count
185  // original
186  bits(0, 1, 2, 7, 8, 9), bits(2, 3, 4, 9, 10, 11), bits(4, 5, 6, 11, 12, 13),
187  bits(7, 8, 9, 16, 17, 18), bits(9, 10, 11, 18, 19, 20), bits(11, 12, 13, 20, 21, 22), bits(13, 14, 15, 22, 23, 24),
188  bits(18, 19, 20, 28, 29, 30), bits(20, 21, 22, 30, 31, 32), bits(22, 23, 24, 32, 33, 34), //bits(24, 25, 26, 34, 35, 36),
189  bits(30, 31, 32, 39, 40, 41), bits(32, 33, 34, 41, 42, 43), //bits(34, 35, 36, 43, 44, 45),
190  bits(41, 42, 43, 48, 49, 50), //bits(43, 44, 45, 50, 51, 52),
191  // original flipped both left/right and up/down
192  /*bits(1, 2, 3, 8, 9, 10),*/ bits(3, 4, 5, 10, 11, 12),
193  /*bits(8, 9, 10, 17, 18, 19),*/ bits(10, 11, 12, 19, 20, 21), bits(12, 13, 14, 21, 22, 23),
194  /*bits(17, 18, 19, 27, 28, 29),*/ bits(19, 20, 21, 29, 30, 31), bits(21, 22, 23, 31, 32, 33), bits(23, 24, 25, 33, 34, 35),
195  bits(29, 30, 31, 38, 39, 40), bits(31, 32, 33, 40, 41, 42), bits(33, 34, 35, 42, 43, 44), bits(35, 36, 37, 44, 45, 46),
196  bits(40, 41, 42, 47, 48, 49), bits(42, 43, 44, 49, 50, 51), bits(44, 45, 46, 51, 52, 53),
197 
198  // original rotated CW - 52+
199  bits(5, 6, 14, 3, 4, 12), bits(14, 15, 25, 12, 13, 23), bits(25, 26, 37, 23, 24, 35),
200  bits(3, 4, 12, 1, 2, 10), bits(12, 13, 23, 10, 11, 21), bits(23, 24, 35, 21, 22, 33), bits(35, 36, 46, 33, 34, 44),
201  bits(10, 11, 21, 8, 9, 19), bits(21, 22, 33, 19, 20, 31), bits(33, 34, 44, 31, 32, 42),
202  bits(19, 20, 31, 17, 18, 29), bits(31, 32, 42, 29, 30, 40),
203  bits(29, 30, 40, 27, 28, 38),
204  // flipped top to bottom and left to right
205  bits(15, 25, 26, 13, 23, 24),
206  bits(13, 23, 24, 11, 21, 22), bits(24, 35, 36, 22, 33, 34),
207  bits(11, 21, 22, 9, 19, 20), bits(22, 33, 34, 20, 31, 32), bits(34, 44, 45, 32, 42, 43),
208  bits(9, 19, 20, 7, 17, 18), bits(20, 31, 32, 18, 29, 30), bits(32, 42, 43, 30, 40, 41), bits(43, 51, 52, 41, 49, 50),
209  bits(18, 29, 30, 16, 27, 28), bits(30, 40, 41, 28, 38, 39), bits(41, 49, 50, 39, 47, 48),
210 
211  // original rotated CCW - 104+
212  bits(27, 16, 17, 38, 28, 29), bits(17, 7, 8, 29, 18, 19), bits(8, 0, 1, 19, 9, 10),
213  bits(38, 28, 29, 47, 39, 40), bits(29, 18, 19, 40, 30, 31), bits(19, 9, 10, 31, 20, 21), bits(10, 2, 3, 21, 11, 12),
214  bits(40, 30, 31, 49, 41, 42), bits(31, 20, 21, 42, 32, 33), bits(21, 11, 12, 33, 22, 23),
215  bits(42, 32, 33, 51, 43, 44), bits(33, 22, 23, 44, 34, 35),
216  bits(44, 34, 35, 53, 45, 46),
217  // flipped top to bottom and left to right (180 degree rotation)
218  bits(7, 8, 0, 18, 19, 9),
219  bits(18, 19, 9, 30, 31, 20), bits(9, 10, 2, 20, 21, 11),
220  bits(30, 31, 20, 41, 42, 32), bits(20, 21, 11, 32, 33, 22), bits(11, 12, 4, 22, 23, 13),
221  bits(41, 42, 32, 50, 51, 43), bits(32, 33, 22, 43, 44, 34), bits(22, 23, 13, 34, 35, 24), bits(13, 14, 6, 24, 25, 15),
222  bits(43, 44, 34, 52, 53, 45), bits(34, 35, 24, 45, 46, 36), bits(24, 25, 15, 36, 37, 26),
223 
224  // original flipped top to bottom
225  bits(1, 2, 3, 10, 11, 12), //bits(3, 4, 5, 12, 13, 14),
226  bits(8, 9, 10, 19, 20, 21), bits(10, 11, 12, 21, 22, 23), //bits(12, 13, 14, 23, 24, 25),
227  bits(17, 18, 19, 29, 30, 31), bits(19, 20, 21, 31, 32, 33), bits(21, 22, 23, 33, 34, 35), //bits(23, 24, 25, 35, 36, 37),
228  bits(27, 28, 29, 38, 39, 40), bits(29, 30, 31, 40, 41, 42), bits(31, 32, 33, 42, 43, 44), bits(33, 34, 35, 44, 45, 46),
229  bits(38, 39, 40, 47, 48, 49), bits(40, 41, 42, 49, 50, 51), bits(42, 43, 44, 51, 52, 53),
230  // original flipped left to right
231  bits(0, 1, 2, 9, 10, 11), bits(2, 3, 4, 11, 12, 13), bits(4, 5, 6, 13, 14, 15),
232  bits(7, 8, 9, 18, 19, 20), bits(9, 10, 11, 20, 21, 22), bits(11, 12, 13, 22, 23, 24), bits(13, 14, 15, 24, 25, 26),
233  /*16-18,28-30,*/ bits(18, 19, 20, 30, 31, 32), bits(20, 21, 22, 32, 33, 34), bits(22, 23, 24, 34, 35, 36),
234  /*28-30,39-41,*/ bits(30, 31, 32, 41, 42, 43), bits(32, 33, 34, 43, 44, 45),
235  /*39-41,48-50,*/ bits(41, 42, 43, 50, 51, 52),
236 
237  // original rotated CW flipped top to bottom
238  bits(6, 14, 15, 13, 23, 24),
239  bits(4, 12, 13, 11, 21, 22), bits(13, 23, 24, 22, 33, 34),
240  bits(2, 10, 11, 9, 19, 20), bits(11, 21, 22, 20, 31, 32), bits(22, 33, 34, 32, 42, 43),
241  bits(0, 8, 9, 7, 17, 18), bits(9, 19, 20, 18, 29, 30), bits(20, 31, 32, 30, 40, 41), bits(32, 42, 43, 41, 49, 50),
242  bits(7, 17, 18, 16, 27, 28), bits(18, 29, 30, 28, 38, 39), bits(30, 40, 41, 39, 47, 48),
243  // original rotated CW flipped left to right
244  bits(5, 6, 14, 12, 13, 23), bits(14, 15, 25, 23, 24, 35), bits(25, 26, 37, 35, 36, 46),
245  bits(3, 4, 12, 10, 11, 21), bits(12, 13, 23, 21, 22, 33), bits(23, 24, 35, 33, 34, 44), bits(35, 36, 46, 44, 45, 53),
246  bits(10, 11, 21, 19, 20, 31), bits(21, 22, 33, 31, 32, 42), bits(33, 34, 44, 42, 43, 51),
247  bits(19, 20, 31, 29, 30, 40), bits(31, 32, 42, 40, 41, 49),
248  bits(29, 30, 40, 38, 39, 47),
249 
250  // original rotated CCW flipped top to bottom
251  bits(16, 17, 7, 18, 19, 9),
252  bits(28, 29, 18, 30, 31, 20), bits(18, 19, 9, 20, 21, 11),
253  bits(39, 40, 30, 41, 42, 32), bits(30, 31, 20, 32, 33, 22), bits(20, 21, 11, 22, 23, 13),
254  bits(48, 49, 41, 50, 51, 43), bits(41, 42, 32, 43, 44, 34), bits(32, 33, 22, 34, 35, 24), bits(22, 23, 13, 24, 25, 15),
255  bits(50, 51, 43, 52, 53, 45), bits(43, 44, 34, 45, 46, 36), bits(34, 35, 24, 36, 37, 26),
256  // original rotated CCW flipped left to right
257  bits(27, 16, 17, 29, 18, 19), bits(17, 7, 8, 19, 9, 10), bits(8, 0, 1, 10, 2, 3),
258  bits(38, 28, 29, 40, 30, 31), bits(29, 18, 19, 31, 20, 21), bits(19, 9, 10, 21, 11, 12), bits(10, 2, 3, 12, 4, 5),
259  bits(40, 30, 31, 42, 32, 33), bits(31, 20, 21, 33, 22, 23), bits(21, 11, 12, 23, 13, 14),
260  bits(42, 32, 33, 44, 34, 35), bits(33, 22, 23, 35, 24, 25),
261  bits(44, 34, 35, 46, 36, 37),
262  },
263  { // long piece a bit like the elbow but asymmetric
264  13*6*2, // kWrench count
265  // meaning there are 6 rotations x 2 after flipping
266  // standard
267  bits(0, 1, 2, 3, 4, 8), bits(2, 3, 4, 5, 6, 10),
268  bits(7, 8, 9, 10, 11, 17), bits(9, 10, 11, 12, 13, 19), bits(11, 12, 13, 14, 15, 21),
269  bits(16, 17, 18, 19, 20, 27), bits(18, 19, 20, 21, 22, 29), bits(20, 21, 22, 23, 24, 31), bits(22, 23, 24, 25, 26, 33),
270  bits(28, 29, 30, 31, 32, 38), bits(30, 31, 32, 33, 34, 40), bits(32, 33, 34, 35, 36, 42),
271  bits(39, 40, 41, 42, 43, 47),
272  // rotated 60
273  bits(4, 5, 6, 14, 15, 25), bits(13, 14, 15, 25, 26, 37),
274  bits(2, 3, 4, 12, 13, 23), bits(11, 12, 13, 23, 24, 35), bits(22, 23, 24, 35, 36, 46),
275  bits(0, 1, 2, 10, 11, 21), bits(9, 10, 11, 21, 22, 33), bits(20, 21, 22, 33, 34, 44), bits(32, 33, 34, 44, 45, 53),
276  bits(7, 8, 9, 19, 20, 31), bits(18, 19, 20, 31, 32, 42), bits(30, 31, 32, 42, 43, 51),
277  bits(16, 17, 18, 29, 30, 40),
278  // rotated 120
279  bits(25, 26, 36, 37, 45, 46), bits(35, 36, 45, 46, 52, 53),
280  bits(14, 15, 24, 25, 34, 35), bits(23, 24, 34, 35, 43, 44), bits(33, 34, 43, 44, 50, 51),
281  bits(5, 6, 13, 14, 22, 23), bits(12, 13, 22, 23, 32, 33), bits(21, 22, 32, 33, 41, 42), bits(31, 32, 41, 42, 48, 49),
282  bits(3, 4, 11, 12, 20, 21), bits(10, 11, 20, 21, 30, 31), bits(19, 20, 30, 31, 39, 40),
283  bits(1, 2, 9, 10, 18, 19),
284  // rotated 180
285  bits(47, 48, 49, 50, 51, 43), bits(49, 50, 51, 52, 53, 45),
286  bits(38, 39, 40, 41, 42, 32), bits(40, 41, 42, 43, 44, 34), bits(42, 43, 44, 45, 46, 36),
287  bits(27, 28, 29, 30, 31, 20), bits(29, 30, 31, 32, 33, 22), bits(31, 32, 33, 34, 35, 24), bits(33, 34, 35, 36, 37, 26),
288  bits(17, 18, 19, 20, 21, 11), bits(19, 20, 21, 22, 23, 13), bits(21, 22, 23, 24, 25, 15),
289  bits(10, 11, 12, 13, 14, 6),
290  // rotated 240
291  bits(28, 38, 39, 47, 48, 49), bits(16, 27, 28, 38, 39, 40),
292  bits(30, 40, 41, 49, 50, 51), bits(18, 29, 30, 40, 41, 42), bits(7, 17, 18, 29, 30, 31),
293  bits(32, 42, 43, 51, 52, 53), bits(20, 31, 32, 42, 43, 44), bits(9, 19, 20, 31, 32, 33), bits(0, 8, 9, 19, 20, 21),
294  bits(22, 33, 34, 44, 45, 46), bits(11, 21, 22, 33, 34, 35), bits(2, 10, 11, 21, 22, 23),
295  bits(13, 23, 24, 35, 36, 37),
296  // rotated 300
297  bits(0, 1, 7, 8, 17, 18), bits(7, 8, 16, 17, 27, 28),
298  bits(2, 3, 9, 10, 19, 20), bits(9, 10, 18, 19, 29, 30), bits(18, 19, 28, 29, 38, 39),
299  bits(4, 5, 11, 12, 21, 22), bits(11, 12, 20, 21, 31, 32), bits(20, 21, 30, 31, 40, 41), bits(30, 31, 39, 40, 47, 48),
300  bits(13, 14, 22, 23, 33, 34), bits(22, 23, 32, 33, 42, 43), bits(32, 33, 41, 42, 49, 50),
301  bits(34, 35, 43, 44, 51, 52),
302  // standard - flipped
303  bits(0, 1, 2, 3, 4, 12), bits(2, 3, 4, 5, 6, 14),
304  bits(7, 8, 9, 10, 11, 21), bits(9, 10, 11, 12, 13, 23), bits(11, 12, 13, 14, 15, 25),
305  bits(16, 17, 18, 19, 20, 31), bits(18, 19, 20, 21, 22, 33), bits(20, 21, 22, 23, 24, 35), bits(22, 23, 24, 25, 26, 37),
306  bits(28, 29, 30, 31, 32, 42), bits(30, 31, 32, 33, 34, 44), bits(32, 33, 34, 35, 36, 46),
307  bits(41, 42, 43, 44, 45, 53),
308  // rotated 60 - flipped
309  bits(24, 5, 6, 14, 15, 25), bits(36, 14, 15, 25, 26, 37),
310  bits(22, 3, 4, 12, 13, 23), bits(34, 12, 13, 23, 24, 35), bits(45, 23, 24, 35, 36, 46),
311  bits(20, 1, 2, 10, 11, 21), bits(32, 10, 11, 21, 22, 33), bits(43, 21, 22, 33, 34, 44), bits(52, 33, 34, 44, 45, 53),
312  bits(30, 8, 9, 19, 20, 31), bits(41, 19, 20, 31, 32, 42), bits(50, 31, 32, 42, 43, 51),
313  bits(48, 29, 30, 40, 41, 49),
314  // rotated 120 - flipped
315  bits(44, 26, 36, 37, 45, 46), bits(51, 36, 45, 46, 52, 53),
316  bits(33, 15, 24, 25, 34, 35), bits(42, 24, 34, 35, 43, 44), bits(49, 34, 43, 44, 50, 51),
317  bits(21, 6, 13, 14, 22, 23), bits(31, 13, 22, 23, 32, 33), bits(40, 22, 32, 33, 41, 42), bits(47, 32, 41, 42, 48, 49),
318  bits(19, 4, 11, 12, 20, 21), bits(29, 11, 20, 21, 30, 31), bits(38, 20, 30, 31, 39, 40),
319  bits(27, 9, 19, 18, 28, 29),
320  // rotated 180 - flipped
321  bits(47, 48, 49, 50, 51, 39), bits(49, 50, 51, 52, 53, 41),
322  bits(38, 39, 40, 41, 42, 28), bits(40, 41, 42, 43, 44, 30), bits(42, 43, 44, 45, 46, 32),
323  bits(27, 28, 29, 30, 31, 16), bits(29, 30, 31, 32, 33, 18), bits(31, 32, 33, 34, 35, 20), bits(33, 34, 35, 36, 37, 22),
324  bits(17, 18, 19, 20, 21, 7), bits(19, 20, 21, 22, 23, 9), bits(21, 22, 23, 24, 25, 11),
325  bits(8, 9, 10, 11, 12, 0),
326  // rotated 240 - flipped
327  bits(28, 38, 39, 47, 48, 29), bits(16, 27, 28, 38, 39, 17),
328  bits(30, 40, 41, 49, 50, 31), bits(18, 29, 30, 40, 41, 19), bits(7, 17, 18, 29, 30, 8),
329  bits(32, 42, 43, 51, 52, 33), bits(20, 31, 32, 42, 43, 21), bits(9, 19, 20, 31, 32, 10), bits(0, 8, 9, 19, 20, 1),
330  bits(22, 33, 34, 44, 45, 23), bits(11, 21, 22, 33, 34, 12), bits(2, 10, 11, 21, 22, 3),
331  bits(4, 12, 13, 23, 24, 5),
332  // rotated 300 - flipped
333  bits(0, 1, 7, 8, 17, 2), bits(7, 8, 16, 17, 27, 9),
334  bits(2, 3, 9, 10, 19, 4), bits(9, 10, 18, 19, 29, 11), bits(18, 19, 28, 29, 38, 20),
335  bits(4, 5, 11, 12, 21, 6), bits(11, 12, 20, 21, 31, 13), bits(20, 21, 30, 31, 40, 22), bits(30, 31, 39, 40, 47, 32),
336  bits(13, 14, 22, 23, 33, 15), bits(22, 23, 32, 33, 42, 24), bits(32, 33, 41, 42, 49, 34),
337  bits(24, 25, 34, 35, 44, 26),
338  },
339  { // triangle piece
340  12*6*2, // kTriangle count
341  // regular
342  bits(1, 2, 3, 4, 5, 10),
343  bits(8, 9, 10, 11, 12, 19), bits(10, 11, 12, 13, 14, 21),
344  bits(17, 18, 19, 20, 21, 29), bits(19, 20, 21, 22, 23, 31), bits(21, 22, 23, 24, 25, 33),
345  bits(27, 28, 29, 30, 31, 38), bits(29, 30, 31, 32, 33, 40), bits(31, 32, 33, 34, 35, 42), bits(33, 34, 35, 36, 37, 44),
346  bits(38, 39, 40, 41, 42, 47), bits(40, 41, 42, 43, 44, 49),
347  // rotated 60
348  bits(6, 13, 14, 15, 25, 26),
349  bits(4, 11, 12, 13, 23, 24), bits(13, 22, 23, 24, 35, 36),
350  bits(2, 9, 10, 11, 21, 22), bits(11, 20, 21, 22, 33, 34), bits(22, 32, 33, 34, 44, 45),
351  bits(0, 7, 8, 9, 19, 20), bits(9, 18, 19, 20, 31, 32), bits(20, 30, 31, 32, 42, 43), bits(32, 41, 42, 43, 51, 52),
352  bits(7, 16, 17, 18, 29, 30), bits(18, 28, 29, 30, 40, 41),
353  // rotated 120
354  bits(35, 36, 37, 45, 46, 53),
355  bits(23, 24, 25, 34, 35, 44), bits(33, 34, 35, 43, 44, 51),
356  bits(12, 13, 14, 22, 23, 33), bits(21, 22, 23, 32, 33, 42), bits(31, 32, 33, 41, 42, 49),
357  bits(3, 4, 5, 11, 12, 21), bits(10, 11, 12, 20, 21, 31), bits(19, 20, 21, 30, 31, 40), bits(29, 30, 31, 39, 40, 47),
358  bits(1, 2, 3, 9, 10, 19), bits(8, 9, 10, 18, 19, 29),
359  // rotated 180
360  bits(48, 49, 50, 51, 52, 43),
361  bits(41, 42, 43, 44, 45, 34), bits(39, 40, 41, 42, 43, 32),
362  bits(32, 33, 34, 35, 36, 24), bits(30, 31, 32, 33, 34, 22), bits(28, 29, 30, 31, 32, 20),
363  bits(22, 23, 24, 25, 26, 15), bits(20, 21, 22, 23, 24, 13), bits(18, 19, 20, 21, 22, 11), bits(16, 17, 18, 19, 20, 9),
364  bits(6, 11, 12, 13, 14, 15), bits(9, 10, 11, 12, 13, 4),
365  // rotated 240
366  bits(27, 28, 38, 39, 40, 47),
367  bits(29, 30, 40, 41, 42, 49), bits(17, 18, 29, 30, 31, 40),
368  bits(31, 32, 42, 43, 44, 51), bits(19, 20, 31, 32, 33, 42), bits(8, 9, 19, 20, 21, 31),
369  bits(33, 34, 44, 45, 46, 53), bits(21, 22, 33, 34, 35, 44), bits(10, 11, 21, 22, 23, 33), bits(1, 2, 10, 11, 12, 21),
370  bits(23, 24, 35, 36, 37, 46), bits(12, 13, 23, 24, 25, 35),
371  // rotated 300
372  bits(0, 7, 8, 16, 17, 18),
373  bits(9, 18, 19, 28, 29, 30), bits(2, 9, 10, 18, 19, 20),
374  bits(20, 30, 31, 39, 40, 41), bits(11, 20, 21, 30, 31, 32), bits(4, 11, 12, 20, 21, 22),
375  bits(32, 41, 42, 48, 49, 50), bits(22, 32, 33, 41, 42, 43), bits(13, 22, 23, 32, 33, 34), bits(6, 13, 14, 22, 23, 24),
376  bits(34, 43, 44, 50, 51, 52), bits(24, 34, 35, 43, 44, 45),
377  // flipped
378  bits(0, 7, 8, 9, 10, 11), bits(2, 9, 10, 11, 12, 13),
379  bits(7, 16, 17, 18, 19, 20), bits(9, 18, 19, 20, 21, 22), bits(11, 20, 21, 22, 23, 24), bits(13, 22, 23, 24, 25, 26),
380  bits(18, 28, 29, 30, 31, 32), bits(20, 30, 31, 32, 33, 34), bits(22, 32, 33, 34, 35, 36),
381  bits(30, 39, 40, 41, 42, 43), bits(32, 41, 42, 43, 44, 45),
382  bits(41, 48, 49, 50, 51, 52),
383  // rotated 60 - flipped
384  bits(3, 4, 5, 12, 13, 23), bits(12, 13, 14, 23, 24, 35),
385  bits(1, 2, 3, 10, 11, 21), bits(10, 11, 12, 21, 22, 33), bits(21, 22, 23, 33, 34, 44), bits(33, 34, 35, 44, 45, 53),
386  bits(8, 9, 10, 19, 20, 31), bits(19, 20, 21, 31, 32, 42), bits(31, 32, 33, 42, 43, 51),
387  bits(17, 18, 19, 29, 30, 40), bits(29, 30, 31, 40, 41, 49),
388  bits(27, 28, 29, 38, 39, 47),
389  // rotated 120 - flipped
390  bits(15, 24, 25, 26, 34, 35), bits(24, 34, 35, 36, 43, 44),
391  bits(6, 13, 14, 15, 22, 23), bits(13, 22, 23, 24, 32, 33), bits(22, 32, 33, 34, 41, 42), bits(32, 41, 42, 43, 48, 49),
392  bits(4, 11, 12, 13, 20, 21), bits(11, 20, 21, 22, 30, 31), bits(20, 30, 31, 32, 39, 40),
393  bits(2, 9, 10, 11, 18, 19), bits(9, 18, 19, 20, 28, 29),
394  bits(0, 7, 8, 9, 16, 17),
395  // rotated 180 - flipped
396  bits(42, 43, 44, 45, 46, 53), bits(40, 41, 42, 43, 44, 51),
397  bits(33, 34, 35, 36, 37, 46), bits(31, 32, 33, 34, 35, 44), bits(29, 30, 31, 32, 33, 42), bits(27, 28, 29, 30, 31, 40),
398  bits(21, 22, 23, 24, 25, 35), bits(19, 20, 21, 22, 23, 33), bits(17, 18, 19, 20, 21, 31),
399  bits(10, 11, 12, 13, 14, 23), bits(8, 9, 10, 11, 12, 21),
400  bits(1, 2, 3, 4, 5, 12),
401  // rotated 240 - flipped
402  bits(30, 40, 41, 48, 49, 50), bits(18, 29, 30, 39, 40, 41),
403  bits(32, 42, 43, 50, 51, 52), bits(20, 31, 32, 41, 42, 43), bits(9, 19, 20, 30, 31, 32), bits(0, 8, 9, 18, 19, 20),
404  bits(22, 33, 34, 43, 44, 45), bits(11, 21, 22, 32, 33, 34), bits(2, 10, 11, 20, 21, 22),
405  bits(13, 23, 24, 34, 35, 36), bits(4, 12, 13, 22, 23, 24),
406  bits(6, 14, 15, 24, 25, 26),
407  // rotated 300 - flipped
408  bits(18, 19, 27, 28, 29, 38), bits(9, 10, 17, 18, 19, 29),
409  bits(30, 31, 38, 39, 40, 47), bits(20, 21, 29, 30, 31, 40), bits(11, 12, 19, 20, 21, 31), bits(4, 5, 10, 11, 12, 21),
410  bits(32, 33, 40, 41, 42, 49), bits(22, 23, 31, 32, 33, 42), bits(13, 14, 21, 22, 23, 33),
411  bits(34, 35, 42, 43, 44, 51), bits(24, 25, 33, 34, 35, 44),
412  bits(36, 37, 44, 45, 46, 53),
413  },
414  {
415  14*6*2, // kHook count
416 
417  // V-like piece-flip
418  bits(0, 1, 8, 9, 10, 11), bits(2, 3, 10, 11, 12, 13),
419  bits(7, 8, 17, 18, 19, 20), bits(9, 10, 19, 20, 21, 22), bits(11, 12, 21, 22, 23, 24),
420  bits(16, 17, 27, 28, 29, 30), bits(18, 19, 29, 30, 31, 32), bits(20, 21, 31, 32, 33, 34), bits(22, 23, 33, 34, 35, 36),
421  bits(28, 29, 38, 39, 40, 41), bits(30, 31, 40, 41, 42, 43), bits(32, 33, 42, 43, 44, 45),
422  bits(39, 40, 47, 48, 49, 50), bits(41, 42, 49, 50, 51, 52),
423  // 60-degrees-flip
424  bits(4, 5, 6, 12, 13, 23), bits(13, 14, 15, 23, 24, 35),
425  bits(2, 3, 4, 10, 11, 21), bits(11, 12, 13, 21, 22, 33), bits(22, 23, 24, 33, 34, 44),
426  bits(0, 1, 2, 8, 9, 19), bits(9, 10, 11, 19, 20, 31), bits(20, 21, 22, 31, 32, 42), bits(32, 33, 34, 42, 43, 51),
427  bits(7, 8, 9, 17, 18, 29), bits(18, 19, 20, 29, 30, 40), bits(30, 31, 32, 40, 41, 49),
428  bits(16, 17, 18, 27, 28, 38), bits(28, 29, 30, 38, 39, 47),
429  // 120-degree-flip
430  bits(24, 25, 26, 34, 35, 37), bits(13, 14, 15, 22, 23, 25), bits(4, 5, 6, 11, 12, 14),
431  bits(34, 35, 36, 43, 44, 46), bits(22, 23, 24, 32, 33, 35), bits(11, 12, 13, 20, 21, 23), bits(2, 3, 4, 9, 10, 12),
432  bits(32, 33, 34, 41, 42, 44), bits(20, 21, 22, 30, 31, 33), bits(9, 10, 11, 18, 19, 21), bits(0, 1, 2, 7, 8, 10),
433  bits(30, 31, 32, 39, 40, 42), bits(18, 19, 20, 28, 29, 31), bits(7, 8, 9, 16, 17, 19),
434  // 180-degree-flip
435  bits(42, 43, 44, 45, 52, 53), bits(40, 41, 42, 43, 50, 51),
436  bits(33, 34, 35, 36, 45, 46), bits(31, 32, 33, 34, 43, 44), bits(29, 30, 31, 32, 41, 42),
437  bits(23, 24, 25, 26, 36, 37), bits(21, 22, 23, 24, 34, 35), bits(19, 20, 21, 22, 32, 33), bits(17, 18, 19, 20, 30, 31),
438  bits(12, 13, 14, 15, 24, 25), bits(10, 11, 12, 13, 22, 23), bits(8, 9, 10, 11, 20, 21),
439  bits(3, 4, 5, 6, 13, 14), bits(1, 2, 3, 4,11, 12),
440  // 240-degree-flip
441  bits(30, 40, 41, 47, 48, 49), bits(32, 42, 43, 49, 50, 51), bits(34, 44, 45, 51, 52, 53),
442  bits(18, 29, 30, 38, 39, 40), bits(20, 31, 32, 40, 41, 42), bits(22, 33, 34, 42, 43, 44), bits(24, 35, 36, 44, 45, 46),
443  bits(9, 19, 20, 29, 30, 31), bits(11, 21, 22, 31, 32, 33), bits(13, 23, 24, 33, 34, 35), bits(15, 25, 26, 35, 36, 37),
444  bits(2, 10, 11, 19, 20, 21), bits(4, 12, 13, 21, 22, 23), bits(6, 14, 15, 23, 24, 25),
445  // 300-degree-flip
446  bits(16, 18, 19, 27, 28, 29), bits(7, 9, 10, 17, 18, 19),
447  bits(28, 30, 31, 38, 39, 40), bits(18, 20, 21, 29, 30, 31), bits(9, 11, 12, 19, 20, 21),
448  bits(39, 41, 42, 47, 48, 49), bits(30, 32, 33, 40, 41, 42), bits(20, 22, 23, 31, 32, 33), bits(11, 13, 14, 21, 22, 23),
449  bits(41, 43, 44, 49, 50, 51), bits(32, 34, 35, 42, 43, 44), bits(22, 24, 25, 33, 34, 35),
450  bits(43, 45, 46, 51, 52, 53), bits(34, 36, 37, 44, 45, 46),
451  // hook / V-like piece
452  bits(0, 1, 2, 3, 8, 9), bits(2, 3, 4, 5, 10, 11),
453  bits(7, 8, 9, 10, 17, 18), bits(9, 10, 11, 12, 19, 20), bits(11, 12, 13, 14, 21, 22),
454  bits(16, 17, 18, 19, 27, 28), bits(18, 19, 20, 21, 29, 30), bits(20, 21, 22, 23, 31, 32), bits(22, 23, 24, 25, 33, 34),
455  bits(28, 29, 30, 31, 38, 39), bits(30, 31, 32, 33, 40, 41), bits(32, 33, 34, 35, 42, 43),
456  bits(39, 40, 41, 42, 47, 48), bits(41, 42, 43, 44, 49, 50),
457  // 60-degrees
458  bits(4, 5, 6, 12, 14, 15), bits(13, 14, 15, 23, 25, 26),
459  bits(2, 3, 4, 10, 12, 13), bits(11, 12, 13, 21, 23, 24), bits(22, 23, 24, 33, 35, 36),
460  bits(0, 1, 2, 8, 10, 11), bits(9, 10, 11, 19, 21, 22), bits(20, 21, 22, 31, 33, 34), bits(32, 33, 34, 42, 44, 45),
461  bits(7, 8, 9, 17, 19, 20), bits(18, 19, 20, 29, 31, 32), bits(30, 31, 32, 40, 42, 43),
462  bits(16, 17, 18, 27, 29, 30), bits(28, 29, 30, 38, 40, 41),
463  // 120-degree
464  bits(24, 25, 26, 36, 37, 46), bits(13, 14, 15, 24, 25, 35), bits(4, 5, 6, 13, 14, 23),
465  bits(34, 35, 36, 45, 46, 53), bits(22, 23, 24, 34, 35, 44), bits(11, 12, 13, 22, 23, 33), bits(2, 3, 4, 11, 12, 21),
466  bits(32, 33, 34, 43, 44, 51), bits(20, 21, 22, 32, 33, 42), bits(9, 10, 11, 20, 21, 31), bits(0, 1, 2, 9, 10, 19),
467  bits(30, 31, 32, 41, 42, 49), bits(18, 19, 20, 30, 31, 40), bits(7, 8, 9, 18, 19, 29),
468  // 180-degree
469  bits(44, 45, 50, 51, 52, 53), bits(42, 43, 48, 49, 50, 51),
470  bits(35, 36, 43, 44, 45, 46), bits(33, 34, 41, 42, 43, 44), bits(31, 32, 39, 40, 41, 42),
471  bits(25, 26, 34, 35, 36, 37), bits(23, 24, 32, 33, 34, 35), bits(21, 22, 30, 31, 32, 33), bits(19, 20, 28, 29, 30, 31),
472  bits(14, 15, 22, 23, 24, 25), bits(12, 13, 20, 21, 22, 23), bits(10, 11, 18, 19, 20, 21),
473  bits(5, 6, 11, 12, 13, 14), bits(3, 4, 9, 10, 11, 12),
474  // 240-degree
475  bits(38, 39, 41, 47, 48, 49), bits(40, 41, 43, 49, 50, 51), bits(42, 43, 45, 51, 52, 53),
476  bits(27, 28, 30, 38, 39, 40), bits(29, 30, 32, 40, 41, 42), bits(31, 32, 34, 42, 43, 44), bits(33, 34, 36, 44, 45, 46),
477  bits(17, 18, 20, 29, 30, 31), bits(19, 20, 22, 31, 32, 33), bits(21, 22, 24, 33, 34, 35), bits(23, 24, 26, 35, 36, 37),
478  bits(8, 9, 11, 19, 20, 21), bits(10, 11, 13, 21, 22, 23), bits(12, 13, 15, 23, 24, 25),
479  // 300-degree
480  bits(7, 16, 17, 27, 28, 29), bits(0, 7, 8, 17, 18, 19),
481  bits(18, 28, 29, 38, 39, 40), bits(9, 18, 19, 29, 30, 31), bits(2, 9, 10, 19, 20, 21),
482  bits(30, 39, 40, 47, 48, 49), bits(20, 30, 31, 40, 41, 42), bits(11, 20, 21, 31, 32, 33), bits(4, 11, 12, 21, 22, 23),
483  bits(32, 41, 42, 49, 50, 51), bits(22, 32, 33, 42, 43, 44), bits(13, 22, 23, 33, 34, 35),
484  bits(34, 43, 44, 51, 52, 53), bits(24, 34, 35, 44, 45, 46),
485  },
486  { // small trapezoids -- symmetric left/right
487  126, // kTrapezoid count
488  // upright pieces
489  bits(0, 1, 2), bits(2, 3, 4), bits(4, 5, 6),
490  bits(7, 8, 9), bits(9, 10, 11), bits(11, 12, 13), bits(13, 14, 15),
491  bits(16, 17, 18), bits(18, 19, 20), bits(20, 21, 22), bits(22, 23, 24), bits(24, 25, 26),
492  bits(28, 29, 30), bits(30, 31, 32), bits(32, 33, 34), bits(34, 35, 36),
493  bits(39, 40, 41), bits(41, 42, 43), bits(43, 44, 45),
494  bits(48, 49, 50), bits(50, 51, 52),
495  // downward pieces
496  bits(1, 2, 3), bits(3, 4, 5),
497  bits(8, 9, 10), bits (10, 11, 12), bits(12, 13, 14),
498  bits(17, 18, 19), bits(19, 20, 21), bits(21, 22, 23), bits(23, 24, 25),
499  bits(27, 28, 29), bits(29, 30, 31), bits(31, 32, 33), bits(33, 34, 35), bits(35, 36, 37),
500  bits(38, 39, 40), bits(40, 41, 42), bits(42, 43, 44), bits(44, 45, 46),
501  bits(47, 48, 49), bits(49, 50, 51), bits(51, 52, 53),
502  // one clockwise rotation
503  bits(5, 6, 14), bits(14, 15, 25), bits(25, 26, 37),
504  bits(3, 4, 12), bits(12, 13, 23), bits(23, 24, 35), bits(35, 36, 46),
505  bits(1, 2, 10), bits(10, 11, 21), bits(21, 22, 33), bits(33, 34, 44), bits(44, 45, 53),
506  bits(8, 9, 19), bits(19, 20, 31), bits(31, 32, 42), bits(42, 43, 51),
507  bits(17, 18, 29), bits(29, 30, 40), bits(40, 41, 49),
508  bits(27, 28, 38), bits(38, 39, 47),
509  // one clockwise rotation downward
510  bits(6, 14, 15), bits(15, 25, 26),
511  bits(4, 12, 13), bits(13, 23, 24), bits(24, 35, 36),
512  bits(2, 10, 11), bits(11, 21, 22), bits(22, 33, 34), bits(34, 44, 45),
513  bits(0, 8, 9), bits(9, 19, 20), bits(20, 31, 32), bits(32, 42, 43), bits(43, 51, 52),
514  bits(7, 17, 18), bits(18, 29, 30), bits(30, 40, 41), bits(41, 49, 50),
515  bits(16, 27, 28), bits(28, 38, 39), bits(39, 47, 48),
516  // two clockwise rotations
517  bits(27, 16, 17), bits(17, 7, 8), bits(8, 0, 1),
518  bits(38, 28, 29), bits(29, 18, 19), bits(19, 9, 10), bits(10, 2, 3),
519  bits(47, 39, 40), bits(40, 30, 31), bits(31, 20, 21), bits(21, 11, 12), bits(12, 4, 5),
520  bits(49, 41, 42), bits(42, 32, 33), bits(33, 22, 23), bits(23, 13, 14),
521  bits(51, 43, 44), bits(44, 34, 35), bits(35, 24, 25),
522  bits(53, 45, 46), bits(46, 36, 37),
523  // two clockwise rotations downward
524  bits(16, 17, 7), bits(7, 8, 0),
525  bits(28, 29, 18), bits(18, 19, 9), bits(9, 10, 2),
526  bits(39, 40, 30), bits(30, 31, 20), bits(20, 21, 11), bits(11, 12, 4),
527  bits(48, 49, 41), bits(41, 42, 32), bits(32, 33, 22), bits(22, 23, 13), bits(13, 14, 6),
528  bits(50, 51, 43), bits(43, 44, 34), bits(34, 35, 24), bits(24, 25, 15),
529  bits(52, 53, 45), bits(45, 46, 36), bits(36, 37, 26)
530  },
531  { // funny last piece
532  12*3*2, // kSnake count (72)
533  bits(0, 1, 2, 10, 11, 12),
534  bits(7, 8, 9, 19, 20, 21), bits(9, 10, 11, 21, 22, 23), bits(11, 12, 13, 23, 24, 25),
535  bits(16, 17, 18, 29, 30, 31), bits(18, 19, 20, 31, 32, 33), bits(20, 21, 22, 33, 34, 35), bits(22, 23, 24, 35, 36, 37),
536  bits(28, 29, 30, 40, 41, 42), bits(30, 31, 32, 42, 43, 44), bits(32, 33, 34, 44, 45, 46),
537  bits(41, 42, 43, 51, 52, 53),
538  // rotated 60 degrees
539  bits(5, 6, 13, 14, 23, 24),
540  bits(3, 4, 11, 12, 21, 22), bits(12, 13, 22, 23, 33, 34), bits(23, 24, 34, 35, 44, 45),
541  bits(1, 2, 9, 10, 19, 20), bits(10, 11, 20, 21, 31, 32), bits(21, 22, 32, 33, 42, 43), bits(33, 34, 43, 44, 51, 52),
542  bits(8, 9, 18, 19, 29, 30), bits(19, 20, 30, 31, 40, 41), bits(31, 32, 41, 42, 49, 50),
543  bits(29, 30, 39, 40, 47, 48),
544  // rotated 120 degress
545  bits(26, 34, 35, 36, 37, 44),
546  bits(15, 22, 23, 24, 25, 33), bits(24, 32, 33, 34, 35, 42), bits(34, 41, 42, 43, 44, 49),
547  bits(6, 11, 12, 13, 14, 21), bits(13, 20, 21, 22, 23, 31), bits(22, 30, 31, 32, 33, 40), bits(32, 39, 40, 41, 42, 47),
548  bits(4, 9, 10, 11, 12, 19), bits(11, 18, 19, 20, 21, 29), bits(20, 28, 29, 30, 31, 38),
549  bits(9, 16, 17, 18, 19, 27),
550  // flipped
551  bits(4, 5, 6, 10, 11, 12), bits(9, 10, 11, 17, 18, 19), bits(11, 12, 13, 19, 20, 21), bits(13, 14, 15, 21, 22, 23),
552  bits(18, 19, 20, 27, 28, 29), bits(20, 21, 22, 29, 30, 31), bits(22, 23, 24, 31, 32, 33), bits(24, 25, 26, 33, 34, 35),
553  bits(30, 31, 32, 38, 39, 40), bits(32, 33, 34, 40, 41, 42), bits(34, 35, 36, 42, 43, 44),
554  bits(41, 42, 43, 47, 48, 49),
555  // rotated 60 degrees - flipped
556  bits(13, 23, 24, 25, 26, 37),
557  bits(2, 10, 11, 12, 13, 23), bits(11, 21, 22, 23, 24, 35), bits(22, 33, 34, 35, 36, 46),
558  bits(0, 8, 9, 10, 11, 21), bits(9, 19, 20, 21, 22, 33), bits(20, 31, 32, 33, 34, 44), bits(32, 42, 43, 44, 45, 53),
559  bits(7, 17, 18, 19, 20, 31), bits(18, 29, 30, 31, 32, 42), bits(30, 40, 41, 42, 43, 51),
560  bits(16, 27, 28, 29, 30, 40),
561  // rotated 120 degress - flipped
562  bits(34, 35, 44, 45, 52, 53),
563  bits(13, 14, 23, 24, 34, 35), bits(22, 23, 33, 34, 43, 44), bits(32, 33, 42, 43, 50, 51),
564  bits(4, 5, 12, 13, 22, 23), bits(11, 12, 21, 22, 32, 33), bits(20, 21, 31, 32, 41, 42), bits(30, 31, 40, 41, 48, 49),
565  bits(2, 3, 10, 11, 20, 21), bits(9, 10, 19, 20, 30, 31), bits(18, 19, 29, 30, 39, 40),
566  bits(0, 1, 8, 9, 18, 19)
567  }
568 };
569 
571 {
572 // pieces = {0, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8};
573 // pieces = {kHexagon, kElbow, kLine, kMountains, kWrench, kTriangle, kHook, kTrapezoid, kTrapezoid, kSnake};
574 // pieces = {kHexagon, kElbow, kLine, kMountains, kWrench, kTriangle, kHook, kTrapezoid, kTrapezoid, kButterfly};
577 // pieces = {0, 1, 2, 3, 4, 5, 6, 7, 8, 8};
578 // pieces = {0, 1, 2, 3, 4, 5, 6, 7, 9};
579 // pieces = {9, 0, 1, 2, 3, 4, 5, 6, 7};
580  BuildFlipTable();
582 }
583 
584 void HexagonEnvironment::SetPieces(const std::vector<tPieceName> &pieces)
585 {
586  this->pieces.resize(0);
587  for (int x = 0; x < pieces.size(); x++)
588  this->pieces.push_back((int)pieces[x]);
589 }
590 
591 void HexagonEnvironment::SetFlippable(const std::array<tFlipType, numPieces> &flips)
592 {
593  flippable = flips;
594 }
595 
596 
598 {
599 
600 }
601 
603 {
604  uint64_t one = 1;
605  // int rotate30Map[12][14*6*2+1];
606  // for all pieces
607  for (int x = 0; x < numPieces; x++)
608  {
609  int total = locations[x][0];
610  if (total == 4) total = 19;
611 
612  // and all locations/rotations
613  for (int y = 1; y <= total; y++)
614  {
615  // rotate the piece from the given location
616  uint64_t loc = locations[x][y];
617  uint64_t rot_loc = 0;
618  for (int x = 0; x < 64; x++) // simple and dumb
619  {
620  if ((loc>>x)&1)
621  {
622  rot_loc |= (one<<rotateCWTable[x]);
623  }
624  }
625  // find match to rotation
626  bool success = false;
627  for (int z = 1; z <= total; z++)
628  {
629  if (locations[x][z] == rot_loc)
630  {
631  rotate30Map[x][y] = z;
632  success = true;
633  break;
634  }
635  }
636  assert(success == true);
637  }
638  }
639 }
640 
642 {
643  uint64_t one = 1;
644  // int flipMap[12][14*6*2+1];
645  // for all pieces
646  for (int x = 0; x < numPieces; x++)
647  {
648  int total = locations[x][0];
649  if (total == 4) total = 19;
650 
651  // and all locations/rotations
652  for (int y = 1; y <= total; y++)
653  {
654  // flip the piece from the given location
655  uint64_t loc = locations[x][y];
656  uint64_t flip_loc = 0;
657  for (int x = 0; x < 64; x++) // simple and dumb
658  {
659  if ((loc>>x)&1)
660  {
661  flip_loc |= (one<<flipTable[x]);
662  }
663  }
664  // find match to flip
665  bool success = false;
666  for (int z = 1; z <= total; z++)
667  {
668  if (locations[x][z] == flip_loc)
669  {
670  flipMap[x][y] = z;
671  success = true;
672  break;
673  }
674  }
675  assert(success == true);
676  }
677  }
678 }
679 
681 {
682  HexagonSearchState tmp;
683  for (int x = 0; x < s.cnt; x++)
684  {
685  ApplyAction(tmp, RotateCW(s.state[x]));
686  }
687  s = tmp;
688 }
689 
691 {
693  return a;
694 }
695 
697 {
698  HexagonSearchState tmp;
699  for (int x = 0; x < s.cnt; x++)
700  {
701  ApplyAction(tmp, Flip(s.state[x]));
702  }
703  s = tmp;
704 }
705 
707 {
708  a.location = flipMap[a.piece][a.location];
709  return a;
710 }
711 
712 void HexagonEnvironment::GetSuccessors(const HexagonSearchState &nodeID, std::vector<HexagonSearchState> &neighbors) const
713 {
714  static std::vector<HexagonAction> actions;
715  GetActions(nodeID, actions);
716  neighbors.resize(0);
717  for (auto i : actions)
718  {
719  HexagonSearchState next;
720  GetNextState(nodeID, i, next);
721  neighbors.push_back(next);
722  }
723 }
724 
725 void HexagonEnvironment::GetActions(const HexagonSearchState &nodeID, std::vector<HexagonAction> &actions) const
726 {
727  actions.clear();
728 // for (int x = 0; x < 126; x++)
729 // actions.push_back({0, x});
730 // for (int x = 0; x < 19; x++)
731 // actions.push_back({1, x});
732 // const int piece = 8;
733  unsigned int piece = pieces[nodeID.cnt];
734 
735 // for (unsigned int x = 1; x <= locations[piece][0]; x++)
736  switch (flippable[nodeID.cnt])
737  {
738  case kCanFlip:
739  for (unsigned int x = 1; x <= locations[piece][0]; x++)
740  {
741  if ((nodeID.bits&locations[piece][x]) == 0)
742  actions.push_back({piece, x});
743  }
744  break;
745  case kSide1:
746  for (unsigned int x = 1; x <= noFlipMoveCount[piece]; x++)
747  {
748  if ((nodeID.bits&locations[piece][x]) == 0)
749  actions.push_back({piece, x});
750  }
751  break;
752  case kSide2:
753  for (unsigned int x = noFlipMoveCount[piece]+1; x <= locations[piece][0]; x++)
754  {
755  if ((nodeID.bits&locations[piece][x]) == 0)
756  actions.push_back({piece, x});
757  }
758  break;
759  }
760 // for (unsigned int x = 1; x <= (flippable[nodeID.cnt]?locations[piece][0]:noFlipMoveCount[piece]); x++)
761 // {
762 // if ((nodeID.bits&locations[piece][x]) == 0)
763 // actions.push_back({piece, x});
764 // }
765 }
766 
767 //QUE: is this on purpose?
769 {
770  assert(false);
771  return {0, 0};
772 }
773 
775 {
776  s.state[s.cnt] = a;
777  s.cnt++;
778  s.bits ^= locations[a.piece][a.location];
779 }
780 
782 {
783  s.cnt--;
784  s.bits ^= locations[a.piece][a.location];
785 }
786 
787 
789 {
790  s2 = s1;
791  ApplyAction(s2, a);
792 }
793 
794 //QUE: how does this work?
796 {
797  return true;
798 }
799 
802 {
803  return node.bits == (((1ull)<<54)-1); // all 54 1s set
804 // return false;
805 }
806 
807 
809 {
810  return 0;
811 }
812 
814 {
815  return 0;
816 }
817 
820 {
821  // 1. Start with environment with only one piece type
823  std::vector<tPieceName> v;
824  v.push_back(p);
825  e.SetPieces(v);
826 
827  // 2. Get legal actions
828  std::vector<HexagonSearchState> succ;
830  e.GetSuccessors(s, succ);
831 
832  // 3. Place the piece on the board
833  s = succ[0];
834 
835  assert(s.cnt == 1); // should only be 1 piece on the board
836 
837  uint64_t state = s.bits;
838 
839  std::cout << pieceNames[p] << "\t";
840 // // count how many objects we have
841  int count = 0;
842  for (int t = 0; t < 54; t++)
843  {
844  if (((state>>t)&1) == 1)
845  {
846  count++;
847  }
848  }
849  std::cout << count << "\n";
850  // drawing doesn't have to be so fast! (compared to enumeration operations)
851  for (int t = 0; t < 54; t++)
852  {
853  if (((state>>t)&1) == 1)
854  {
855  int x, y;
856  Graphics::point p1, p2, p3;
857  IndexToXY(t, x, y);
858  GetCorners(x, y, p1, p2, p3);
859 
860  std::cout.precision(20);
861  std::cout << std::fixed;
862 
863  std::cout << " " << p1 << " " << p2 << " " << p3 << "\t";
864  }
865  }
866  std::cout << "\n";
867 }
868 
871 {
872  // 1. Start with environment with only one piece type
874 
875  std::cout << "Board\t";
876 // // count how many objects we have
877  int count = 54;
878  std::cout << count << "\n";
879  // drawing doesn't have to be so fast! (compared to enumeration operations)
880  for (int t = 0; t < 54; t++)
881  {
882  int x, y;
883  Graphics::point p1, p2, p3;
884  IndexToXY(t, x, y);
885  GetCorners(x, y, p1, p2, p3);
886 
887  std::cout.precision(20);
888  std::cout << std::fixed;
889 
890  std::cout << " " << p1 << " " << p2 << " " << p3 << "\t";
891  }
892  std::cout << "\n";
893 }
894 
896 {
897 
898 }
899 
902 {
903  hex.DrawSetup(display);
904 }
905 
907 {
908  display.FillSquare({0,0}, 1.0, Colors::white);
909  for (int t = 0; t < 54; t++)
910  {
911  int x, y;
912  Graphics::point p1, p2, p3;
913  IndexToXY(t, x, y);
914  GetCorners(x, y, p1, p2, p3);
915  display.FillTriangle(p1, p2, p3, Colors::lightgray);
916  }
917 
918  HexagonSearchState tmp;
919  for (int i = 0; i < s.cnt; i++)
920  {
921  tmp.Reset();
922  ApplyAction(tmp, s.state[i]);
923  uint64_t state = tmp.bits;
924 
925  // drawing doesn't have to be so fast! (compared to enumeration operations)
926  for (int t = 0; t < 54; t++)
927  {
928  if (((state>>t)&1) == 1)
929  {
930  int x, y;
931  Graphics::point p1, p2, p3;
932  IndexToXY(t, x, y);
933  GetCorners(x, y, p1, p2, p3);
934  display.FillTriangle(p1, p2, p3, rgbColor::hsl((float)i/12, (i%2)?0.75f:0.25f, 0.5f));
935  }
936  }
937  }
938 }
939 
940 void HexagonEnvironment::IndexToXY(int index, int &x, int &y) const
941 {
942  switch (index)
943  {
944  case 0: x = 2; y = 0; return;
945  case 1: x = 3; y = 0; return;
946  case 2: x = 4; y = 0; return;
947  case 3: x = 5; y = 0; return;
948  case 4: x = 6; y = 0; return;
949  case 5: x = 7; y = 0; return;
950  case 6: x = 8; y = 0; return;
951 
952  case 7: x = 1; y = 1; return;
953  case 8: x = 2; y = 1; return;
954  case 9: x = 3; y = 1; return;
955  case 10: x = 4; y = 1; return;
956  case 11: x = 5; y = 1; return;
957  case 12: x = 6; y = 1; return;
958  case 13: x = 7; y = 1; return;
959  case 14: x = 8; y = 1; return;
960  case 15: x = 9; y = 1; return;
961 
962  case 16: x = 0; y = 2; return;
963  case 17: x = 1; y = 2; return;
964  case 18: x = 2; y = 2; return;
965  case 19: x = 3; y = 2; return;
966  case 20: x = 4; y = 2; return;
967  case 21: x = 5; y = 2; return;
968  case 22: x = 6; y = 2; return;
969  case 23: x = 7; y = 2; return;
970  case 24: x = 8; y = 2; return;
971  case 25: x = 9; y = 2; return;
972  case 26: x = 10; y = 2; return;
973 
974  case 27: x = 0; y = 3; return;
975  case 28: x = 1; y = 3; return;
976  case 29: x = 2; y = 3; return;
977  case 30: x = 3; y = 3; return;
978  case 31: x = 4; y = 3; return;
979  case 32: x = 5; y = 3; return;
980  case 33: x = 6; y = 3; return;
981  case 34: x = 7; y = 3; return;
982  case 35: x = 8; y = 3; return;
983  case 36: x = 9; y = 3; return;
984  case 37: x = 10; y = 3; return;
985 
986  case 38: x = 1; y = 4; return;
987  case 39: x = 2; y = 4; return;
988  case 40: x = 3; y = 4; return;
989  case 41: x = 4; y = 4; return;
990  case 42: x = 5; y = 4; return;
991  case 43: x = 6; y = 4; return;
992  case 44: x = 7; y = 4; return;
993  case 45: x = 8; y = 4; return;
994  case 46: x = 9; y = 4; return;
995 
996  case 47: x = 2; y = 5; return;
997  case 48: x = 3; y = 5; return;
998  case 49: x = 4; y = 5; return;
999  case 50: x = 5; y = 5; return;
1000  case 51: x = 6; y = 5; return;
1001  case 52: x = 7; y = 5; return;
1002  case 53: x = 8; y = 5; return;
1003  }
1004  x=-1;y=-1;
1005 }
1006 
1007 
1009 {
1010  return hex.GetCorners(x, y, p1, p2, p3);
1011 }
1012 
1013 bool HexagonEnvironment::GetBorder(int x, int y, int xoff, int yoff, Graphics::point &p1, Graphics::point &p2) const
1014 {
1015  return hex.GetBorder(x, y, xoff, yoff, p1, p2);
1016 }
1017 
1018 bool HexagonEnvironment::Valid(int x, int y) const
1019 {
1020  return hex.Valid(x, y);
1021 }
1022 
1023 //std::vector<rgbColor> pieceColors;
1024 
1025 #pragma mark -
1026 #pragma mark Hexagon Display Code
1027 #pragma mark -
1028 
1029 
1031 {
1032 
1033 }
1035 {
1036 
1037 }
1038 
1039 void Hexagon::LoadSolution(const char *file, HexagonState &s)
1040 {
1041  Load(file, s, true);
1042 }
1043 
1044 void Hexagon::LoadPuzzle(const char *file, HexagonState &s)
1045 {
1046  Load(file, s, false);
1047 }
1048 
1049 void Hexagon::Load(const char *file, HexagonState &s, bool solution)
1050 {
1051  s.state.FillMax();
1052  this->solution.state.FillMax();
1053  FILE *f = fopen(file, "r");
1054  if (f == 0)
1055  {
1056  printf("Error opening file for read\n");
1057  return;
1058  }
1059  int h, w;
1060  fscanf(f, "type triangle\n");
1061  int cnt = fscanf(f, "height %d\nwidth %d\nmap\n", &h, &w);
1062  if (cnt != 2)
1063  {
1064  printf("Error reading height/width from file\n");
1065  return;
1066  }
1067  if (h != 6 || w != 11)
1068  {
1069  printf("Invalid height/width from file. Requires 6/11.\n");
1070  return;
1071  }
1072  // read constraints (if any)
1073  char buffer[255];
1074  fgets(buffer, 255, f);
1075  if (strncmp("Constraint:", buffer, 11) != 0)
1076  {
1077  printf("Error: expected 'Constraint:'\n");
1078  return;
1079  }
1080  char *tmp;
1081 
1082  // must touch diagonally
1083  tmp = strcasestr(buffer, "Diag");
1084  if (tmp != NULL)
1085  {
1086  diagPieces.resize(3);
1087  sscanf(&tmp[5], "%d %d %d", &diagPieces[0], &diagPieces[1], &diagPieces[2]);
1088  }
1089 
1090  tmp = strcasestr(buffer, "NoFlip");
1091 
1092  if (tmp != NULL)
1093  {
1094  noFlipPieces.resize(3);
1095  sscanf(&tmp[7], "%d %d %d", &noFlipPieces[0], &noFlipPieces[1], &noFlipPieces[2]);
1096  }
1097 
1098  tmp = strcasestr(buffer, "NotTouch");
1099 
1100  if (tmp != NULL)
1101  {
1102  notTouchPieces.resize(3);
1103  sscanf(&tmp[9], "%d %d %d", &notTouchPieces[0], &notTouchPieces[1], &notTouchPieces[2]);
1104  }
1105 
1106  tmp = strcasestr(buffer, " Touch"); // Add space -- otherwise matches NotTouch
1107 
1108  if (tmp != NULL)
1109  {
1110  touchPieces.resize(3);
1111  sscanf(&tmp[7], "%d %d %d", &touchPieces[0], &touchPieces[1], &touchPieces[2]);
1112  }
1113 
1114  for (int x = 0; x < 66; x++)
1115  {
1116  char c = fgetc(f);
1117  while (isspace(c))
1118  c = fgetc(f);
1119  if (c == 'x')
1120  {
1121  s.state.Set(x, -1);
1122  this->solution.state.Set(x, -1);
1123  }
1124  else if (isalpha(c))
1125  {
1126  this->solution.state.Set(x, tolower(c)-'a');
1127  if (solution)
1128  {
1129  s.state.Set(x, tolower(c)-'a');
1130  }
1131  else {
1132  s.state.Set(x, 11);
1133  }
1134  }
1135  else if (isdigit(c))
1136  {
1137  this->solution.state.Set(x, tolower(c)-'0');
1138  s.state.Set(x, tolower(c)-'0');
1139  }
1140  }
1141  fclose(f);
1142 // this->solution = s;
1143 
1144  // Get all of the colors
1145  for (int y = 0; y < 6; y++)
1146  {
1147  for (int x = 0; x < 11; x++)
1148  {
1149  if (!Valid(x, y))
1150  continue;
1151  int piece = this->solution.state.Get(y*11+x);
1152  if (piece > pieceColors.size())
1153  pieceColors.resize(piece+1);
1154  pieceColors[piece] = rgbColor::hsl((piece)/11.0, (piece%2)?1.0:0.5, 0.5);
1155  }
1156  }
1157  for (auto i : diagPieces)
1158  pieceColors[i] = rgbColor::hsl((diagPieces[0])/11.0, (diagPieces[0]%2)?1.0:0.5, 0.5);
1159  for (auto i : noFlipPieces)
1160  pieceColors[i] = rgbColor::hsl((noFlipPieces[0])/11.0, (noFlipPieces[0]%2)?1.0:0.5, 0.5);
1161  for (auto i : touchPieces)
1162  pieceColors[i] = rgbColor::hsl((touchPieces[0])/11.0, (touchPieces[0]%2)?1.0:0.5, 0.5);
1163  for (auto i : notTouchPieces)
1164  pieceColors[i] = rgbColor::hsl((notTouchPieces[0])/11.0, (notTouchPieces[0]%2)?1.0:0.5, 0.5);
1165 }
1166 
1167 void Hexagon::GetSuccessors(const HexagonState &nodeID, std::vector<HexagonState> &neighbors) const
1168 {
1169 
1170 }
1171 
1172 void Hexagon::GetActions(const HexagonState &nodeID, std::vector<HexagonAction> &actions) const
1173 {
1174 
1175 }
1176 
1178 {
1179  HexagonAction a;
1180  return a;
1181 }
1182 
1184 {
1185 
1186 }
1187 
1189 {
1190 
1191 }
1192 
1194 {
1195  return true;
1196 }
1197 
1198 
1200 {
1201  return 0;
1202 }
1203 
1205 {
1206  return 0;
1207 }
1208 
1211 {
1212  return true;
1213 }
1214 
1216 {
1217 
1218 }
1219 
1220 
1221 bool Hexagon::GetBorder(int x, int y, int xoff, int yoff, Graphics::point &p1, Graphics::point &p2) const
1222 {
1223  const float triangleWidth = 2.0/7;
1224  const float triangleHeight = triangleWidth/1.154700538379252; // 2/sqrt(3)
1225  const float xMargin = triangleWidth/2;
1226  const float yMargin = (2.0-triangleHeight*6)/2;
1227 // const float triangleHeight = 2.0/7;
1228 // const float triangleWidth = 1.154700538379252*triangleHeight; // 2/sqrt(3)
1229 // const float margin = triangleHeight/2;
1230 
1231  if (0==(x+y)%2) // points up
1232  {
1233  if (yoff < 0)
1234  {
1235  return false;
1236  }
1237  else if (xoff > 0)
1238  {
1239  p1 = {
1240  -1+xMargin+(x+2)*triangleWidth/2,
1241  -1+yMargin+(y+1)*triangleHeight
1242  };
1243  p2 = {
1244  -1+xMargin+(x+1)*triangleWidth/2,
1245  -1+yMargin+(y)*triangleHeight
1246  };
1247  }
1248  else if (xoff < 0)
1249  {
1250  p1 = {
1251  -1+xMargin+x*triangleWidth/2,
1252  -1+yMargin+(y+1)*triangleHeight
1253  };
1254  p2 = {
1255  -1+xMargin+(x+1)*triangleWidth/2,
1256  -1+yMargin+(y)*triangleHeight
1257  };
1258  }
1259  else if (yoff > 0)
1260  {
1261  p1 = {
1262  -1+xMargin+x*triangleWidth/2,
1263  -1+yMargin+(y+1)*triangleHeight
1264  };
1265  p2 = {
1266  -1+xMargin+(x+2)*triangleWidth/2,
1267  -1+yMargin+(y+1)*triangleHeight
1268  };
1269  }
1270  return true;
1271  }
1272  else { // points down
1273  if (yoff > 0)
1274  {
1275  return false;
1276  }
1277  else if (xoff > 0)
1278  {
1279  // upper right
1280  p1 = {
1281  -1+xMargin+(x+2)*triangleWidth/2,
1282  -1+yMargin+(y)*triangleHeight
1283  };
1284  // bottom tip
1285  p2 = {
1286  -1+xMargin+(x+1)*triangleWidth/2,
1287  -1+yMargin+(y+1)*triangleHeight
1288  };
1289  }
1290  else if (xoff < 0)
1291  {
1292  // upper left
1293  p1 = {
1294  -1+xMargin+(x)*triangleWidth/2,
1295  -1+yMargin+(y)*triangleHeight
1296  };
1297  // bottom tip
1298  p2 = {
1299  -1+xMargin+(x+1)*triangleWidth/2,
1300  -1+yMargin+(y+1)*triangleHeight
1301  };
1302  }
1303  else if (yoff < 0)
1304  {
1305  // upper right
1306  p1 = {
1307  -1+xMargin+(x+2)*triangleWidth/2,
1308  -1+yMargin+(y)*triangleHeight
1309  };
1310  // upper left
1311  p2 = {
1312  -1+xMargin+(x)*triangleWidth/2,
1313  -1+yMargin+(y)*triangleHeight
1314  };
1315  }
1316  return true;
1317 // // upper right
1318 // p1 = {
1319 // -1+margin+(x+2)*triangleHeight/2,
1320 // -1+margin+(y)*triangleHeight
1321 // };
1322 // // upper left
1323 // p2 = {
1324 // -1+margin+(x)*triangleHeight/2,
1325 // -1+margin+(y)*triangleHeight
1326 // };
1327 // // bottom tip
1328 // p3 = {
1329 // -1+margin+(x+1)*triangleHeight/2,
1330 // -1+margin+(y+1)*triangleHeight
1331 // };
1332 // return false;
1333  }
1334 }
1335 
1337 {
1338  const float triangleWidth = 2.0/7;
1339  const float triangleHeight = triangleWidth/1.154700538379252; // 2/sqrt(3)
1340  const float xMargin = triangleWidth/2;
1341  const float yMargin = (2.0-triangleHeight*6)/2;
1342 
1343  if (0==(x+y)%2) // points up
1344  {
1345  p1 = {
1346  -1+xMargin+x*triangleWidth/2,
1347  -1+yMargin+(y+1)*triangleHeight
1348  };
1349  p2 = {
1350  -1+xMargin+(x+2)*triangleWidth/2,
1351  -1+yMargin+(y+1)*triangleHeight
1352  };
1353  p3 = {
1354  -1+xMargin+(x+1)*triangleWidth/2,
1355  -1+yMargin+(y)*triangleHeight
1356  };
1357  }
1358  else { // points down
1359  p1 = {
1360  -1+xMargin+(x+2)*triangleWidth/2,
1361  -1+yMargin+(y)*triangleHeight
1362  };
1363  p2 = {
1364  -1+xMargin+(x)*triangleWidth/2,
1365  -1+yMargin+(y)*triangleHeight
1366  };
1367  p3 = {
1368  -1+xMargin+(x+1)*triangleWidth/2,
1369  -1+yMargin+(y+1)*triangleHeight
1370  };
1371  }
1372 }
1373 
1374 bool Hexagon::Valid(int x, int y) const
1375 {
1376  static bool valid[6][11] =
1377  {
1378  {false, false, true, true, true, true, true, true, true, false, false},
1379  {false, true, true, true, true, true, true, true, true, true, false},
1380  {true, true, true, true, true, true, true, true, true, true, true},
1381  {true, true, true, true, true, true, true, true, true, true, true},
1382  {false, true, true, true, true, true, true, true, true, true, false},
1383  {false, false, true, true, true, true, true, true, true, false, false}
1384  };
1385  return valid[y][x];
1386 }
1387 
1388 void Hexagon::Draw(Graphics::Display &display) const
1389 {
1390  // Draw board
1391  display.FillRect(Graphics::rect({0,0}, 1.0), Colors::white);
1392  for (int y = 0; y < 6; y++)
1393  {
1394  for (int x = 0; x < 11; x++)
1395  {
1396  if (!Valid(x, y))
1397  //if (!valid[y][x])
1398  continue;
1399  Graphics::point p1, p2, p3;
1400  GetCorners(x, y, p1, p2, p3);
1401  display.FillTriangle(p1, p2, p3, Colors::lightgray);
1402  display.FrameTriangle(p1, p2, p3, 0.01f, Colors::darkgray);
1403  }
1404  }
1405  float xLoc = -1, yLoc = -1;
1406  float dim = 0.1;
1407 
1408  if (noFlipPieces.size() != 0)
1409  {
1410  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[noFlipPieces[0]]);
1411  display.DrawText("Cannot Flip", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1412  xLoc = 0;
1413  }
1414  if (diagPieces.size() != 0)
1415  {
1416  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[diagPieces[0]]);
1417  display.DrawText("Must Touch Diagonally", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1418  xLoc = 0;
1419  }
1420  if (notTouchPieces.size() != 0)
1421  {
1422  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[notTouchPieces[0]]);
1423  display.DrawText("Cannot Touch", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1424  xLoc = 0;
1425  }
1426  if (touchPieces.size() != 0)
1427  {
1428  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[touchPieces[0]]);
1429  display.DrawText("Must Touch Edges", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1430  xLoc = 0;
1431  }
1432 }
1433 
1435 {
1436  // Draw board
1437  display.FillRect(Graphics::rect({0,0}, 1.0), Colors::white);
1438 
1439  // Horribly inefficient for now; just looking for correctness
1440  // Could all be pre-computed and cached
1441  for (int piece = 0; piece < 10; piece++)
1442  {
1443  bool found = false;
1444  Graphics::rect bounds;
1445  // get bounding box for piece
1446  for (int y = 0; y < 6; y++)
1447  {
1448  for (int x = 0; x < 11; x++)
1449  {
1450  if (!Valid(x, y))
1451  continue;
1452  int p = solution.state.Get(y*11+x);
1453  if (piece == p)
1454  {
1455  Graphics::point p1, p2, p3;
1456  GetCorners(x, y, p1, p2, p3);
1457 
1458  if (!found)
1459  {
1460  found = true;
1461  bounds = Graphics::rect(p1, p2);
1462  }
1463  else {
1464  bounds |= Graphics::rect(p1, p2);
1465  }
1466  bounds |= Graphics::rect(p2, p1);
1467  bounds |= Graphics::rect(p2, p3);
1468  bounds |= Graphics::rect(p3, p2);
1469  bounds |= Graphics::rect(p1, p3);
1470  bounds |= Graphics::rect(p3, p1);
1471  }
1472  }
1473  }
1474 
1475  float newWidth = 0.45f;
1476  float newHeight = 0.45f;
1477  float border = 0.01;
1478  float scale = 0.45f/std::max(bounds.right-bounds.left, bounds.bottom-bounds.top);
1479  float baseX = -0.9f+(piece%4)*(newWidth+border);
1480  float baseY = -0.7f+(piece>>2)*(newHeight+border);
1481 // std::cout << "Piece " << piece << " rect: " << bounds << "\n";
1482  // draw piece scaled
1483  for (int y = 0; y < 6; y++)
1484  {
1485  for (int x = 0; x < 11; x++)
1486  {
1487  if (!Valid(x, y))
1488  continue;
1489  int p = solution.state.Get(y*11+x);
1490  if (piece == p)
1491  {
1492  Graphics::point p1, p2, p3;
1493  GetCorners(x, y, p1, p2, p3);
1494  p1.x = baseX+(p1.x-bounds.left)*scale;
1495  p1.y = baseY+(p1.y-bounds.top)*scale;
1496  p2.x = baseX+(p2.x-bounds.left)*scale;
1497  p2.y = baseY+(p2.y-bounds.top)*scale;
1498  p3.x = baseX+(p3.x-bounds.left)*scale;
1499  p3.y = baseY+(p3.y-bounds.top)*scale;
1500  display.FillTriangle(p1, p2, p3, pieceColors[piece]);
1501  }
1502  }
1503  }
1504  }
1505 
1506  // Draw constraints at top
1507  {
1508  float xLoc = -1, yLoc = -1;
1509  float dim = 0.1;
1510 
1511  if (noFlipPieces.size() != 0)
1512  {
1513  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[noFlipPieces[0]]);
1514  display.DrawText("Cannot Flip", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1515  xLoc = 0;
1516  }
1517  if (diagPieces.size() != 0)
1518  {
1519  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[diagPieces[0]]);
1520  display.DrawText("Must Touch Diagonally", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1521  xLoc = 0;
1522  }
1523  if (notTouchPieces.size() != 0)
1524  {
1525  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[notTouchPieces[0]]);
1526  display.DrawText("Cannot Touch", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1527  xLoc = 0;
1528  }
1529  if (touchPieces.size() != 0)
1530  {
1531  display.FillRect({xLoc, yLoc, xLoc+dim, yLoc+dim}, pieceColors[touchPieces[0]]);
1532  display.DrawText("Must Touch Edges", {xLoc+1.2f*dim, yLoc+dim/2.0f}, Colors::black, dim*0.8f, Graphics::textAlignLeft, Graphics::textBaselineMiddle);
1533  xLoc = 0;
1534  }
1535  }
1536 }
1537 
1538 void Hexagon::Draw(Graphics::Display &display, const HexagonState &s) const
1539 {
1540  // Draw objects
1541  for (int y = 0; y < 6; y++)
1542  {
1543  for (int x = 0; x < 11; x++)
1544  {
1545  if (!Valid(x, y))
1546  continue;
1547  Graphics::point p1, p2, p3;
1548  GetCorners(x, y, p1, p2, p3);
1549  int piece = s.state.Get(y*11+x);
1550  if (piece < 10)
1551  {
1552  display.FillTriangle(p1, p2, p3, pieceColors[piece]);
1553  }
1554  }
1555  }
1556  // Draw Borders
1557  for (int y = 0; y < 6; y++)
1558  {
1559  for (int x = 0; x < 11; x++)
1560  {
1561  if (!Valid(x, y))
1562  //if (!valid[y][x])
1563  continue;
1564  Graphics::point p1, p2, p3;
1565  GetCorners(x, y, p1, p2, p3);
1566  int piece = s.state.Get(y*11+x);
1567 
1568  if ((x == 10) || (piece != s.state.Get(y*11+x+1)))
1569  {
1570  if (GetBorder(x, y, 1, 0, p1, p2))
1571  {
1572  display.DrawLine(p1, p2, 0.02, Colors::black);
1573  }
1574  }
1575  if ((x == 0) || (x > 0 && piece != s.state.Get(y*11+x-1)))
1576  {
1577  if (GetBorder(x, y, -1, 0, p1, p2))
1578  {
1579  display.DrawLine(p1, p2, 0.02, Colors::black);
1580  }
1581  }
1582  if ((y == 5) || (y < 5 && piece != s.state.Get((y+1)*11+x)))
1583  {
1584  if (GetBorder(x, y, 0, 1, p1, p2))
1585  {
1586  display.DrawLine(p1, p2, 0.02, Colors::black);
1587  }
1588  }
1589  if ((y == 0) || (y > 0 && piece != s.state.Get((y-1)*11+x)))
1590  {
1591  if (GetBorder(x, y, 0, -1, p1, p2))
1592  {
1593  display.DrawLine(p1, p2, 0.02, Colors::black);
1594  }
1595  }
1596  }
1597  }
1598 }
1599 
Graphics::Display::DrawLine
void DrawLine(point start, point end, float lineWidth, rgbColor c)
Definition: Graphics.cpp:184
Hexagon::Draw
void Draw(Graphics::Display &display) const
Definition: Hexagon.cpp:1388
Hexagon::RotateCW
void RotateCW(HexagonState &s) const
Definition: Hexagon.cpp:1215
Graphics::point
Definition: Graphics.h:32
HexagonEnvironment::GetNextState
void GetNextState(const HexagonSearchState &, HexagonAction, HexagonSearchState &) const
Definition: Hexagon.cpp:788
Graphics::point::y
float y
Definition: Graphics.h:36
rgbColor::hsl
static rgbColor hsl(float h, float s, float l)
Definition: Colors.h:29
HexagonState::state
NBitArray< 4 > state
Definition: Hexagon.h:67
HexagonEnvironment::GenerateBoardBorder
void GenerateBoardBorder()
Prints out the outer coorsinates of the board.
Definition: Hexagon.cpp:870
Hexagon::~Hexagon
~Hexagon()
Definition: Hexagon.cpp:1034
kElbow
@ kElbow
Definition: Hexagon.h:22
HexagonEnvironment::pieces
std::vector< int > pieces
Definition: Hexagon.h:227
HexagonEnvironment::InvertAction
bool InvertAction(HexagonAction &a) const
Definition: Hexagon.cpp:795
HexagonEnvironment::DrawSetup
void DrawSetup(Graphics::Display &display) const
Draws available pieces and constraints.
Definition: Hexagon.cpp:901
Graphics::Display::FillSquare
void FillSquare(point p, float radius, rgbColor c)
Definition: Graphics.cpp:92
Hexagon::GetSuccessors
void GetSuccessors(const HexagonState &nodeID, std::vector< HexagonState > &neighbors) const
Definition: Hexagon.cpp:1167
Hexagon::touchPieces
std::vector< int > touchPieces
Definition: Hexagon.h:129
kCanFlip
@ kCanFlip
Definition: Hexagon.h:33
tPieceName
tPieceName
Definition: Hexagon.h:19
numPieces
const int numPieces
Definition: Hexagon.h:38
Graphics::Display::FillTriangle
void FillTriangle(point p1, point p2, point p3, rgbColor c)
Definition: Graphics.cpp:146
Hexagon::GetBorder
bool GetBorder(int x, int y, int xoff, int yoff, Graphics::point &p1, Graphics::point &p2) const
Definition: Hexagon.cpp:1221
HexagonEnvironment::hex
Hexagon hex
Definition: Hexagon.h:229
HexagonEnvironment::BuildFlipTable
void BuildFlipTable()
Definition: Hexagon.cpp:641
HexagonEnvironment::Valid
bool Valid(int x, int y) const
Definition: Hexagon.cpp:1018
d
mcData d[]
Definition: MotionCaptureMovement.cpp:21
NBitArray::FillMax
void FillMax()
Definition: NBitArray.h:123
HexagonState
Definition: Hexagon.h:62
Graphics::rect
Definition: Graphics.h:94
NBitArray::Set
void Set(uint64_t index, uint64_t val)
Definition: NBitArray.h:224
HexagonEnvironment::GetAction
HexagonAction GetAction(const HexagonSearchState &s1, const HexagonSearchState &s2) const
Definition: Hexagon.cpp:768
HexagonEnvironment::HexagonEnvironment
HexagonEnvironment()
Definition: Hexagon.cpp:570
HexagonAction::piece
unsigned int piece
Definition: Hexagon.h:55
kMountains
@ kMountains
Definition: Hexagon.h:24
Hexagon::ApplyAction
void ApplyAction(HexagonState &s, HexagonAction a) const
Definition: Hexagon.cpp:1183
pieces
const int pieces
Definition: RubiksCube7Edges.h:17
HexagonAction
Definition: Hexagon.h:53
HexagonEnvironment::GetBorder
bool GetBorder(int x, int y, int xoff, int yoff, Graphics::point &p1, Graphics::point &p2) const
Definition: Hexagon.cpp:1013
Graphics::textBaselineMiddle
@ textBaselineMiddle
Definition: Graphics.h:27
HexagonEnvironment
Definition: Hexagon.h:175
HexagonSearchState
Definition: Hexagon.h:132
HexagonEnvironment::GetCorners
void GetCorners(int x, int y, Graphics::point &p1, Graphics::point &p2, Graphics::point &p3) const
Definition: Hexagon.cpp:1008
flipTable
const int flipTable[54]
Definition: Hexagon.cpp:30
HexagonEnvironment::GetStateHash
uint64_t GetStateHash(const HexagonSearchState &node) const
Definition: Hexagon.cpp:808
Hexagon::GetActionHash
uint64_t GetActionHash(HexagonAction act) const
Definition: Hexagon.cpp:1204
HexagonEnvironment::GoalTest
bool GoalTest(const HexagonSearchState &node) const
Goal Test if the goal is stored.
Definition: Hexagon.cpp:801
Hexagon::GetCorners
void GetCorners(int x, int y, Graphics::point &p1, Graphics::point &p2, Graphics::point &p3) const
Definition: Hexagon.cpp:1336
Graphics::rect::top
float top
Definition: Graphics.h:100
HexagonEnvironment::Flip
void Flip(HexagonSearchState &s) const
Definition: Hexagon.cpp:696
Hexagon::Hexagon
Hexagon()
Definition: Hexagon.cpp:1030
loc
Definition: MapGenerators.cpp:296
kTrapezoid
@ kTrapezoid
Definition: Hexagon.h:28
Colors::black
const rgbColor black
Definition: Colors.h:119
NBitArray::Get
uint64_t Get(uint64_t index) const
Definition: NBitArray.h:209
kSide1
@ kSide1
Definition: Hexagon.h:34
HexagonSearchState::Reset
void Reset()
Definition: Hexagon.h:139
Graphics::Display
Definition: Graphics.h:146
HexagonEnvironment::RotateCW
void RotateCW(HexagonSearchState &s) const
Definition: Hexagon.cpp:680
Colors::darkgray
const rgbColor darkgray
Definition: Colors.h:123
HexagonEnvironment::GetActions
void GetActions(const HexagonSearchState &nodeID, std::vector< HexagonAction > &actions) const
Definition: Hexagon.cpp:725
HexagonEnvironment::SetFlippable
void SetFlippable(const std::array< tFlipType, numPieces > &flips)
Definition: Hexagon.cpp:591
rotateCWTable
const int rotateCWTable[54]
Definition: Hexagon.cpp:27
Graphics::rect::right
float right
Definition: Graphics.h:100
kWrench
@ kWrench
Definition: Hexagon.h:25
Hexagon::InvertAction
bool InvertAction(HexagonAction &a) const
Definition: Hexagon.cpp:1193
locations
const uint64_t locations[numPieces][14 *6 *2+1]
Definition: Hexagon.cpp:57
kSnake
@ kSnake
Definition: Hexagon.h:29
HexagonEnvironment::BuildRotationTable
void BuildRotationTable()
Definition: Hexagon.cpp:602
max
#define max(a, b)
Definition: MinimalSectorAbstraction.cpp:40
HexagonEnvironment::Draw
void Draw(Graphics::Display &display) const
Definition: Hexagon.cpp:895
HexagonSearchState::bits
uint64_t bits
Definition: Hexagon.h:141
Hexagon::DrawSetup
void DrawSetup(Graphics::Display &display) const
Draws available pieces and constraints.
Definition: Hexagon.cpp:1434
Hexagon::pieceColors
std::vector< rgbColor > pieceColors
Definition: Hexagon.h:125
HexagonEnvironment::SetPieces
void SetPieces(const std::vector< tPieceName > &pieces)
Definition: Hexagon.cpp:584
HexagonEnvironment::ApplyAction
void ApplyAction(HexagonSearchState &s, HexagonAction a) const
Definition: Hexagon.cpp:774
Hexagon::LoadSolution
void LoadSolution(const char *, HexagonState &s)
Definition: Hexagon.cpp:1039
HexagonAction::location
unsigned int location
Definition: Hexagon.h:56
Hexagon::Load
void Load(const char *, HexagonState &s, bool solution)
Definition: Hexagon.cpp:1049
kHexagon
@ kHexagon
Definition: Hexagon.h:20
kSide2
@ kSide2
Definition: Hexagon.h:35
Hexagon::GoalTest
bool GoalTest(const HexagonState &node) const
Goal Test if the goal is stored.
Definition: Hexagon.cpp:1210
HexagonSearchState::state
std::array< HexagonAction, 12 > state
Definition: Hexagon.h:143
Graphics::point::x
float x
Definition: Graphics.h:36
HexagonEnvironment::flipMap
int flipMap[numPieces][14 *6 *2+1]
Definition: Hexagon.h:231
Hexagon::noFlipPieces
std::vector< int > noFlipPieces
Definition: Hexagon.h:127
HexagonEnvironment::~HexagonEnvironment
~HexagonEnvironment()
Definition: Hexagon.cpp:597
Hexagon.h
HexagonEnvironment::UndoAction
void UndoAction(HexagonSearchState &s, HexagonAction a) const
Definition: Hexagon.cpp:781
Graphics::Display::FrameTriangle
void FrameTriangle(point p1, point p2, point p3, float lineWidth, rgbColor c)
Definition: Graphics.cpp:155
HexagonEnvironment::IndexToXY
void IndexToXY(int index, int &x, int &y) const
Definition: Hexagon.cpp:940
Graphics::textAlignLeft
@ textAlignLeft
Definition: Graphics.h:21
Colors::white
const rgbColor white
Definition: Colors.h:120
Graphics::rect::left
float left
Definition: Graphics.h:100
pieceNames
const std::string pieceNames[numPieces]
Definition: Hexagon.h:39
Hexagon::Valid
bool Valid(int x, int y) const
Definition: Hexagon.cpp:1374
HexagonEnvironment::flippable
std::array< tFlipType, numPieces > flippable
Definition: Hexagon.h:228
Hexagon::GetAction
HexagonAction GetAction(const HexagonState &s1, const HexagonState &s2) const
Definition: Hexagon.cpp:1177
Hexagon::GetNextState
void GetNextState(const HexagonState &, HexagonAction, HexagonState &) const
Definition: Hexagon.cpp:1188
Hexagon::diagPieces
std::vector< int > diagPieces
Definition: Hexagon.h:126
HexagonEnvironment::GetSuccessors
void GetSuccessors(const HexagonSearchState &nodeID, std::vector< HexagonSearchState > &neighbors) const
Definition: Hexagon.cpp:712
Graphics::Display::DrawText
void DrawText(const char *text, point location, rgbColor c, float height, const char *typeface=0)
Definition: Graphics.cpp:221
Colors::lightgray
const rgbColor lightgray
Definition: Colors.h:125
Hexagon::GetStateHash
uint64_t GetStateHash(const HexagonState &node) const
Definition: Hexagon.cpp:1199
HexagonSearchState::cnt
int cnt
Definition: Hexagon.h:142
Graphics::rect::bottom
float bottom
Definition: Graphics.h:100
Graphics::Display::FillRect
void FillRect(rect r, rgbColor c)
Definition: Graphics.cpp:101
HexagonEnvironment::GetActionHash
uint64_t GetActionHash(HexagonAction act) const
Definition: Hexagon.cpp:813
Hexagon::LoadPuzzle
void LoadPuzzle(const char *, HexagonState &s)
Definition: Hexagon.cpp:1044
Hexagon::solution
HexagonState solution
Definition: Hexagon.h:124
Hexagon::notTouchPieces
std::vector< int > notTouchPieces
Definition: Hexagon.h:128
kTriangle
@ kTriangle
Definition: Hexagon.h:26
kButterfly
@ kButterfly
Definition: Hexagon.h:21
Hexagon::GetActions
void GetActions(const HexagonState &nodeID, std::vector< HexagonAction > &actions) const
Definition: Hexagon.cpp:1172
HexagonEnvironment::rotate30Map
int rotate30Map[numPieces][14 *6 *2+1]
Definition: Hexagon.h:230
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
kHook
@ kHook
Definition: Hexagon.h:27
noFlipMoveCount
const int noFlipMoveCount[numPieces]
Definition: Hexagon.cpp:33
HexagonEnvironment::GeneratePieceCoordinates
void GeneratePieceCoordinates(tPieceName p)
Prints out the triangles used for this piece in HOG2 coordinates.
Definition: Hexagon.cpp:819
bits
constexpr uint64_t bits(uint64_t a, uint64_t b, uint64_t c)
Definition: Hexagon.cpp:16