46 int rotations[] = {8, 9, 1, 2, 0, 6, 7, 11, 10, 3, 4, 5};
47 for (
int x = 0; x < 12; x++)
69 for (
int x = 0; x < 12; x++)
78 return (
state>>(12+4*whichLoc))&0xF;
85 uint64_t value = cube&0xF;
87 state |= (value<<(12+4*whichLoc));
91 return state&(0x1<<whichCube);
99 state |= (0x1<<whichCube);
112 for (
int x = 0; x < 12; x++)
126 for (
int x = 0; x < 12; x++)
138 return state[12+whichLoc];
145 state[whichLoc+12] = cube;
153 return state[whichCube];
160 state[whichCube] = flip;
177 for (
int x = 0; x < 12; x++)
188 for (
int x = 0; x < 18; x++)
191 neighbors.push_back(s);
198 for (
int x = 0; x < 18; x++)
200 actions.push_back(x);
223 else if (1 == todo%3)
237 else if (1 == todo%3)
251 else if (1 == todo%3)
258 template <
typename t>
265 int a = s.GetCubeInLoc(1-1);
266 int b = s.GetCubeInLoc(3-1);
267 int c = s.GetCubeInLoc(5-1);
268 int d = s.GetCubeInLoc(7-1);
269 s.SetCubeInLoc(1-1,
d);
270 s.SetCubeInLoc(3-1, a);
271 s.SetCubeInLoc(5-1, b);
272 s.SetCubeInLoc(7-1, c);
277 int a = s.GetCubeInLoc(1-1);
278 int b = s.GetCubeInLoc(3-1);
279 int c = s.GetCubeInLoc(5-1);
280 int d = s.GetCubeInLoc(7-1);
281 s.SetCubeInLoc(1-1, b);
282 s.SetCubeInLoc(3-1, c);
283 s.SetCubeInLoc(5-1,
d);
284 s.SetCubeInLoc(7-1, a);
289 int a = s.GetCubeInLoc(1-1);
290 int b = s.GetCubeInLoc(3-1);
291 int c = s.GetCubeInLoc(5-1);
292 int d = s.GetCubeInLoc(7-1);
293 s.SetCubeInLoc(1-1, c);
294 s.SetCubeInLoc(3-1,
d);
295 s.SetCubeInLoc(5-1, a);
296 s.SetCubeInLoc(7-1, b);
301 int a = s.GetCubeInLoc(9-1);
302 int b = s.GetCubeInLoc(10-1);
303 int c = s.GetCubeInLoc(11-1);
304 int d = s.GetCubeInLoc(12-1);
305 s.SetCubeInLoc(9-1,
d);
306 s.SetCubeInLoc(10-1, a);
307 s.SetCubeInLoc(11-1, b);
308 s.SetCubeInLoc(12-1, c);
313 int a = s.GetCubeInLoc(9-1);
314 int b = s.GetCubeInLoc(10-1);
315 int c = s.GetCubeInLoc(11-1);
316 int d = s.GetCubeInLoc(12-1);
317 s.SetCubeInLoc(9-1, b);
318 s.SetCubeInLoc(10-1, c);
319 s.SetCubeInLoc(11-1,
d);
320 s.SetCubeInLoc(12-1, a);
325 int a = s.GetCubeInLoc(9-1);
326 int b = s.GetCubeInLoc(10-1);
327 int c = s.GetCubeInLoc(11-1);
328 int d = s.GetCubeInLoc(12-1);
329 s.SetCubeInLoc(9-1, c);
330 s.SetCubeInLoc(10-1,
d);
331 s.SetCubeInLoc(11-1, a);
332 s.SetCubeInLoc(12-1, b);
338 int a = s.GetCubeInLoc(2-1);
339 int b = s.GetCubeInLoc(3-1);
340 int c = s.GetCubeInLoc(4-1);
341 int d = s.GetCubeInLoc(10-1);
342 s.SetCubeInLoc(2-1,
d);
343 s.SetCubeInLoc(3-1, a);
344 s.SetCubeInLoc(4-1, b);
345 s.SetCubeInLoc(10-1, c);
346 s.FlipCubeOrientation(b);
347 s.FlipCubeOrientation(
d);
352 int a = s.GetCubeInLoc(2-1);
353 int b = s.GetCubeInLoc(3-1);
354 int c = s.GetCubeInLoc(4-1);
355 int d = s.GetCubeInLoc(10-1);
356 s.SetCubeInLoc(2-1, b);
357 s.SetCubeInLoc(3-1, c);
358 s.SetCubeInLoc(4-1,
d);
359 s.SetCubeInLoc(10-1, a);
360 s.FlipCubeOrientation(a);
361 s.FlipCubeOrientation(c);
366 int a = s.GetCubeInLoc(2-1);
367 int b = s.GetCubeInLoc(3-1);
368 int c = s.GetCubeInLoc(4-1);
369 int d = s.GetCubeInLoc(10-1);
370 s.SetCubeInLoc(2-1, c);
371 s.SetCubeInLoc(3-1,
d);
372 s.SetCubeInLoc(4-1, a);
373 s.SetCubeInLoc(10-1, b);
374 s.FlipCubeOrientation(a);
375 s.FlipCubeOrientation(b);
376 s.FlipCubeOrientation(c);
377 s.FlipCubeOrientation(
d);
383 int a = s.GetCubeInLoc(6-1);
384 int b = s.GetCubeInLoc(7-1);
385 int c = s.GetCubeInLoc(8-1);
386 int d = s.GetCubeInLoc(12-1);
387 s.SetCubeInLoc(6-1,
d);
388 s.SetCubeInLoc(7-1, a);
389 s.SetCubeInLoc(8-1, b);
390 s.SetCubeInLoc(12-1, c);
391 s.FlipCubeOrientation(c);
392 s.FlipCubeOrientation(
d);
397 int a = s.GetCubeInLoc(6-1);
398 int b = s.GetCubeInLoc(7-1);
399 int c = s.GetCubeInLoc(8-1);
400 int d = s.GetCubeInLoc(12-1);
401 s.SetCubeInLoc(6-1, b);
402 s.SetCubeInLoc(7-1, c);
403 s.SetCubeInLoc(8-1,
d);
404 s.SetCubeInLoc(12-1, a);
405 s.FlipCubeOrientation(a);
406 s.FlipCubeOrientation(
d);
411 int a = s.GetCubeInLoc(6-1);
412 int b = s.GetCubeInLoc(7-1);
413 int c = s.GetCubeInLoc(8-1);
414 int d = s.GetCubeInLoc(12-1);
415 s.SetCubeInLoc(6-1, c);
416 s.SetCubeInLoc(7-1,
d);
417 s.SetCubeInLoc(8-1, a);
418 s.SetCubeInLoc(12-1, b);
419 s.FlipCubeOrientation(b);
420 s.FlipCubeOrientation(
d);
426 int a = s.GetCubeInLoc(1-1);
427 int b = s.GetCubeInLoc(2-1);
428 int c = s.GetCubeInLoc(9-1);
429 int d = s.GetCubeInLoc(8-1);
430 s.SetCubeInLoc(1-1,
d);
431 s.SetCubeInLoc(2-1, a);
432 s.SetCubeInLoc(9-1, b);
433 s.SetCubeInLoc(8-1, c);
434 s.FlipCubeOrientation(a);
435 s.FlipCubeOrientation(
d);
440 int a = s.GetCubeInLoc(1-1);
441 int b = s.GetCubeInLoc(2-1);
442 int c = s.GetCubeInLoc(9-1);
443 int d = s.GetCubeInLoc(8-1);
444 s.SetCubeInLoc(1-1, b);
445 s.SetCubeInLoc(2-1, c);
446 s.SetCubeInLoc(9-1,
d);
447 s.SetCubeInLoc(8-1, a);
448 s.FlipCubeOrientation(a);
449 s.FlipCubeOrientation(b);
454 int a = s.GetCubeInLoc(1-1);
455 int b = s.GetCubeInLoc(2-1);
456 int c = s.GetCubeInLoc(9-1);
457 int d = s.GetCubeInLoc(8-1);
458 s.SetCubeInLoc(1-1, c);
459 s.SetCubeInLoc(2-1,
d);
460 s.SetCubeInLoc(9-1, a);
461 s.SetCubeInLoc(8-1, b);
462 s.FlipCubeOrientation(a);
463 s.FlipCubeOrientation(c);
468 int a = s.GetCubeInLoc(4-1);
469 int b = s.GetCubeInLoc(5-1);
470 int c = s.GetCubeInLoc(6-1);
471 int d = s.GetCubeInLoc(11-1);
472 s.SetCubeInLoc(4-1,
d);
473 s.SetCubeInLoc(5-1, a);
474 s.SetCubeInLoc(6-1, b);
475 s.SetCubeInLoc(11-1, c);
476 s.FlipCubeOrientation(b);
477 s.FlipCubeOrientation(
d);
482 int a = s.GetCubeInLoc(4-1);
483 int b = s.GetCubeInLoc(5-1);
484 int c = s.GetCubeInLoc(6-1);
485 int d = s.GetCubeInLoc(11-1);
486 s.SetCubeInLoc(4-1, b);
487 s.SetCubeInLoc(5-1, c);
488 s.SetCubeInLoc(6-1,
d);
489 s.SetCubeInLoc(11-1, a);
490 s.FlipCubeOrientation(a);
491 s.FlipCubeOrientation(c);
496 int a = s.GetCubeInLoc(4-1);
497 int b = s.GetCubeInLoc(5-1);
498 int c = s.GetCubeInLoc(6-1);
499 int d = s.GetCubeInLoc(11-1);
500 s.SetCubeInLoc(4-1, c);
501 s.SetCubeInLoc(5-1,
d);
502 s.SetCubeInLoc(6-1, a);
503 s.SetCubeInLoc(11-1, b);
504 s.FlipCubeOrientation(a);
505 s.FlipCubeOrientation(b);
506 s.FlipCubeOrientation(c);
507 s.FlipCubeOrientation(
d);
518 LocalApplyAction<RubikEdgeStateArray>(s, a);
523 LocalApplyAction<RubikEdgeStateBits>(s, a);
549 assert(!
"Code not called");
555 assert(!
"Code not called");
562 { 1ll, 1ll, 2ll, 6ll, 24ll, 120ll, 720ll, 5040ll, 40320ll, 362880ll, 3628800ll, 39916800ll, 479001600ll,
563 6227020800ll, 87178291200ll, 1307674368000ll, 20922789888000ll, 355687428096000ll,
564 6402373705728000ll, 121645100408832000ll, 2432902008176640000ll };
569 inline int get(uint64_t state,
int whichLoc)
571 return (state>>((whichLoc<<2)))&0xF;
574 inline void set(uint64_t &state,
int whichLoc,
int cube)
576 const uint64_t blank = 0xF;
577 uint64_t value = cube;
578 state = state&(~(blank<<((whichLoc<<2))));
579 state |= (value<<((whichLoc<<2)));
582 inline void swap(uint64_t &state,
int loc1,
int loc2)
586 uint64_t val1 = (state>>(loc1));
587 uint64_t val2 = (state>>(loc2));
589 uint64_t xord = (val1 ^ val2)&0xF;
590 xord = (xord << loc1) | (xord << loc2);
601 { 1ll, 1ll, 2ll, 6ll, 24ll, 120ll, 720ll, 5040ll, 40320ll, 362880ll, 3628800ll, 39916800ll, 479001600ll,
602 6227020800ll, 87178291200ll, 1307674368000ll, 20922789888000ll, 355687428096000ll,
603 6402373705728000ll, 121645100408832000ll, 2432902008176640000ll };
630 uint64_t perm = 0, dual = 0;
631 for (
int x = 0; x < 12; x++)
633 set(perm, x,
node.GetCubeInLoc(x));
634 set(dual,
node.GetCubeInLoc(x), x);
637 uint64_t hashVal = 0;
638 for (
int x = 7; x < 11; x++)
640 hashVal = (hashVal<<1)+
node.GetCubeOrientation(11-x);
649 uint64_t perm = 0, dual = 0;
650 for (
int x = 0; x < 12; x++)
652 int val =
node.GetCubeInLoc(x);
657 uint64_t hashVal = 0;
658 for (
int x = 0; x < 11; x++)
660 hashVal = (hashVal<<1)+
node.GetCubeOrientation(11-x);
675 for (
int i = n; i > 1; i--)
681 swap(perm, i-1,
get(dual, i-1));
687 for (
int i = (
int)ssLoc-1; i >= 0; i--)
709 int s =
get(perm, n-1);
710 swap(perm, n-1,
get(dual, n-1));
712 return s+n*
MRRank2(n-1, perm, dual);
720 for (
int x = 10; x >= 0; x--)
722 node.SetCubeOrientation(11-x,
bits&0x1);
728 node.SetCubeOrientation(11-11,
true);
731 node.SetCubeOrientation(11-11,
false);
735 for (
int x = 0; x < 12; x++)
738 for (
int x = 0; x < 12; x++)
740 node.SetCubeInLoc(x,
get(val, x));
752 swap(perm, n-1, r%n);
760 for (
int i = n; i > 0; i--)
763 swap(perm, i-1, r%i);
844 for (
int x = 1; x <= 7; x+=2)
850 for (
int x = 9; x <= 25; x+=2)
868 const float scale = 0.3;
869 const float offset = 0.95*2.0*scale/3.0;
870 const float offset2 = 2.0*scale/3.0;
871 const float epsilon = 0.002;
878 glVertex3f(-offset/2.0, -scale, -scale);
879 glVertex3f(-offset/2.0, -scale, -scale+offset);
880 glVertex3f(offset/2.0, -scale, -scale+offset);
881 glVertex3f(offset/2.0, -scale, -scale);
884 glVertex3f(-offset2/2.0, -scale+epsilon, -scale);
885 glVertex3f(-offset2/2.0, -scale+epsilon, -scale+offset2);
886 glVertex3f(offset2/2.0, -scale+epsilon, -scale+offset2);
887 glVertex3f(offset2/2.0, -scale+epsilon, -scale);
892 glVertex3f(-offset/2.0, -scale+offset, -scale);
893 glVertex3f(offset/2.0, -scale+offset, -scale);
894 glVertex3f(offset/2.0, -scale, -scale);
895 glVertex3f(-offset/2.0, -scale, -scale);
898 glVertex3f(-offset2/2.0, -scale+offset2, -scale+epsilon);
899 glVertex3f(offset2/2.0, -scale+offset2, -scale+epsilon);
900 glVertex3f(offset2/2.0, -scale, -scale+epsilon);
901 glVertex3f(-offset2/2.0, -scale, -scale+epsilon);
908 glVertex3f(-scale, -scale, offset/2.0);
909 glVertex3f(-scale, -scale, -offset/2.0);
910 glVertex3f(-scale+offset, -scale, -offset/2.0);
911 glVertex3f(-scale+offset, -scale, offset/2.0);
914 glVertex3f(-scale, -scale+epsilon, offset2/2.0);
915 glVertex3f(-scale, -scale+epsilon, -offset2/2.0);
916 glVertex3f(-scale+offset2, -scale+epsilon, -offset2/2.0);
917 glVertex3f(-scale+offset2, -scale+epsilon, offset2/2.0);
921 glVertex3f(-scale, -scale+offset, -offset/2.0);
922 glVertex3f(-scale, -scale+offset, offset/2.0);
923 glVertex3f(-scale, -scale, offset/2.0);
924 glVertex3f(-scale, -scale, -offset/2.0);
927 glVertex3f(-scale+epsilon, -scale+offset2, -offset2/2.0);
928 glVertex3f(-scale+epsilon, -scale+offset2, offset2/2.0);
929 glVertex3f(-scale+epsilon, -scale, offset2/2.0);
930 glVertex3f(-scale+epsilon, -scale, -offset2/2.0);
937 glVertex3f(scale, -scale, offset/2.0);
938 glVertex3f(scale, -scale, -offset/2.0);
939 glVertex3f(scale-offset, -scale, -offset/2.0);
940 glVertex3f(scale-offset, -scale, offset/2.0);
943 glVertex3f(scale, -scale+epsilon, offset2/2.0);
944 glVertex3f(scale, -scale+epsilon, -offset2/2.0);
945 glVertex3f(scale-offset2, -scale+epsilon, -offset2/2.0);
946 glVertex3f(scale-offset2, -scale+epsilon, offset2/2.0);
950 glVertex3f(scale, -scale+offset, -offset/2.0);
951 glVertex3f(scale, -scale+offset, offset/2.0);
952 glVertex3f(scale, -scale, offset/2.0);
953 glVertex3f(scale, -scale, -offset/2.0);
956 glVertex3f(scale-epsilon, -scale+offset2, -offset2/2.0);
957 glVertex3f(scale-epsilon, -scale+offset2, offset2/2.0);
958 glVertex3f(scale-epsilon, -scale, offset2/2.0);
959 glVertex3f(scale-epsilon, -scale, -offset2/2.0);
965 glVertex3f(-offset/2.0, -scale, scale);
966 glVertex3f(-offset/2.0, -scale, scale-offset);
967 glVertex3f(offset/2.0, -scale, scale-offset);
968 glVertex3f(offset/2.0, -scale, scale);
971 glVertex3f(-offset2/2.0, -scale+epsilon, scale);
972 glVertex3f(-offset2/2.0, -scale+epsilon, scale-offset2);
973 glVertex3f(offset2/2.0, -scale+epsilon, scale-offset2);
974 glVertex3f(offset2/2.0, -scale+epsilon, scale);
978 glVertex3f(-offset/2.0, -scale+offset, scale);
979 glVertex3f(offset/2.0, -scale+offset, scale);
980 glVertex3f(offset/2.0, -scale, scale);
981 glVertex3f(-offset/2.0, -scale, scale);
984 glVertex3f(-offset2/2.0, -scale+offset2, scale-epsilon);
985 glVertex3f(offset2/2.0, -scale+offset2, scale-epsilon);
986 glVertex3f(offset2/2.0, -scale, scale-epsilon);
987 glVertex3f(-offset2/2.0, -scale, scale-epsilon);
994 glVertex3f(-scale, -offset/2.0, -scale+offset);
995 glVertex3f(-scale, offset/2.0, -scale+offset);
996 glVertex3f(-scale, offset/2.0, -scale);
997 glVertex3f(-scale, -offset/2.0, -scale);
1000 glVertex3f(-scale+epsilon, -offset2/2.0, -scale+offset2);
1001 glVertex3f(-scale+epsilon, offset2/2.0, -scale+offset2);
1002 glVertex3f(-scale+epsilon, offset2/2.0, -scale);
1003 glVertex3f(-scale+epsilon, -offset2/2.0, -scale);
1008 glVertex3f(-scale+offset, -offset/2.0, -scale);
1009 glVertex3f(-scale+offset, offset/2.0, -scale);
1010 glVertex3f(-scale, offset/2.0, -scale);
1011 glVertex3f(-scale, -offset/2.0, -scale);
1014 glVertex3f(-scale+offset2, -offset2/2.0, -scale+epsilon);
1015 glVertex3f(-scale+offset2, offset2/2.0, -scale+epsilon);
1016 glVertex3f(-scale, offset2/2.0, -scale+epsilon);
1017 glVertex3f(-scale, -offset2/2.0, -scale+epsilon);
1023 glVertex3f(scale-offset, -offset/2.0, -scale);
1024 glVertex3f(scale-offset, offset/2.0, -scale);
1025 glVertex3f(scale, offset/2.0, -scale);
1026 glVertex3f(scale, -offset/2.0, -scale);
1029 glVertex3f(scale-offset2, -offset2/2.0, -scale+epsilon);
1030 glVertex3f(scale-offset2, offset2/2.0, -scale+epsilon);
1031 glVertex3f(scale, offset2/2.0, -scale+epsilon);
1032 glVertex3f(scale, -offset2/2.0, -scale+epsilon);
1037 glVertex3f(scale, -offset/2.0, -scale+offset);
1038 glVertex3f(scale, offset/2.0, -scale+offset);
1039 glVertex3f(scale, offset/2.0, -scale);
1040 glVertex3f(scale, -offset/2.0, -scale);
1043 glVertex3f(scale-epsilon, -offset2/2.0, -scale+offset2);
1044 glVertex3f(scale-epsilon, offset2/2.0, -scale+offset2);
1045 glVertex3f(scale-epsilon, offset2/2.0, -scale);
1046 glVertex3f(scale-epsilon, -offset2/2.0, -scale);
1053 glVertex3f(-scale, -offset/2.0, scale-offset);
1054 glVertex3f(-scale, offset/2.0, scale-offset);
1055 glVertex3f(-scale, offset/2.0, scale);
1056 glVertex3f(-scale, -offset/2.0, scale);
1059 glVertex3f(-scale+epsilon, -offset2/2.0, scale-offset2);
1060 glVertex3f(-scale+epsilon, offset2/2.0, scale-offset2);
1061 glVertex3f(-scale+epsilon, offset2/2.0, scale);
1062 glVertex3f(-scale+epsilon, -offset2/2.0, scale);
1066 glVertex3f(-scale+offset, -offset/2.0, scale);
1067 glVertex3f(-scale+offset, offset/2.0, scale);
1068 glVertex3f(-scale, offset/2.0, scale);
1069 glVertex3f(-scale, -offset/2.0, scale);
1072 glVertex3f(-scale+offset2, -offset2/2.0, scale-epsilon);
1073 glVertex3f(-scale+offset2, offset2/2.0, scale-epsilon);
1074 glVertex3f(-scale, offset2/2.0, scale-epsilon);
1075 glVertex3f(-scale, -offset2/2.0, scale-epsilon);
1082 glVertex3f(scale, -offset/2.0, scale-offset);
1083 glVertex3f(scale, offset/2.0, scale-offset);
1084 glVertex3f(scale, offset/2.0, scale);
1085 glVertex3f(scale, -offset/2.0, scale);
1088 glVertex3f(scale-epsilon, -offset2/2.0, scale-offset2);
1089 glVertex3f(scale-epsilon, offset2/2.0, scale-offset2);
1090 glVertex3f(scale-epsilon, offset2/2.0, scale);
1091 glVertex3f(scale-epsilon, -offset2/2.0, scale);
1095 glVertex3f(scale-offset, -offset/2.0, scale);
1096 glVertex3f(scale-offset, offset/2.0, scale);
1097 glVertex3f(scale, offset/2.0, scale);
1098 glVertex3f(scale, -offset/2.0, scale);
1101 glVertex3f(scale-offset2, -offset2/2.0, scale-epsilon);
1102 glVertex3f(scale-offset2, offset2/2.0, scale-epsilon);
1103 glVertex3f(scale, offset2/2.0, scale-epsilon);
1104 glVertex3f(scale, -offset2/2.0, scale-epsilon);
1110 glVertex3f(-offset/2.0, scale-offset, -scale);
1111 glVertex3f(offset/2.0, scale-offset, -scale);
1112 glVertex3f(offset/2.0, scale, -scale);
1113 glVertex3f(-offset/2.0, scale, -scale);
1116 glVertex3f(-offset2/2.0, scale-offset2, -scale+epsilon);
1117 glVertex3f(offset2/2.0, scale-offset2, -scale+epsilon);
1118 glVertex3f(offset2/2.0, scale, -scale+epsilon);
1119 glVertex3f(-offset2/2.0, scale, -scale+epsilon);
1123 glVertex3f(-offset/2.0, scale, -scale);
1124 glVertex3f(-offset/2.0, scale, -scale+offset);
1125 glVertex3f(offset/2.0, scale, -scale+offset);
1126 glVertex3f(offset/2.0, scale, -scale);
1129 glVertex3f(-offset2/2.0, scale-epsilon, -scale);
1130 glVertex3f(-offset2/2.0, scale-epsilon, -scale+offset2);
1131 glVertex3f(offset2/2.0, scale-epsilon, -scale+offset2);
1132 glVertex3f(offset2/2.0, scale-epsilon, -scale);
1139 glVertex3f(-scale, scale-offset, -offset/2.0);
1140 glVertex3f(-scale, scale-offset, offset/2.0);
1141 glVertex3f(-scale, scale, offset/2.0);
1142 glVertex3f(-scale, scale, -offset/2.0);
1145 glVertex3f(-scale+epsilon, scale-offset2, -offset2/2.0);
1146 glVertex3f(-scale+epsilon, scale-offset2, offset2/2.0);
1147 glVertex3f(-scale+epsilon, scale, offset2/2.0);
1148 glVertex3f(-scale+epsilon, scale, -offset2/2.0);
1152 glVertex3f(-scale, scale, offset/2.0);
1153 glVertex3f(-scale, scale, -offset/2.0);
1154 glVertex3f(-scale+offset, scale, -offset/2.0);
1155 glVertex3f(-scale+offset, scale, offset/2.0);
1158 glVertex3f(-scale, scale-epsilon, offset2/2.0);
1159 glVertex3f(-scale, scale-epsilon, -offset2/2.0);
1160 glVertex3f(-scale+offset2, scale-epsilon, -offset2/2.0);
1161 glVertex3f(-scale+offset2, scale-epsilon, offset2/2.0);
1168 glVertex3f(scale, scale-offset, -offset/2.0);
1169 glVertex3f(scale, scale-offset, offset/2.0);
1170 glVertex3f(scale, scale, offset/2.0);
1171 glVertex3f(scale, scale, -offset/2.0);
1174 glVertex3f(scale-epsilon, scale-offset2, -offset2/2.0);
1175 glVertex3f(scale-epsilon, scale-offset2, offset2/2.0);
1176 glVertex3f(scale-epsilon, scale, offset2/2.0);
1177 glVertex3f(scale-epsilon, scale, -offset2/2.0);
1181 glVertex3f(scale, scale, offset/2.0);
1182 glVertex3f(scale, scale, -offset/2.0);
1183 glVertex3f(scale-offset, scale, -offset/2.0);
1184 glVertex3f(scale-offset, scale, offset/2.0);
1187 glVertex3f(scale, scale-epsilon, offset2/2.0);
1188 glVertex3f(scale, scale-epsilon, -offset2/2.0);
1189 glVertex3f(scale-offset2, scale-epsilon, -offset2/2.0);
1190 glVertex3f(scale-offset2, scale-epsilon, offset2/2.0);
1197 glVertex3f(-offset/2.0, scale-offset, scale);
1198 glVertex3f(offset/2.0, scale-offset, scale);
1199 glVertex3f(offset/2.0, scale, scale);
1200 glVertex3f(-offset/2.0, scale, scale);
1203 glVertex3f(-offset2/2.0, scale-offset2, scale-epsilon);
1204 glVertex3f(offset2/2.0, scale-offset2, scale-epsilon);
1205 glVertex3f(offset2/2.0, scale, scale-epsilon);
1206 glVertex3f(-offset2/2.0, scale, scale-epsilon);
1210 glVertex3f(-offset/2.0, scale, scale);
1211 glVertex3f(-offset/2.0, scale, scale-offset);
1212 glVertex3f(offset/2.0, scale, scale-offset);
1213 glVertex3f(offset/2.0, scale, scale);
1216 glVertex3f(-offset2/2.0, scale-epsilon, scale);
1217 glVertex3f(-offset2/2.0, scale-epsilon, scale-offset2);
1218 glVertex3f(offset2/2.0, scale-epsilon, scale-offset2);
1219 glVertex3f(offset2/2.0, scale-epsilon, scale);
1227 int cubes_first[12] = { 0, 1, 0, 2, 0, 3, 0, 1, 1, 2, 3, 4};
1228 int cubes_second[12] = { 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5};
1232 glColor3f(0.0, 0.0, 0.0);
1240 glColor3f(0.0, 0.0, 0.0);
1244 if (flipped == face)
1245 theColor = cubes_first[cube];
1247 theColor = cubes_second[cube];
1251 case 0: glColor3f(1.0, 0.0, 0.0);
break;
1252 case 1: glColor3f(0.0, 1.0, 0.0);
break;
1253 case 2: glColor3f(0.0, 0.0, 1.0);
break;
1254 case 3: glColor3f(1.0, 1.0, 0.0);
break;
1255 case 4: glColor3f(1.0, 0.75, 0.0);
break;
1256 case 5: glColor3f(1.0, 1.0, 1.0);
break;
1257 default: assert(
false);
1263 :
PDBHeuristic(e), edges(distinctEdges), puzzles(
std::thread::hardware_concurrency())
1265 for (
size_t x = 0; x <
puzzles.size(); x++)
1272 #pragma message("This code belongs in the RubikEdge, not in the PDB.")
1273 return 479001600ll*2048ll;
1278 uint64_t perm = 0, dual = 0;
1279 for (
int x = 0; x < 12; x++)
1286 uint64_t hashVal = 0;
1287 for (
int x = 0; x < 11; x++)
1300 for (
int x = 10; x >= 0; x--)
1315 for (
int x = 0; x < 12; x++)
1318 for (
int x = 0; x < 12; x++)
1329 uint64_t power2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 2048};
1330 int elts = (int)
edges.size();
1340 int puzzle[12] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
1343 int edgeSize =
edges.size();
1344 int lastPiece = 12-(int)edgeSize;
1345 for (
int x = 0; x < 12; x++)
1347 for (
int x = 0; x < edgeSize; x++)
1349 newdual[x] = dual[
edges[x]];
1350 puzzle[dual[
edges[x]]] = x;
1352 uint64_t hashVal = 0;
1354 hashVal =
mr1.
Rank(puzzle, newdual, edgeSize, 12);
1358 for (
int x = 0; x < limit; x++)
1366 int lastPiece = 12-(int)
edges.size();
1368 for (
int x = 0; x < 12; x++)
1370 for (
int x = 0; x <
edges.size(); x++)
1371 puzzle[x] = dual[
edges[x]];
1373 uint64_t hashVal = 0;
1375 int numEntriesLeft = 12;
1376 for (
unsigned int x = 0; x <
edges.size(); x++)
1381 for (
unsigned y = x; y <
edges.size(); y++)
1383 if (puzzle[y] > puzzle[x])
1388 for (
int x = 0; x < limit; x++)
1402 int lastPiece = 12-(int)
edges.size();
1403 int puzzle[12] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
1404 int dual[16] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
1405 uint64_t hashVal = hash;
1406 int edgeSize =
edges.size();
1410 mr1.
Unrank(hashVal, puzzle, dual, edgeSize, 12);
1411 for (
int x = 0; x < 12; x++)
1417 for (
int x = 0; x < edgeSize; x++)
1423 int limit =
std::min((
int)edgeSize, 11);
1424 for (
int x = limit-1; x >= 0; x--)
1430 if (
edges.size() == 12)
1432 assert(!
"Be sure to test this code");
1438 int lastPiece = 12-(int)
edges.size();
1441 uint64_t hashVal = hash;
1445 int numEntriesLeft = lastPiece+1;
1446 for (
int x =
edges.size()-1; x >= 0; x--)
1448 puzzle[x] = hashVal%numEntriesLeft;
1449 hashVal /= numEntriesLeft;
1451 for (
int y = x+1; y <
edges.size(); y++)
1453 if (puzzle[y] >= puzzle[x])
1457 for (
int x = 0; x < 12; x++)
1463 for (
int x = 0; x <
edges.size(); x++)
1466 dual[
edges[x]] = puzzle[x];
1471 for (
int x = limit-1; x >= 0; x--)
1478 if (
edges.size() == 12)
1485 FILE *f = fopen(
GetFileName(prefix).c_str(),
"rb");
1488 perror(
"Opening RubiksEdgePDB file");
1498 FILE *f = fopen(
GetFileName(prefix).c_str(),
"w+");
1501 perror(
"Opening RubiksEdgePDB file");
1518 size_t edgeSize =
edges.size();
1519 if (fread(&edgeSize,
sizeof(edgeSize), 1, f) != 1)
1521 edges.resize(edgeSize);
1532 size_t edgeSize =
edges.size();
1533 fwrite(&edgeSize,
sizeof(edgeSize), 1, f);
1539 std::string fileName;
1540 fileName +=
"RC-E-";
1542 for (
int x = 0; x < 12; x++)
1544 fileName += std::to_string(
goalState[0].GetCubeInLoc(x));
1546 fileName += std::to_string(
goalState[0].GetCubeOrientation(
goalState[0].GetCubeInLoc(x)));
1549 fileName.pop_back();
1552 for (
size_t x = 0; x <
edges.size(); x++)
1554 fileName += std::to_string(
edges[x]);
1557 fileName.pop_back();
1561 if (std::is_same<RubikEdgeStateArray,RubikEdgeState>::value)
1572 static uint64_t table[21] =
1573 { 1ll, 1ll, 2ll, 6ll, 24ll, 120ll, 720ll, 5040ll, 40320ll, 362880ll, 3628800ll, 39916800ll, 479001600ll,
1574 6227020800ll, 87178291200ll, 1307674368000ll, 20922789888000ll, 355687428096000ll,
1575 6402373705728000ll, 121645100408832000ll, 2432902008176640000ll };
1577 return (uint64_t)-1;
1583 const uint64_t result[13][13] = {
1589 {120, 120, 60, 20, 5, 1},
1590 {720, 720, 360, 120, 30, 6, 1},
1591 {5040, 5040, 2520, 840, 210, 42, 7, 1},
1592 {40320, 40320, 20160, 6720, 1680, 336, 56, 8, 1},
1593 {362880, 362880, 181440, 60480, 15120, 3024, 504, 72, 9, 1},
1594 {3628800, 3628800, 1814400, 604800, 151200, 30240, 5040, 720, 90, 10, 1},
1595 {39916800, 39916800, 19958400, 6652800, 1663200, 332640, 55440, 7920, 990, 110, 11, 1},
1596 {479001600, 479001600, 239500800, 79833600, 19958400, 3991680, 665280, 95040, 11880, 1320, 132, 12, 1}
1598 return result[n][k];
1611 #pragma mark orientation pdb
1621 #pragma message("This code belongs in the RubikEdge, not in the PDB.")
1627 uint64_t hashVal = 0;
1628 for (
int x = 0; x < 11; x++)
1638 for (
int x = 10; x >= 0; x--)
1672 FILE *f = fopen(
GetFileName(prefix).c_str(),
"rb");
1675 perror(
"Opening RubiksEdgePDB file");
1685 FILE *f = fopen(
GetFileName(prefix).c_str(),
"w+");
1688 perror(
"Opening RubiksEdgePDB file");
1711 std::string fileName;
1712 fileName +=
"RC-E12-OR.pdb";