19 int findInArray(
int arr[],
int elem,
int lower,
int upper);
21 float rotation [3][3] = { {0,0,0}, {0,0,0}, {0,0,0} };
70 bool isCorner =
false;
71 if (RCind >= 12) isCorner =
true;
74 int xPos = 0, yPos = 0, zPos = 0;
75 int xAdd[8] = {3, 4, 5, 10, 13, 14, 17, 18};
76 int xSubt[8] = {0, 1, 7, 8, 12, 15, 16, 19};
77 int yAdd[8] = {8, 9, 10, 11, 16, 17, 18, 19};
78 int ySubt[8] = {0, 2, 4, 6, 12, 13, 14, 15};
79 int zAdd[8] = {5, 6, 7, 11, 14, 15, 18, 19};
80 int zSubt[8] = {1, 2, 3, 9, 12, 13, 16, 17};
83 int starti = 0, endi = 4;
94 }
else if (
findInArray(xSubt, RCpos, starti, endi) != -1)
101 }
else if (
findInArray(ySubt, RCpos, starti, endi) != -1)
108 }
else if (
findInArray(zSubt, RCpos, starti, endi) != -1)
115 for (
int i = 0; i < 6; i++)
124 for (
int i = 0; i < 3; i++)
133 }
else if (RCrot == 1)
136 indToEdit = (i + 1) % 3;
140 indToEdit = (i + 2) % 3;
147 for (
int i = 0; i < 2; i++)
158 std::cout <<
"ERROR: 2 OUT OF BOUNDS [Cubie::Initialize(int RCpos, int RCind, int RCrot)]" <<
'\n';
165 for (
int i = 0; i < 8; i++)
169 if ((i%4) == 1 || (i%4) == 2)
177 for (
int i = 0; i < 6; i++)
179 facePoints.push_back(std::vector<Graphics::point>());
181 for (
int j = 0; j < 4; j++)
184 if (i == 2 || i == 4) x = 1.0f;
186 if (i == 0 || i == 5) y = 1.0f;
188 if (i == 1 || i == 3) z = 1.0f;
200 for (
int i = 0; i < 8; i++)
209 for (
int i = 0; i < 6; i++)
211 for (
int j = 0; j < 4; j++)
227 int xPos = 0, yPos = 0, zPos = 0;
233 for (
int i = 0; i < 6; i++)
239 for (
int i = 0; i < 3; i++)
241 if (in >= i*9 && in <= i*9 + 2)
249 if (in >= 0 && in <= 8)
263 if (in >= 18 && in <= 26)
278 for (
int i = 0; i < 3; i++)
280 if (in >= i*9 + 6 && in <= i*9 + 8)
289 for (
int i = 0; i < 8; i++)
293 if ((i%4) == 1 || (i%4) == 2)
301 for (
int i = 0; i < 6; i++)
303 facePoints.push_back(std::vector<Graphics::point>());
305 for (
int j = 0; j < 4; j++)
308 if (i == 2 || i == 4) x = 1.0f;
310 if (i == 0 || i == 5) y = 1.0f;
312 if (i == 1 || i == 3) z = 1.0f;
324 for (
int i = 0; i < 8; i++)
333 for (
int i = 0; i < 6; i++)
335 for (
int j = 0; j < 4; j++)
372 for (
int i = 1; i < 8; i++)
374 if (
points[i].z > highest) {
380 if (
points[i].z == highest) {
385 for (
int i = 0; i < 6; i++)
389 bool drawThis =
true;
419 display.FillTriangle( points[pointsOnFace[index][0]], points[pointsOnFace[index][1]],
420 points[pointsOnFace[index][2]], outCol);
421 display.FillTriangle( points[pointsOnFace[index][0]], points[pointsOnFace[index][2]],
422 points[pointsOnFace[index][3]], outCol);
424 display.FillTriangle( facePoints[index][0], facePoints[index][1],
425 facePoints[index][2], faceCols[index]);
426 display.FillTriangle( facePoints[index][0], facePoints[index][2],
427 facePoints[index][3], faceCols[index]);
444 for (
int i = 0; i < 6; i++)
447 for (
int j = 0; j < 4; j++)
450 for (
int j = 0; j < 4; j++)
453 for (
int j = 0; j < 4; j++)
472 for (
int i = 0; i < 6; i++)
475 for (
int j = 0; j < 4; j++)
478 for (
int j = 0; j < 4; j++)
481 for (
int j = 0; j < 4; j++)
495 for (
int i = 3; i > 0; i--)
503 for (
int i = 0; i < 3; i++)
516 for (
int i = 0; i < 8; i++)
522 for (
int i = 0; i < 6; i++)
524 for (
int j = 0; j < 4; j++)
559 std::cout <<
"Index: " <<
index << std::endl;
563 std::cout <<
"faceCols: ";
564 for (
int i = 0; i < 6; i ++)
567 } std::cout << std::endl;
569 std::cout <<
"facesShown: ";
570 for (
int i = 0; i < 6; i ++)
573 } std::cout << std::endl;
575 std::cout <<
"faceInPos: ";
576 for (
int i = 0; i < 6; i ++)
579 } std::cout << std::endl;
581 std::cout <<
"points: ";
582 for (
int i = 0; i < 8; i ++)
584 std::cout <<
points[i] <<
", ";
585 } std::cout << std::endl;
587 std::cout <<
"basePoints: ";
588 for (
int i = 0; i < 8; i ++)
590 std::cout <<
points[i] <<
", ";
591 } std::cout << std::endl;
593 std::cout <<
"facePoints: " << std::endl;
594 for (
int i = 0; i < 6; i ++)
596 std::cout <<
" Face " << i <<
": ";
597 for (
int j = 0; j < 8; j++)
600 } std::cout << std::endl;
601 } std::cout << std::endl;
603 std::cout <<
"baseFacePoints: " << std::endl;
604 for (
int i = 0; i < 6; i ++)
606 std::cout <<
" Face " << i <<
": ";
607 for (
int j = 0; j < 8; j++)
610 } std::cout << std::endl;
611 } std::cout << std::endl;
633 if (move == 0) forward =
true;
634 else forward =
false;
763 if (move != 2 && (face == 1 || face == 3))
765 for (
int i = 0; i < 4; i++)
781 int add = 2 - (face % 2);
804 if (face % 5 == 0) index = 0;
805 else if (face % 2 == 1) index = 1;
811 int specialCorners[4] = {13, 15, 16, 18};
814 for (
int i = 0; i < 4; i++)
817 bool special =
false;
818 for(
int j = 0; j < 4; j++){
831 if (special) add = 3-add;
919 for (
int i = 3; i > 0; i--)
930 for (
int i = 0; i < 3; i++)
943 std::cout <<
"Indices: [";
944 for (
int i = 0; i < 20; i++)
946 std::cout <<
indices[i] <<
", ";
948 std::cout <<
"]" << std::endl;
949 std::cout <<
"Rotation: [";
950 for (
int i = 0; i < 20; i++)
954 std::cout <<
"]" << std::endl;
971 for (
int i = 0; i < 26; i++)
987 }
else goto drawCubie;
990 for (
int i = 0; i < 9; i++)
999 for (
int i = 0; i < 17; i++)
1014 for (
int i = 0; i < 3; i++)
1018 for (
int i = 0; i < 26; i++)
1032 bool clockwise =
true;
1042 if (face == 0 || face == 3 || face == 4)
1046 if (face == 5 || face == 3 || face == 4 )
1048 clockwise = !clockwise;
1058 for (
int i = 3; i > 0; i--)
1065 }
else if (move == 1)
1071 for (
int i = 0; i < 3; i++)
1079 clockwise = !clockwise;
1084 for (
int i = 0; i < 2; i++)
1098 }
else if (face == 1 || face == 3) {
1105 for (
int i = 0; i < 9; i++)
1119 if (toEdit >= 13) toEdit++;
1123 if (toEdit >= 14) toEdit--;
1135 for (
int i = 0; i < 3; i++)
1141 for (
int i = 0; i < 9; i++)
1151 for (
int i = 0; i < 17; i++)
1169 float testRot [3] = {0, 0, 0};
1184 for (
int i = 0; i < 3; i++)
1194 for (
int i = 0; i < 26; i++)
1208 neighbors.resize(18);
1209 for (
int x = 0; x < 18; x++)
1240 for (
int x = 0; x < 18; x++)
1241 actions.push_back(x);
1247 int firstFace[6] = {-1, -1, -1, 1, 2, 0};
1248 for (
int x = 0; x < 18; x++)
1255 if (firstFace[x/3] ==
history.back()/3)
1261 actions.push_back(x);
1272 for (
int x = 0; x < 18; x++)
1325 return HCost(node1, node2);
1343 return node == goal;
1349 for (
int x = 0; x < 20; x++)
1351 if (
node.indices[x] != x)
1353 if (
node.rotation[x] != 0)
1411 for (
int i = 0; i < 20; i++)
1418 for (
int i = 0; i < 26; i++)
1441 for (
int i = 0; i < vecRows; i++)
1445 for (
int j = 0; j < vecCols; j++)
1447 sum += vec[i][j] *
array3[j];
1472 a[1][1] = cos(angle);
1473 a[1][2] = -sin(angle);
1476 a[2][1] = sin(angle);
1477 a[2][2] = cos(angle);
1485 a[0][0] = cosf(angle);
1487 a[0][2] = -sin(angle);
1493 a[2][0] = sin(angle);
1495 a[2][2] = cos(angle);
1503 a[0][0] = cosf(angle);
1504 a[0][1] = -sin(angle);
1507 a[1][0] = sin(angle);
1508 a[1][1] = cos(angle);
1521 for (
int i = lower; i < upper; i++)
1523 if (arr[i] == elem)
return i;
1535 uint64_t answer[] = {1, 24, 504, 9072, 136080, 1632960, 14696640, 88179840, 88179840};
1544 int cornerSize =
corners.size();
1545 int lastPiece = 8-(int)
corners.size();
1546 for (
int x = 0; x < 8; x++)
1548 for (
int x = 0; x < cornerSize; x++)
1551 uint64_t hashVal = 0;
1553 int numEntriesLeft = 8;
1566 int limit =
std::min((
int)cornerSize, 7);
1567 for (
int x = 0; x < limit; x++)
1578 int lastPiece = 8-(int)
corners.size();
1579 int cornerSize =
corners.size();
1582 uint64_t hashVal = hash;
1600 for (
int x = 0; x < 8; x++)
1606 for (
int x = 0; x < cornerSize; x++)
1614 for (
int x = limit-1; x >= 0; x--)
1627 uint64_t hashVal = 0;
1628 for (
int x = 0; x < 7; x++)
1630 hashVal = (hashVal<<1) + s.
rotation[19-x];
1742 const uint64_t result[9][9] = {
1748 {120, 120, 60, 20, 5, 1},
1749 {720, 720, 360, 120, 30, 6, 1},
1750 {5040, 5040, 2520, 840, 210, 42, 7, 1},
1751 {40320, 40320, 20160, 6720, 1680, 336, 56, 8, 1},
1753 return result[n][k];
1761 const std::array<bool, 12> &edgeRotations,
const std::array<bool, 12> &edgeLocations,
1762 const std::array<bool, 8> &cornerRotations,
const std::array<bool, 8> &cornerLocations)
1765 for (
int x = 0; x < 12; x++)
1768 this->edgeRotations.push_back(x);
1770 this->edgeLocations.push_back(x);
1772 for (
int x = 0; x < 8; x++)
1775 this->cornerRotations.push_back(x);
1777 this->cornerLocations.push_back(x);
1878 uint64_t answer[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683};
1880 return answer[limit];
1892 for (
int x = 0; x < limit; x++)
1908 for (
int x = 0; x < 12; x++)
1913 uint64_t hashVal = 0;
1914 int numEntriesLeft = 12;
1922 if (puzzle[y] > puzzle[x])
1934 for (
int x = 0; x < limit; x++)
1951 for (
int x = 0; x < 8; x++)
1956 uint64_t hashVal = 0;
1957 int numEntriesLeft = 8;
1958 for (
unsigned int x = 0; x < cornerSize; x++)
1965 if (puzzle[y] > puzzle[x])
1975 for (
int x = 0; x < 12; x++)
1984 for (
int x = limit-1; x >= 0; x--)
2003 uint64_t hashVal = hash;
2007 int numEntriesLeft = lastPiece+1;
2010 puzzle[x] = hashVal%numEntriesLeft;
2011 hashVal /= numEntriesLeft;
2015 if (puzzle[y] >= puzzle[x])
2019 for (
int x = 0; x < 12; x++)
2037 for (
int x = 0; x < 8; x++)
2043 for (
int x = limit-1; x >= 0; x--)
2055 assert((cnt%3) == 0);
2064 uint64_t hashVal = hash;
2068 int numEntriesLeft = lastPiece+1;
2071 puzzle[x] = hashVal%numEntriesLeft;
2072 hashVal /= numEntriesLeft;
2074 for (
int y = x+1; y < cornerSize; y++)
2076 if (puzzle[y] >= puzzle[x])
2080 for (
int x = 0; x < 8; x++)
2087 for (
int x = 0; x < cornerSize; x++)
2097 const uint64_t result[13][13] = {
2103 {120, 120, 60, 20, 5, 1},
2104 {720, 720, 360, 120, 30, 6, 1},
2105 {5040, 5040, 2520, 840, 210, 42, 7, 1},
2106 {40320, 40320, 20160, 6720, 1680, 336, 56, 8, 1},
2107 {362880, 362880, 181440, 60480, 15120, 3024, 504, 72, 9, 1},
2108 {3628800, 3628800, 1814400, 604800, 151200, 30240, 5040, 720, 90, 10, 1},
2109 {39916800, 39916800, 19958400, 6652800, 1663200, 332640, 55440, 7920, 990, 110, 11, 1},
2110 {479001600, 479001600, 239500800, 79833600, 19958400, 3991680, 665280, 95040, 11880, 1320, 132, 12, 1}
2112 return result[n][k];