21 #include <unordered_map>
29 for (
unsigned int x = 0; x < N; x++)
34 for (
unsigned int x = 0; x < N; x++)
37 size_t size()
const {
return N; }
52 for (
unsigned int x = 0; x < N; x++)
53 out <<
loc.puzzle[x] <<
" ";
62 for (
unsigned int x = 0; x < N; x++)
76 template <
int N,
int k>
105 for (
int x = 0; x < N; x++)
107 for (
int y = 0; y < N; y++)
127 virtual const std::string
GetName();
138 for (
int x = 0; x <
hDist.size(); x++)
141 for (
int y = 0; y <= 12; y++)
144 for (
int x = 0; x <
hDist.size(); x++)
146 if (y >=
hDist[x].size())
149 printf(
"%d\t",
hDist[x][y]);
168 std::vector<std::vector<int> >
hDist;
181 template <
int N,
int k>
188 for (
int x = 0; x < N; x++)
192 template <
int N,
int k>
198 template <
int N,
int k>
200 std::stringstream name;
201 name <<
"TopSpin(" << N <<
", " << k <<
")";
206 template <
int N,
int k>
209 if (pattern.size() == 0)
213 for (
int x = 0; x < N; x++)
214 this->pattern[x] =
false;
215 for (
int i : pattern)
216 this->pattern[i] =
true;
219 template <
int N,
int k>
223 for (
int x = 0; x < k; x++)
225 if (pattern[s.
puzzle[(a+x)%N]])
232 template <
int N,
int k>
236 movePrune.resize(N*N*N);
239 RecursiveMovePruning(3, start);
242 pruningCostMap.clear();
245 template <
int N,
int k>
250 if (pruningMap.find(this->GetStateHash(state)) != pruningMap.end())
252 int last = history.size()-1;
256 movePrune[history[last]*N*N+history[last-1]*N+history[last-2]] =
true;
259 pruningMap[this->GetStateHash(state)] =
true;
263 for (
int x = 0; x < N; x++)
265 ApplyAction(state, x);
266 history.push_back(x);
267 RecursiveMovePruning(depth-1, state);
269 UndoAction(state, x);
273 template <
int N,
int k>
278 template <
int N,
int k>
281 for (
int x = 0; x < N; x++)
287 template <
int N,
int k>
292 for (
unsigned int i = 0; i < N; i++)
296 neighbors.push_back(s);
300 template <
int N,
int k>
303 if (!pruneSuccessors || history.size() < 3)
311 for (
int x = 0; x < N; x++)
314 if (!movePrune[x*N*N+history.back()*N+history[history.size()-2]])
315 actions.push_back(x);
320 template <
int N,
int k>
323 for (
int x = 0; x < k/2; x++)
328 history.push_back(a);
331 template <
int N,
int k>
334 if (pruneSuccessors && history.size() > 0)
336 assert(history.back() == a);
339 for (
int x = 0; x < k/2; x++)
345 template <
int N,
int k>
352 template <
int N,
int k>
364 static int tscosts[
tsCostCount] = {47,45,52,41,56,43,50,46,49,51,48,53,59,58,55,40,57,60,44,42,54};
367 template <
int N,
int k>
384 template <
int N,
int k>
392 template <
int N,
int k>
395 return GoalTest(state);
399 template <
int N,
int k>
405 template <
int N,
int k>
412 float angleStep =
TWOPI/segments;
414 glBegin(GL_QUAD_STRIP);
415 for (
float angle = 0; angle <
TWOPI; angle += angleStep)
417 glVertex3f(x+cos(angle)*r1, y+sin(angle)*r1, 0);
418 glVertex3f(x+cos(angle)*r2, y+sin(angle)*r2, 0);
420 glVertex3f(x+r1, y, 0);
421 glVertex3f(x+r2, y, 0);
425 static void DrawTSTile(
float x,
float y,
char c1,
char c2,
int w,
int h)
436 glTranslatef(x, y, -0.001);
437 glScalef(1.0/(w*120.0), 1.0/(h*120.0), 1);
438 glRotatef(180, 0.0, 0.0, 1.0);
439 glRotatef(180, 0.0, 1.0, 0.0);
440 glTranslatef(-textWidth/2, -60, 0);
449 template <
int N,
int k>
454 template <
int N,
int k>
457 glEnable(GL_LINE_SMOOTH);
461 for (
int x = 0; x < N; x++)
464 c1 =
'0'+(((s.
puzzle[x])/10)%10);
466 c2 =
'0'+((s.
puzzle[x])%10);
468 glColor3f(1.0, 1.0, 1.0);
469 DrawTSTile(-1+x*diam + diam/2, 0.0f, c1, c2, N, N);
471 glColor3f(0.0, 0.3, 0.8);
472 LocalDrawCircle(-1+x*diam + diam/2, 0, diam/2-diam/20, diam/2+diam/20, 50);
476 template <
int N,
int k>