SHARE
TWEET

only first face

a guest Jan 22nd, 2020 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <iostream>
  4. #include <memory>
  5. #include <string>
  6. #include <algorithm>
  7. #include <ctime>
  8. #include <random>
  9.  
  10.  
  11. enum Colors {
  12.     white = 0,
  13.     yellow = 1,
  14.     red = 2,
  15.     green = 3,
  16.     orange = 4,
  17.     blue = 5
  18. };
  19.  
  20. enum Directions {
  21.     x = 0,
  22.     y = 1,
  23.     z = 2
  24. };
  25.  
  26. enum Movements {
  27.     R = 0,
  28.     Rp = 1,
  29.     L = 2,
  30.     Lp = 3,
  31.     U = 4,
  32.     Up = 5,
  33.     D = 6,
  34.     Dp = 7,
  35.     F = 8,
  36.     Fp = 9,
  37.     B = 10,
  38.     Bp = 11
  39. };
  40.  
  41.  
  42. class Piece {
  43.    
  44.     protected:
  45.    
  46.    
  47.    
  48.     public:
  49.    
  50.     virtual std::shared_ptr<Piece> copy() {}
  51.     virtual int getColor() {}
  52.     virtual int getColor(int i) {}
  53.     virtual std::ostream& getStream(std::ostream& stream) {return stream;}
  54.     virtual void rotate() {}
  55.     virtual void rotate(int unchangedDirection) {}
  56.     virtual std::vector<int> getAllColors() {}
  57.    
  58. };
  59.  
  60. class Corner : public Piece {
  61.    
  62.     private:
  63.     int m_xColor;
  64.     int m_yColor;
  65.     int m_zColor;
  66.    
  67.     public:
  68.    
  69.     Corner(int xColor, int yColor, int zColor);
  70.     virtual std::shared_ptr<Piece> copy();
  71.     virtual int getColor(int i);
  72.     virtual std::ostream& getStream(std::ostream& stream) override;
  73.     virtual void rotate(int unchangedDirection);
  74.     virtual std::vector<int> getAllColors();
  75. };
  76.  
  77. class Edge : public Piece {
  78.    
  79.     private:
  80.     int m_color1;
  81.     int m_color2;
  82.  
  83.     public:
  84.    
  85.     // color1 is the color oriented to the white side or the yellow side.
  86.     // If there is not, this is the color oriented to the red or the orange side.
  87.     // color2 is the other color
  88.     Edge(int color1, int color2);
  89.     virtual std::shared_ptr<Piece> copy();
  90.     virtual int getColor(int i);
  91.     virtual std::ostream& getStream(std::ostream& stream) override;
  92.     virtual void rotate();
  93.     virtual std::vector<int> getAllColors();
  94. };
  95.  
  96. class Center : public Piece {
  97.    
  98.     private:
  99.     int m_color;
  100.    
  101.     public:
  102.    
  103.     Center(int color);
  104.     virtual std::shared_ptr<Piece> copy();
  105.     virtual int getColor();
  106.     virtual std::ostream& getStream(std::ostream& stream) override;
  107.     virtual std::vector<int> getAllColors();
  108. };
  109.  
  110. typedef std::vector<std::vector<std::shared_ptr<Piece>>> vectorOfPieces;
  111.  
  112. class Sequence {
  113.    
  114. };
  115.  
  116. class RubiksCube {
  117.    
  118.     private:
  119.     vectorOfPieces m_possibility;
  120.     void move(int corners[4][2], int edges[4][2], bool prime, bool doEdgesRotate, int cornerUnchangedDirection);
  121.     void moveInterior(int edges[4][2], int centers[4][2], bool prime);
  122.     bool isPieceWellPlaced(vectorOfPieces objective, std::shared_ptr<Piece> piece);
  123.     std::vector<int> findPlaceOfPiece(std::shared_ptr<Piece> piece, vectorOfPieces possibility);
  124.     // RESOLUTION
  125.     // FIRST CROSS (WHITE FACE)
  126.     void solveFirstCross(vectorOfPieces objective);
  127.     void putEdgeDown(std::shared_ptr<Piece> edge);
  128.     void placeEdge(vectorOfPieces objective, std::shared_ptr<Piece> edge);
  129.     // 1st FACE (WHITE) = CORNERS
  130.     void finishFirstFace(vectorOfPieces objective);
  131.     void putCornerDown(std::shared_ptr<Piece> corner);
  132.     void placeCorner(vectorOfPieces objective, std::shared_ptr<Piece> corner);
  133.     // 2ND LAYER = EDGES
  134.     void solveSecondLayer(vectorOfPieces objective);
  135.     void put2ndLayerEdgeDown(std::shared_ptr<Piece> edge);
  136.     void place2ndLayerEdgeDown(vectorOfPieces objective, std::shared_ptr<Piece> edge);
  137.     void silentMovex();
  138.     void silentMovexp();
  139.     void silentMovey();
  140.     void silentMoveyp();
  141.     void silentMovez();
  142.     void silentMovezp();
  143.    
  144.  
  145.     public:
  146.     static RubiksCube askForCube();
  147.     static RubiksCube makeRandomCube();
  148.     static RubiksCube makeRandomCube(vectorOfPieces possibility);
  149.     static RubiksCube makeRandomCube(vectorOfPieces possibility, int seed);
  150.     RubiksCube(vectorOfPieces possibility);
  151.     void moveR();
  152.     void moveRp();
  153.     void moveL();
  154.     void moveLp();
  155.     void moveU();
  156.     void moveUp();
  157.     void moveD();
  158.     void moveDp();
  159.     void moveF();
  160.     void moveFp();
  161.     void moveB();
  162.     void moveBp();
  163.     void moveM();
  164.     void movem();
  165.     void moveE();
  166.     void movee();
  167.     void moveS();
  168.     void moves();
  169.     void movex();
  170.     void movexp();
  171.     void movey();
  172.     void moveyp();
  173.     void movez();
  174.     void movezp();
  175.     int getFaceColor();
  176.     std::shared_ptr<Piece> getPiece(int ring, int i);
  177.     Sequence goTo(vectorOfPieces objective);
  178.     void test();
  179. };
  180.  
  181.  
  182.  
  183.  
  184.  
  185. // CONSTANTS
  186.  
  187. vectorOfPieces RUBIKS_CUBE_FINISHED = {
  188.     {
  189.         std::shared_ptr<Piece>(new Center(Colors::white)),
  190.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::white, Colors::red)),
  191.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::green)),
  192.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::white, Colors::orange)),
  193.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::orange)),
  194.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::white, Colors::orange)),
  195.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::blue)),
  196.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::white, Colors::red)),
  197.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::red))
  198.     },
  199.     {
  200.         std::shared_ptr<Piece>(new Edge(Colors::red, Colors::green)),
  201.         std::shared_ptr<Piece>(new Center(Colors::green)),
  202.         std::shared_ptr<Piece>(new Edge(Colors::orange, Colors::green)),
  203.         std::shared_ptr<Piece>(new Center(Colors::orange)),
  204.         std::shared_ptr<Piece>(new Edge(Colors::orange, Colors::blue)),
  205.         std::shared_ptr<Piece>(new Center(Colors::blue)),
  206.         std::shared_ptr<Piece>(new Edge(Colors::red, Colors::blue)),
  207.         std::shared_ptr<Piece>(new Center(Colors::red))
  208.     },
  209.     {
  210.         std::shared_ptr<Piece>(new Center(Colors::yellow)),
  211.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::yellow, Colors::red)),
  212.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::green)),
  213.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::yellow, Colors::orange)),
  214.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::orange)),
  215.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::yellow, Colors::orange)),
  216.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::blue)),
  217.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::yellow, Colors::red)),
  218.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::red))
  219.     }
  220. };
  221.  
  222.  
  223.  
  224.  
  225. std::ostream& Corner::getStream(std::ostream& stream) {
  226.     stream << "Corner(";
  227.     int color;
  228.     for (int i = 0; i < 3; i++) {
  229.         stream << "Colors::";
  230.         color = getColor(i);
  231.         switch (color) {
  232.             case Colors::white : stream << "white" ; break;
  233.             case Colors::yellow : stream << "yellow" ; break;
  234.             case Colors::red : stream << "red" ; break;
  235.             case Colors::green : stream << "green" ; break;
  236.             case Colors::orange : stream << "orange" ; break;
  237.             case Colors::blue : stream << "blue" ; break;
  238.         }
  239.         stream << ", ";
  240.     }
  241.     stream << ")";
  242.     return stream;
  243. }
  244.  
  245. std::ostream& Edge::getStream(std::ostream& stream) {
  246.     stream << "Edge(";
  247.     int color;
  248.     for (int i = 0; i < 2; i++) {
  249.         stream << "Colors::";
  250.         color = getColor(i);
  251.         switch (color) {
  252.             case Colors::white : stream << "white" ; break;
  253.             case Colors::yellow : stream << "yellow" ; break;
  254.             case Colors::red : stream << "red" ; break;
  255.             case Colors::green : stream << "green" ; break;
  256.             case Colors::orange : stream << "orange" ; break;
  257.             case Colors::blue : stream << "blue" ; break;
  258.         }
  259.         stream << ", ";
  260.     }
  261.     stream << ")";
  262.     return stream;
  263. }
  264.  
  265. std::ostream& Center::getStream(std::ostream& stream) {
  266.     stream << "Center(";
  267.     stream << "Colors::";
  268.     int color = getColor();
  269.     switch (color) {
  270.         case Colors::white : stream << "white" ; break;
  271.         case Colors::yellow : stream << "yellow" ; break;
  272.         case Colors::red : stream << "red" ; break;
  273.         case Colors::green : stream << "green" ; break;
  274.         case Colors::orange : stream << "orange" ; break;
  275.         case Colors::blue : stream << "blue" ; break;
  276.         default: stream << "oullalala la ya un pb la... color=" << color << std::endl;
  277.     }
  278.     stream << ", ";
  279.     stream << ")";
  280.     return stream;
  281. }
  282.  
  283. std::ostream& operator<<(std::ostream& sortie, std::shared_ptr<Piece> piece) {
  284.     return piece->getStream(sortie);
  285. }
  286.  
  287. std::ostream& operator<<(std::ostream& stream, RubiksCube cube) {
  288.     stream << "{" << std::endl;
  289.     stream << "\t{" << std::endl;
  290.     for (int i = 0; i < 9; i++) {
  291.         stream << "\t\t" << cube.getPiece(0, i) << "," << std::endl;
  292.     }
  293.     stream << "\t}," << std::endl;
  294.     stream << "\t{" << std::endl;
  295.     for (int i = 0; i < 8; i++) {
  296.         stream << "\t\t" << cube.getPiece(1, i) << "," << std::endl;
  297.     }
  298.     stream << "\t}," << std::endl;
  299.     stream << "\t{" << std::endl;
  300.     for (int i = 0; i < 9; i++) {
  301.         stream << "\t\t" << cube.getPiece(2, i) << "," << std::endl;
  302.     }
  303.     stream << "\t}" << std::endl;
  304.     stream << "}" << std::endl;
  305.     return stream;
  306. }
  307.  
  308. // WELL PLACED AND ORIENTED. TO GET ONLY WELL PLACED, USE !(piece1 != piece2)
  309. bool operator==(std::shared_ptr<Piece> piece1, std::shared_ptr<Piece> piece2) {
  310.     std::vector<int> piece1Colors = piece1->getAllColors();
  311.     std::vector<int> piece2Colors = piece2->getAllColors();
  312.     if (piece1Colors.size() != piece2Colors.size()) return false;
  313.     for (int i = 0; i < piece1Colors.size(); i++) {
  314.         if (piece1Colors[i] != piece2Colors[i]) return false;
  315.     } return true;
  316. }
  317.  
  318. bool operator!=(std::shared_ptr<Piece> piece1, std::shared_ptr<Piece> piece2) {
  319.     std::vector<int> piece1Colors = piece1->getAllColors();
  320.     std::vector<int> piece2Colors = piece2->getAllColors();
  321.     if (piece1Colors.size() != piece2Colors.size()) return true;
  322.     for (int i = 0; i < piece2Colors.size(); i++) {
  323.         if (std::find(piece1Colors.begin(), piece1Colors.end(), piece2Colors[i]) == piece1Colors.end()) {
  324.             return true;
  325.         }
  326.     } return false;
  327. }
  328.  
  329. int getStrongestColor(int color1, int color2) {
  330.     if (color1 == Colors::white || color1 == Colors::yellow) return color1;
  331.     if (color2 == Colors::white || color2 == Colors::yellow) return color2;
  332.     if (color1 == Colors::green || color1 == Colors::blue) return color2;
  333.     if (color2 == Colors::green || color2 == Colors::blue) return color1;
  334.     return color1;
  335. }
  336.  
  337. int getWeakestColor(int color1, int color2) {
  338.     return getStrongestColor(color1, color2) == color1 ? color2 : color1;
  339. }
  340.  
  341. Corner::Corner(int xColor, int yColor, int zColor) :
  342. m_xColor(xColor),
  343. m_yColor(yColor),
  344. m_zColor(zColor) {}
  345.  
  346. Edge::Edge(int color1, int color2) :
  347. m_color1(color1),
  348. m_color2(color2) {}
  349.  
  350. Center::Center(int color) :
  351. m_color(color) {}
  352.  
  353. std::shared_ptr<Piece> Corner::copy() {
  354.     return std::shared_ptr<Piece> (new Corner(m_xColor, m_yColor, m_zColor));
  355. }
  356.  
  357. std::shared_ptr<Piece> Edge::copy() {
  358.     return std::shared_ptr<Piece> (new Edge(m_color1, m_color2));
  359. }
  360.  
  361. std::shared_ptr<Piece> Center::copy() {
  362.     return std::shared_ptr<Piece> (new Center(m_color));
  363. }
  364.  
  365. int Corner::getColor(int color) {
  366.     switch (color) {
  367.         case 0: return m_xColor;
  368.         case 1: return m_yColor;
  369.         case 2: return m_zColor;
  370.     }
  371. }
  372.  
  373. int Edge::getColor(int color) {
  374.     switch (color) {
  375.         case 0: return m_color1;
  376.         case 1: return m_color2;
  377.     }
  378. }
  379.  
  380. int Center::getColor() {
  381.     return m_color;
  382. }
  383.  
  384. std::vector<int> Corner::getAllColors() {
  385.     std::vector<int> colors = {m_xColor, m_yColor, m_zColor};
  386.     return colors;
  387. }
  388.  
  389. std::vector<int> Edge::getAllColors() {
  390.     std::vector<int> colors = {m_color1, m_color2};
  391.     return colors;
  392. }
  393.  
  394. std::vector<int> Center::getAllColors() {
  395.     std::vector<int> colors = {m_color};
  396.     return colors;
  397. }
  398.  
  399. void Corner::rotate(int unchangedDirection) {
  400.     int directionsToChange[2];
  401.     if (unchangedDirection == Directions::x) {
  402.         int color = m_yColor;
  403.         m_yColor = m_zColor;
  404.         m_zColor = color;
  405.     }
  406.     if (unchangedDirection == Directions::y) {
  407.         int color = m_xColor;
  408.         m_xColor = m_zColor;
  409.         m_zColor = color;
  410.     }
  411.     if (unchangedDirection == Directions::z) {
  412.         int color = m_xColor;
  413.         m_xColor = m_yColor;
  414.         m_yColor = color;
  415.     }
  416.    
  417. }
  418.  
  419. void Edge::rotate() {
  420.     int color1 = m_color1;
  421.     m_color1 = m_color2;
  422.     m_color2 = color1;
  423. }
  424.  
  425. RubiksCube::RubiksCube(vectorOfPieces possibility) :
  426. m_possibility(possibility) {}
  427.  
  428. std::shared_ptr<Piece> RubiksCube::getPiece(int ring, int i) {
  429.     return m_possibility[ring][i];
  430. }
  431.  
  432. int RubiksCube::getFaceColor() {
  433.     return m_possibility[1][7]->getColor();
  434. }
  435.  
  436.  
  437. void RubiksCube::move(int corners[4][2], int edges[4][2], bool prime, bool doEdgesRotate, int cornerUnchangedDirection) {
  438.     std::vector<std::shared_ptr<Piece>> cornersVector = {
  439.         m_possibility[corners[0][0]][corners[0][1]],
  440.         m_possibility[corners[1][0]][corners[1][1]],
  441.         m_possibility[corners[2][0]][corners[2][1]],
  442.         m_possibility[corners[3][0]][corners[3][1]]
  443.     };
  444.     std::vector<std::shared_ptr<Piece>> edgesVector = {
  445.         m_possibility[edges[0][0]][edges[0][1]],
  446.         m_possibility[edges[1][0]][edges[1][1]],
  447.         m_possibility[edges[2][0]][edges[2][1]],
  448.         m_possibility[edges[3][0]][edges[3][1]]
  449.     };
  450.     if (!prime) {
  451.         m_possibility[corners[0][0]][corners[0][1]] = cornersVector[3];
  452.         m_possibility[corners[1][0]][corners[1][1]] = cornersVector[0];
  453.         m_possibility[corners[2][0]][corners[2][1]] = cornersVector[1];
  454.         m_possibility[corners[3][0]][corners[3][1]] = cornersVector[2];
  455.         m_possibility[edges[0][0]][edges[0][1]] = edgesVector[3];
  456.         m_possibility[edges[1][0]][edges[1][1]] = edgesVector[0];
  457.         m_possibility[edges[2][0]][edges[2][1]] = edgesVector[1];
  458.         m_possibility[edges[3][0]][edges[3][1]] = edgesVector[2];
  459.     } else {
  460.         m_possibility[corners[0][0]][corners[0][1]] = cornersVector[1];
  461.         m_possibility[corners[1][0]][corners[1][1]] = cornersVector[2];
  462.         m_possibility[corners[2][0]][corners[2][1]] = cornersVector[3];
  463.         m_possibility[corners[3][0]][corners[3][1]] = cornersVector[0];
  464.         m_possibility[edges[0][0]][edges[0][1]] = edgesVector[1];
  465.         m_possibility[edges[1][0]][edges[1][1]] = edgesVector[2];
  466.         m_possibility[edges[2][0]][edges[2][1]] = edgesVector[3];
  467.         m_possibility[edges[3][0]][edges[3][1]] = edgesVector[0];
  468.     }
  469.     if (doEdgesRotate) {
  470.         for (int i = 0; i < 4; i++) {
  471.             m_possibility[edges[i][0]][edges[i][1]]->rotate();
  472.         }
  473.     }
  474.     for (int i = 0; i < 4; i++) {
  475.         m_possibility[corners[i][0]][corners[i][1]]->rotate(cornerUnchangedDirection);
  476.     }
  477. }
  478.  
  479. void RubiksCube::moveInterior(int edges[4][2], int centers[4][2], bool prime) {
  480.     std::vector<std::shared_ptr<Piece>> edgesVector = {
  481.         m_possibility[edges[0][0]][edges[0][1]],
  482.         m_possibility[edges[1][0]][edges[1][1]],
  483.         m_possibility[edges[2][0]][edges[2][1]],
  484.         m_possibility[edges[3][0]][edges[3][1]]
  485.     };
  486.     std::vector<std::shared_ptr<Piece>> centersVector = {
  487.         m_possibility[centers[0][0]][centers[0][1]],
  488.         m_possibility[centers[1][0]][centers[1][1]],
  489.         m_possibility[centers[2][0]][centers[2][1]],
  490.         m_possibility[centers[3][0]][centers[3][1]]
  491.     };
  492.     if (!prime) {
  493.         m_possibility[edges[0][0]][edges[0][1]] = edgesVector[3];
  494.         m_possibility[edges[1][0]][edges[1][1]] = edgesVector[0];
  495.         m_possibility[edges[2][0]][edges[2][1]] = edgesVector[1];
  496.         m_possibility[edges[3][0]][edges[3][1]] = edgesVector[2];
  497.         m_possibility[centers[0][0]][centers[0][1]] = centersVector[3];
  498.         m_possibility[centers[1][0]][centers[1][1]] = centersVector[0];
  499.         m_possibility[centers[2][0]][centers[2][1]] = centersVector[1];
  500.         m_possibility[centers[3][0]][centers[3][1]] = centersVector[2];
  501.     } else {
  502.         m_possibility[edges[0][0]][edges[0][1]] = edgesVector[1];
  503.         m_possibility[edges[1][0]][edges[1][1]] = edgesVector[2];
  504.         m_possibility[edges[2][0]][edges[2][1]] = edgesVector[3];
  505.         m_possibility[edges[3][0]][edges[3][1]] = edgesVector[0];
  506.         m_possibility[centers[0][0]][centers[0][1]] = centersVector[1];
  507.         m_possibility[centers[1][0]][centers[1][1]] = centersVector[2];
  508.         m_possibility[centers[2][0]][centers[2][1]] = centersVector[3];
  509.         m_possibility[centers[3][0]][centers[3][1]] = centersVector[0];
  510.     }
  511.     for (int i = 2; i <= 8; i += 2) {
  512.         if (std::find(edgesVector.begin(), edgesVector.end(), m_possibility[0][i]) == edgesVector.end()) {
  513.             int strongestColor = getStrongestColor(m_possibility[0][0]->getColor(), m_possibility[1][i-1]->getColor());
  514.             if (strongestColor != m_possibility[0][i]->getColor(0)) {
  515.                 m_possibility[0][i]->rotate();
  516.             }
  517.         }
  518.     }
  519.     for (int i = 0; i <= 6; i += 2) {
  520.         if (std::find(edgesVector.begin(), edgesVector.end(), m_possibility[1][i]) == edgesVector.end()) {
  521.             int strongestColor = getStrongestColor(m_possibility[1][i+1]->getColor(), m_possibility[1][i == 0 ? 7 : i-1]->getColor());
  522.             if (strongestColor != m_possibility[1][i]->getColor(0)) {
  523.                 m_possibility[1][i]->rotate();
  524.             }
  525.         }
  526.     }
  527.     for (int i = 2; i <= 8; i += 2) {
  528.         if (std::find(edgesVector.begin(), edgesVector.end(), m_possibility[2][i]) == edgesVector.end()) {
  529.             int strongestColor = getStrongestColor(m_possibility[2][0]->getColor(), m_possibility[1][i-1]->getColor());
  530.             if (strongestColor != m_possibility[2][i]->getColor(0)) {
  531.                 m_possibility[2][i]->rotate();
  532.             }
  533.         }
  534.     }
  535. }
  536.  
  537. void RubiksCube::moveR() {
  538.     int corners[4][2] = {{0,7}, {0,5}, {2,5}, {2,7}};
  539.     int edges[4][2] = {{0,6}, {1,4}, {2,6}, {1,6}};
  540.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  541.     move(corners, edges, false, doEdgesRotate, Directions::x);
  542. }
  543.  
  544. void RubiksCube::moveRp() {
  545.     int corners[4][2] = {{0,7}, {0,5}, {2,5}, {2,7}};
  546.     int edges[4][2] = {{0,6}, {1,4}, {2,6}, {1,6}};
  547.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  548.     move(corners, edges, true, doEdgesRotate, Directions::x);
  549. }
  550.  
  551.  
  552. void RubiksCube::moveL() {
  553.     int corners[4][2] = {{0,3}, {0,1}, {2,1}, {2,3}};
  554.     int edges[4][2] = {{0,2}, {1,0}, {2,2}, {1,2}};
  555.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  556.     move(corners, edges, false, doEdgesRotate, Directions::x);
  557. }
  558.  
  559. void RubiksCube::moveLp() {
  560.     int corners[4][2] = {{0,3}, {0,1}, {2,1}, {2,3}};
  561.     int edges[4][2] = {{0,2}, {1,0}, {2,2}, {1,2}};
  562.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  563.     move(corners, edges, true, doEdgesRotate, Directions::x);
  564. }
  565.  
  566. void RubiksCube::moveU() {
  567.     int corners[4][2] = {{0,1}, {0,3}, {0,5}, {0,7}};
  568.     int edges[4][2] = {{0,2}, {0,4}, {0,6}, {0,8}};
  569.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  570.     move(corners, edges, false, doEdgesRotate, Directions::y);
  571. }
  572.  
  573. void RubiksCube::moveUp() {
  574.     int corners[4][2] = {{0,1}, {0,3}, {0,5}, {0,7}};
  575.     int edges[4][2] = {{0,2}, {0,4}, {0,6}, {0,8}};
  576.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  577.     move(corners, edges, true, doEdgesRotate, Directions::y);
  578. }
  579.  
  580. void RubiksCube::moveD() {
  581.     int corners[4][2] = {{2,7}, {2,5}, {2,3}, {2,1}};
  582.     int edges[4][2] = {{2,8}, {2,6}, {2,4}, {2,2}};
  583.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  584.     move(corners, edges, false, doEdgesRotate, Directions::y);
  585. }
  586.  
  587. void RubiksCube::moveDp() {
  588.     int corners[4][2] = {{2,7}, {2,5}, {2,3}, {2,1}};
  589.     int edges[4][2] = {{2,8}, {2,6}, {2,4}, {2,2}};
  590.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  591.     move(corners, edges, true, doEdgesRotate, Directions::y);
  592. }
  593.  
  594. void RubiksCube::moveF() {
  595.     int corners[4][2] = {{0,1}, {0,7}, {2,7}, {2,1}};
  596.     int edges[4][2] = {{0,8}, {1,6}, {2,8}, {1,0}};
  597.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::red;
  598.     move(corners, edges, false, doEdgesRotate, Directions::z);
  599. }
  600.  
  601. void RubiksCube::moveFp() {
  602.     int corners[4][2] = {{0,1}, {0,7}, {2,7}, {2,1}};
  603.     int edges[4][2] = {{0,8}, {1,6}, {2,8}, {1,0}};
  604.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::orange;
  605.     move(corners, edges, true, doEdgesRotate, Directions::z);
  606. }
  607.  
  608. void RubiksCube::moveB() {
  609.     int corners[4][2] = {{0,3}, {2,3}, {2,5}, {0,5}};
  610.     int edges[4][2] = {{0,4}, {1,2}, {2,4}, {1,4}};
  611.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::orange;
  612.     move(corners, edges, false, doEdgesRotate, Directions::z);
  613. }
  614.  
  615. void RubiksCube::moveBp() {
  616.     int corners[4][2] = {{0,3}, {2,3}, {2,5}, {0,5}};
  617.     int edges[4][2] = {{0,4}, {1,2}, {2,4}, {1,4}};
  618.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::orange;
  619.     move(corners, edges, true, doEdgesRotate, Directions::z);
  620. }
  621.  
  622. void RubiksCube::moveM() {
  623.     int edges[4][2] = {{0,8}, {2,8}, {2,4}, {0,4}};
  624.     int centers[4][2] = {{0,0}, {1,7}, {2,0}, {1,3}};
  625.     moveInterior(edges, centers, false);
  626. }
  627.  
  628. void RubiksCube::movem() {
  629.     int edges[4][2] = {{0,8}, {2,8}, {2,4}, {0,4}};
  630.     int centers[4][2] = {{0,0}, {1,7}, {2,0}, {1,3}};
  631.     moveInterior(edges, centers, true);
  632. }
  633.  
  634. void RubiksCube::moveE() {
  635.     int edges[4][2] = {{1,0}, {1,2}, {1,4}, {1,6}};
  636.     int centers[4][2] = {{1,7}, {1,1}, {1,3}, {1,5}};
  637.     moveInterior(edges, centers, false);
  638. }
  639.  
  640. void RubiksCube::movee() {
  641.     int edges[4][2] = {{1,0}, {1,2}, {1,4}, {1,6}};
  642.     int centers[4][2] = {{1,7}, {1,1}, {1,3}, {1,5}};
  643.     moveInterior(edges, centers, true);
  644. }
  645.  
  646. void RubiksCube::moveS() {
  647.     int edges[4][2] = {{0,6}, {2,6}, {2,2}, {0,2}};
  648.     int centers[4][2] = {{0,0}, {1,5}, {2,0}, {1,1}};
  649.     moveInterior(edges, centers, false);
  650. }
  651.  
  652. void RubiksCube::moves() {
  653.     int edges[4][2] = {{0,6}, {2,6}, {2,2}, {0,2}};
  654.     int centers[4][2] = {{0,0}, {1,5}, {2,0}, {1,1}};
  655.     moveInterior(edges, centers, true);
  656. }
  657.  
  658. void RubiksCube::movex() {
  659.     moveR();
  660.     movem();
  661.     moveLp();
  662. }
  663.  
  664. void RubiksCube::movexp() {
  665.     moveRp();
  666.     moveM();
  667.     moveL();
  668. }
  669.  
  670. void RubiksCube::movey() {
  671.     moveU();
  672.     moveE();
  673.     moveDp();
  674. }
  675.  
  676. void RubiksCube::moveyp() {
  677.     moveUp();
  678.     movee();
  679.     moveD();
  680. }
  681.  
  682. void RubiksCube::movez() {
  683.     moveF();
  684.     moveS();
  685.     moveBp();
  686. }
  687.  
  688.  
  689. void RubiksCube::movezp() {
  690.     moveFp();
  691.     moveS();
  692.     moveB();
  693. }
  694.  
  695. void RubiksCube::silentMovex() {
  696.     moveR();
  697.     movem();
  698.     moveLp();
  699. }
  700.  
  701. void RubiksCube::silentMovexp() {
  702.     moveRp();
  703.     moveM();
  704.     moveL();
  705. }
  706.  
  707. void RubiksCube::silentMovey() {
  708.     moveU();
  709.     moveE();
  710.     moveDp();
  711. }
  712.  
  713. void RubiksCube::silentMoveyp() {
  714.     moveUp();
  715.     movee();
  716.     moveD();
  717. }
  718.  
  719. void RubiksCube::silentMovez() {
  720.     moveF();
  721.     moveS();
  722.     moveBp();
  723. }
  724.  
  725. void RubiksCube::silentMovezp() {
  726.     moveFp();
  727.     moveS();
  728.     moveB();
  729. }
  730.  
  731. RubiksCube RubiksCube::askForCube() {
  732.     int faces[6][9];
  733.     std::cout << "Les couleurs"
  734.     << std::endl << "\t- Blanc : 0"
  735.     << std::endl << "\t- Jaune : 1"
  736.     << std::endl << "\t- Rouge : 2"
  737.     << std::endl << "\t- Vert : 3"
  738.     << std::endl << "\t- Orange : 4"
  739.     << std::endl << "\t- Bleu : 5" << std::endl;
  740.     std::string facesNames[6] = {"blanche", "jaune", "rouge", "verte", "orange", "bleue"};
  741.     for (int face = 0; face < 6; face++) {
  742.         std::cout << "Entrez la face " << facesNames[face] << " : (centre en premier)" << std::endl;
  743.         for (int i = 0; i < 9; i++) {
  744.             std::cout << "\t> ";
  745.             std::cin >> faces[face][i];
  746.         }
  747.     }
  748.     vectorOfPieces possibility = {
  749.         {
  750.             std::shared_ptr<Piece>(new Center(faces[0][0])),
  751.             std::shared_ptr<Piece>(new Corner(faces[3][5], faces[0][1], faces[2][3])),
  752.             std::shared_ptr<Piece>(new Edge(faces[0][2], faces[3][4])),
  753.             std::shared_ptr<Piece>(new Corner(faces[3][3], faces[0][3], faces[4][5])),
  754.             std::shared_ptr<Piece>(new Edge(faces[0][4], faces[4][4])),
  755.             std::shared_ptr<Piece>(new Corner(faces[5][5], faces[0][5], faces[4][3])),
  756.             std::shared_ptr<Piece>(new Edge(faces[0][6], faces[5][4])),
  757.             std::shared_ptr<Piece>(new Corner(faces[5][3], faces[0][7], faces[2][5])),
  758.             std::shared_ptr<Piece>(new Edge(faces[0][8], faces[2][4])),
  759.         },
  760.         {
  761.             std::shared_ptr<Piece>(new Edge(faces[2][2], faces[3][6])),
  762.             std::shared_ptr<Piece>(new Center(faces[3][0])),
  763.             std::shared_ptr<Piece>(new Edge(faces[4][6], faces[3][2])),
  764.             std::shared_ptr<Piece>(new Center(faces[4][0])),
  765.             std::shared_ptr<Piece>(new Edge(faces[4][2], faces[5][6])),
  766.             std::shared_ptr<Piece>(new Center(faces[5][0])),
  767.             std::shared_ptr<Piece>(new Edge(faces[2][6], faces[5][2])),
  768.             std::shared_ptr<Piece>(new Center(faces[2][0])),
  769.         },
  770.         {
  771.             std::shared_ptr<Piece>(new Center(faces[1][0])),
  772.             std::shared_ptr<Piece>(new Corner(faces[3][7], faces[1][3], faces[2][1])),
  773.             std::shared_ptr<Piece>(new Edge(faces[1][2], faces[3][8])),
  774.             std::shared_ptr<Piece>(new Corner(faces[3][1], faces[1][1], faces[4][7])),
  775.             std::shared_ptr<Piece>(new Edge(faces[1][8], faces[4][8])),
  776.             std::shared_ptr<Piece>(new Corner(faces[5][7], faces[1][7], faces[4][1])),
  777.             std::shared_ptr<Piece>(new Edge(faces[1][6], faces[5][8])),
  778.             std::shared_ptr<Piece>(new Corner(faces[5][1], faces[1][5], faces[2][7])),
  779.             std::shared_ptr<Piece>(new Edge(faces[1][4], faces[2][8])),
  780.         }
  781.     };
  782.     RubiksCube cube(possibility);
  783.     return cube;
  784. }
  785.  
  786. RubiksCube RubiksCube::makeRandomCube(vectorOfPieces possibility, int seed) {
  787.     for (int i = 0; i < 9; i++) {
  788.         possibility[0][i] = possibility[0][i]->copy();
  789.     }
  790.     for (int i = 0; i < 8; i++) {
  791.         possibility[1][i] = possibility[1][i]->copy();
  792.     }
  793.     for (int i = 0; i < 9; i++) {
  794.         possibility[2][i] = possibility[2][i]->copy();
  795.     }
  796.     srand(seed);
  797.     RubiksCube cube(possibility);
  798.     for (int i = 0; i < 100; i++) {
  799.         switch(rand() % 11) {
  800.             case Movements::R: cube.moveR();break;
  801.             case Movements::Rp: cube.moveRp();break;
  802.             case Movements::L: cube.moveL();break;
  803.             case Movements::Lp: cube.moveLp();break;
  804.             case Movements::U: cube.moveU();break;
  805.             case Movements::Up: cube.moveUp();break;
  806.             case Movements::D: cube.moveD();break;
  807.             case Movements::Dp: cube.moveDp();break;
  808.             case Movements::F: cube.moveF();break;
  809.             case Movements::Fp: cube.moveFp();break;
  810.             case Movements::B: cube.moveB();break;
  811.             case Movements::Bp: cube.moveBp();break;
  812.         }
  813.     } return cube;
  814. }
  815.  
  816. RubiksCube RubiksCube::makeRandomCube(vectorOfPieces possibility) {
  817.     return makeRandomCube(possibility, time(NULL));
  818. }
  819.  
  820. RubiksCube RubiksCube::makeRandomCube() {
  821.     return makeRandomCube(RUBIKS_CUBE_FINISHED, time(NULL));
  822. }
  823.  
  824. std::vector<int> RubiksCube::findPlaceOfPiece(std::shared_ptr<Piece> piece, vectorOfPieces possibility) {
  825.     for (int i = 0; i < 9; i++) {
  826.         if (!(possibility[0][i] != piece)) return std::vector<int> {0, i};
  827.     }
  828.     for (int i = 0; i < 8; i++) {
  829.         if (!(possibility[1][i] != piece)) return std::vector<int> {1, i};
  830.     }
  831.     for (int i = 0; i < 9; i++) {
  832.         if (!(possibility[2][i] != piece)) return std::vector<int> {2, i};
  833.     }
  834.     std::cout << "ERROR : Piece not found " << piece << std::endl;
  835.     return std::vector<int> {-1, -1};
  836. }
  837.  
  838. bool RubiksCube::isPieceWellPlaced(vectorOfPieces objective, std::shared_ptr<Piece> piece) {
  839.     std::vector<int> movements;
  840.     if (m_possibility[1][1]->getColor() == Colors::white || m_possibility[1][5]->getColor() == Colors::white) {
  841.         silentMovez();
  842.         movements.push_back(Directions::z);
  843.     }
  844.     while (m_possibility[0][0]->getColor() != Colors::white) {
  845.         silentMovex();
  846.         movements.push_back(Directions::x);
  847.     }
  848.     while (m_possibility[1][7]->getColor() != Colors::red) {
  849.         silentMovey();
  850.         movements.push_back(Directions::y);
  851.     }
  852.     std::vector<int> placeOnObjective = findPlaceOfPiece(piece, objective);
  853.     std::vector<int> placeOnPossibility =  findPlaceOfPiece(piece, m_possibility);
  854.     bool response = placeOnObjective == placeOnPossibility && objective[placeOnObjective[0]][placeOnObjective[1]] == m_possibility[placeOnPossibility[0]][placeOnPossibility[1]];
  855.     for (int i = movements.size() - 1; i >= 0; i--) {
  856.         switch (movements[i]) {
  857.             case Directions::x: silentMovexp();break;
  858.             case Directions::y: silentMoveyp();break;
  859.             case Directions::z: silentMovezp();break;
  860.         }
  861.     }
  862.     return response;
  863. }
  864.  
  865. Sequence RubiksCube::goTo(vectorOfPieces objective) {
  866.     solveFirstCross(objective);
  867.     finishFirstFace(objective);
  868.     solveSecondLayer(objective);
  869.     Sequence s;
  870.     return s;
  871. }
  872.  
  873. void RubiksCube::solveFirstCross(vectorOfPieces objective) {
  874.     std::vector<std::shared_ptr<Piece>> edges = {
  875.         objective[0][2],
  876.         objective[0][4],
  877.         objective[0][6],
  878.         objective[0][8]
  879.     };
  880.     for (int i = 0; i < 4; i++) {
  881.         moveyp();
  882.         if (!isPieceWellPlaced(objective, edges[i])) {
  883.             putEdgeDown(edges[i]);
  884.             placeEdge(objective, edges[i]);
  885.         }
  886.     }
  887. }
  888.  
  889. void RubiksCube::putEdgeDown(std::shared_ptr<Piece> edge) {
  890.     std::vector<int> pos = findPlaceOfPiece(edge, m_possibility);
  891.     for (int i = 0; i < pos[1] / 2; i++) {
  892.         moveyp();
  893.     }
  894.     if (pos[0] == 0) {
  895.         moveM();
  896.         moveDp();
  897.         movem();
  898.         moveD();
  899.     } else if (pos[0] == 1) {
  900.         moveL();
  901.         moveD();
  902.         moveLp();
  903.     }
  904.     for (int i = 0; i < pos[1] / 2; i++) {
  905.         movey();
  906.         moveD();
  907.     }
  908. }
  909.  
  910. void RubiksCube::placeEdge(vectorOfPieces objective, std::shared_ptr<Piece> edge) {
  911.     if (m_possibility[2][8]->getColor(1) == objective[0][findPlaceOfPiece(edge, objective)[1]]->getColor(0)) {   // GOOD ORIENTATION
  912.         moveDp();
  913.         moveM();
  914.         moveD();
  915.         movem();
  916.     } else {    // BAD ORIENTATION
  917.         moveM();
  918.         moveD();
  919.         moveD();
  920.         movem();
  921.     }
  922. }
  923.  
  924.  
  925. void RubiksCube::finishFirstFace(vectorOfPieces objective) {
  926.     std::vector<std::shared_ptr<Piece>> corners = {
  927.         objective[0][1],
  928.         objective[0][3],
  929.         objective[0][5],
  930.         objective[0][7]
  931.     };
  932.     for (int i = 0; i < 4; i++) {
  933.         moveyp();
  934.         if (!isPieceWellPlaced(objective, corners[i])) {
  935.             putCornerDown(corners[i]);
  936.             placeCorner(objective, corners[i]);
  937.         }
  938.     }
  939. }
  940.  
  941. void RubiksCube::putCornerDown(std::shared_ptr<Piece> corner) {
  942.     std::vector<int> pos = findPlaceOfPiece(corner, m_possibility);
  943.     for (int i = 0; i < (pos[1] + 1) / 2; i++) {
  944.         moveyp();
  945.     }
  946.     if (pos[0] == 0) {
  947.         moveRp();
  948.         moveDp();
  949.         moveR();
  950.         moveD();
  951.     }
  952.     for (int i = 0; i < (pos[1] + 1) / 2; i++) {
  953.         movey();
  954.         moveD();
  955.     }
  956. }
  957.  
  958.  
  959.  
  960.  
  961. void RubiksCube::placeCorner(vectorOfPieces objective, std::shared_ptr<Piece> corner) {
  962.     int color = objective[0][findPlaceOfPiece(corner, objective)[1]]->getColor(1);      // COLOR OF WHITE FACE
  963.     //std::cout << objective << std::endl;
  964.     //std::cout << color << findPlaceOfPiece(corner, objective)[0] << findPlaceOfPiece(corner, objective)[1];
  965.     //std::cout << m_possibility[2][7] << std::endl;
  966.     if (m_possibility[2][7]->getColor(0) == color) {
  967.         moveRp();
  968.         moveDp();
  969.         moveR();
  970.     } else if (m_possibility[2][7]->getColor(1) == color) {
  971.         moveRp();
  972.         moveD();
  973.         moveD();
  974.         moveR();
  975.         moveD();
  976.         moveRp();
  977.         moveDp();
  978.         moveR();
  979.     } else if (m_possibility[2][7]->getColor(2) == color) {
  980.         moveDp();
  981.         moveRp();
  982.         moveD();
  983.         moveR();
  984.     }
  985. }
  986.  
  987. void RubiksCube::solveSecondLayer(vectorOfPieces objective) {
  988.     std::vector<std::shared_ptr<Piece>> edges = {
  989.         objective[1][0],
  990.         objective[1][2],
  991.         objective[1][4],
  992.         objective[1][6]
  993.     };
  994.     for (int i = 0; i < 4; i++) {
  995.         //std::cout << "apres le move" << *this;
  996.         moveyp();
  997.         //std::cout << "avant le move" << *this;
  998.         //std::cout << edges[i] << isPieceWellPlaced(objective, edges[i]) << std::endl;
  999.         if (!isPieceWellPlaced(objective, edges[i])) {
  1000.             put2ndLayerEdgeDown(edges[i]);
  1001.             //std::cout << *this;
  1002.             place2ndLayerEdgeDown(objective, edges[i]);
  1003.         }
  1004.     }
  1005. }
  1006.  
  1007. void RubiksCube::put2ndLayerEdgeDown(std::shared_ptr<Piece> edge) {
  1008.     std::vector<int> pos = findPlaceOfPiece(edge, m_possibility);
  1009.     for (int i = 0; i < (pos[1] + (pos[0] == 1 ? 2 : 0)) / 2; i++) {
  1010.         moveyp();
  1011.     }
  1012.     if (pos[0] == 1) {
  1013.         moveRp();
  1014.         moveD();
  1015.         moveR();
  1016.         moveD();
  1017.         moveF();
  1018.         moveDp();
  1019.         moveFp();
  1020.     }
  1021.     for (int i = 0; i < (pos[1] + (pos[0] == 1 ? 2 : 0)) / 2; i++) {
  1022.         movey();
  1023.         moveD();
  1024.     }
  1025.     //std::cout << *this << std::endl;
  1026. }
  1027.  
  1028. void RubiksCube::place2ndLayerEdgeDown(vectorOfPieces objective, std::shared_ptr<Piece> edge) {
  1029.     std::vector<int> colors = objective[1][findPlaceOfPiece(edge, objective)[1]]->getAllColors();      // COLORS OF EDGE
  1030.     int centerColor = m_possibility[1][7]->getColor();      // FRONT FACE COLOR
  1031.     std::cout << edge << *this << std::endl;
  1032.     if (m_possibility[2][8]->getColor(1) == colors[centerColor == Colors::red || centerColor == Colors::orange ? 0 : 1]) {
  1033.         std::cout << "number 1" << std::endl;
  1034.         moveDp();
  1035.         moveRp();
  1036.         moveD();
  1037.         moveR();
  1038.         moveD();
  1039.         moveF();
  1040.         moveDp();
  1041.         moveFp();
  1042.     } else {
  1043.         std::cout << "number 2" << std::endl;
  1044.         movey();
  1045.         moveD();
  1046.         moveD();
  1047.         moveL();
  1048.         moveDp();
  1049.         moveLp();
  1050.         moveDp();
  1051.         moveFp();
  1052.         moveD();
  1053.         moveF();
  1054.         moveyp();
  1055.     }
  1056. }
  1057.  
  1058. void RubiksCube::test() {
  1059.     std::cout << m_possibility.size() << m_possibility[0].size() << m_possibility[1].size() << m_possibility[2].size();
  1060. }
  1061.  
  1062. void getStats(bool debug) {
  1063.     std::vector<std::vector<int>> TO_VERIFY {
  1064.         {0, 0},
  1065.         {0, 1},
  1066.         {0, 2},
  1067.         {0, 3},
  1068.         {0, 4},
  1069.         {0, 5},
  1070.         {0, 6},
  1071.         {0, 7},
  1072.         {0, 8},
  1073.         {1, 0},
  1074.         {1, 1},
  1075.         {1, 2},
  1076.         {1, 3},
  1077.         {1, 4},
  1078.         {1, 5},
  1079.         {1, 6},
  1080.         {1, 7},
  1081.     };
  1082.     srand(time(NULL));
  1083.     int rights = 0;
  1084.     int tests = 1000;
  1085.     double startTime = time(NULL);
  1086.     for (int i = 0; i < tests; i++) {
  1087.         int seed = rand();
  1088.         RubiksCube cube = RubiksCube::makeRandomCube(RUBIKS_CUBE_FINISHED, seed);
  1089.         cube.goTo(RUBIKS_CUBE_FINISHED);
  1090.         bool error = false;
  1091.         for (int j = 0; j < TO_VERIFY.size(); j++) {
  1092.             if (!(cube.getPiece(TO_VERIFY[j][0], TO_VERIFY[j][1]) == RUBIKS_CUBE_FINISHED[TO_VERIFY[j][0]][TO_VERIFY[j][1]])) {
  1093.                 error = true;
  1094.             }
  1095.         }
  1096.         if (!error) {
  1097.             rights += 1;
  1098.         } else if (debug) {
  1099.             std::cout << "FAILURE WITH SEED : " << seed << std::endl;
  1100.         }
  1101.         if (tests / 100 != 0 && i % (tests/100) == 0) {
  1102.             std::cout << i / (tests/100) << "% made" << std::endl;
  1103.         }
  1104.         //std::cout << cube;
  1105.     }
  1106.     double endTime = time(NULL);
  1107.     std::cout << std::endl << std::endl;
  1108.     std::cout << "\t- Number of tests : " << tests << std::endl;
  1109.     std::cout << "\t- " << (((double)rights)/tests) * 100 << "% tests successfull (" << tests - rights << " failed)" << std::endl;
  1110.     std::cout << "\t- Execution time : " << endTime - startTime << "s" << std::endl;
  1111.     std::cout << "\t- " << (endTime - startTime) / tests << " s/test" << std::endl;
  1112.     std::cout << "\t- " << tests / (endTime - startTime) << " tests/s" << std::endl;
  1113. }
  1114.  
  1115.  
  1116.  
  1117.  
  1118. vectorOfPieces TEST_RUBIKS_CUBE = {
  1119.     {
  1120.         std::shared_ptr<Piece>(new Center(Colors::white)),
  1121.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::white, Colors::red)),
  1122.         std::shared_ptr<Piece>(new Edge(Colors::green, Colors::white)),
  1123.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::white, Colors::orange)),
  1124.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::orange)),
  1125.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::white, Colors::orange)),
  1126.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::blue)),
  1127.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::white, Colors::red)),
  1128.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::orange))
  1129.     },
  1130.     {
  1131.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::green)),
  1132.         std::shared_ptr<Piece>(new Center(Colors::green)),
  1133.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::blue)),
  1134.         std::shared_ptr<Piece>(new Center(Colors::orange)),
  1135.         std::shared_ptr<Piece>(new Edge(Colors::orange, Colors::blue)),
  1136.         std::shared_ptr<Piece>(new Center(Colors::blue)),
  1137.         std::shared_ptr<Piece>(new Edge(Colors::blue, Colors::red)),
  1138.         std::shared_ptr<Piece>(new Center(Colors::red))
  1139.     },
  1140.     {
  1141.         std::shared_ptr<Piece>(new Center(Colors::yellow)),
  1142.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::yellow, Colors::red)),
  1143.         std::shared_ptr<Piece>(new Edge(Colors::orange, Colors::green)),
  1144.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::yellow, Colors::orange)),
  1145.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::red)),
  1146.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::yellow, Colors::orange)),
  1147.         std::shared_ptr<Piece>(new Edge(Colors::red, Colors::green)),
  1148.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::yellow, Colors::red)),
  1149.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::red))
  1150.     }
  1151. };
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157. int main() {
  1158.     //RubiksCube cube = RubiksCube::makeRandomCube(RUBIKS_CUBE_FINISHED, 667522242);
  1159.     //std::cout << cube << std::endl;
  1160.     RubiksCube cube(TEST_RUBIKS_CUBE);
  1161.     //cube.moveM();
  1162.     //cube.moveD();
  1163.     cube.goTo(RUBIKS_CUBE_FINISHED);
  1164.     std::cout << cube;
  1165.     //getStats(true);
  1166.     return 0;
  1167. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top