SHARE
TWEET

full beugué

a guest Jan 22nd, 2020 66 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.     struct CentersNearEdges {
  481.         std::vector<int> edgePosition;
  482.         std::vector<int> weakestColorPosition;
  483.         int strongestColor;
  484.     };
  485.     std::vector<std::shared_ptr<Piece>> edgesVector = {
  486.         m_possibility[edges[0][0]][edges[0][1]],
  487.         m_possibility[edges[1][0]][edges[1][1]],
  488.         m_possibility[edges[2][0]][edges[2][1]],
  489.         m_possibility[edges[3][0]][edges[3][1]]
  490.     };
  491.     std::vector<std::shared_ptr<Piece>> centersVector = {
  492.         m_possibility[centers[0][0]][centers[0][1]],
  493.         m_possibility[centers[1][0]][centers[1][1]],
  494.         m_possibility[centers[2][0]][centers[2][1]],
  495.         m_possibility[centers[3][0]][centers[3][1]]
  496.     };
  497.     for (int i = 0; i < 4; i++) {
  498.         std::cout << edgesVector[i] << std::endl;
  499.     }
  500.     std::vector<CentersNearEdges> allEdges;
  501.     for (int i = 2; i <= 8; i += 2) {
  502.         if (std::find(edgesVector.begin(), edgesVector.end(), m_possibility[0][i]) == edgesVector.end()) {
  503.             CentersNearEdges centersNearEdges;
  504.             centersNearEdges.edgePosition = {0, i};
  505.             centersNearEdges.strongestColor = getStrongestColor(m_possibility[0][0]->getColor(), m_possibility[1][i-1]->getColor());
  506.             int weakestColor = getWeakestColor(m_possibility[0][0]->getColor(), m_possibility[1][i-1]->getColor());
  507.             centersNearEdges.weakestColorPosition = weakestColor == m_possibility[0][0]->getColor() ? std::vector<int>{0,0} : std::vector<int>{1,i-1};
  508.             allEdges.push_back(centersNearEdges);
  509.         }
  510.     }
  511.     for (int i = 0; i <= 6; i += 2) {
  512.         if (std::find(edgesVector.begin(), edgesVector.end(), m_possibility[1][i]) == edgesVector.end()) {
  513.             CentersNearEdges centersNearEdges;
  514.             centersNearEdges.edgePosition = {1, i};
  515.             centersNearEdges.strongestColor = getStrongestColor(m_possibility[1][i+1]->getColor(), m_possibility[1][i == 0 ? 7 : i-1]->getColor());
  516.             int weakestColor = getWeakestColor(m_possibility[1][i+1]->getColor(), m_possibility[1][i == 0 ? 7 : i-1]->getColor());
  517.             centersNearEdges.weakestColorPosition = weakestColor == m_possibility[1][i+1]->getColor() ? std::vector<int>{1,i+1} : std::vector<int>{1,i == 0 ? 7 : i-1};
  518.             allEdges.push_back(centersNearEdges);
  519.         }
  520.     }
  521.     for (int i = 2; i <= 8; i += 2) {
  522.         if (std::find(edgesVector.begin(), edgesVector.end(), m_possibility[2][i]) == edgesVector.end()) {
  523.             CentersNearEdges centersNearEdges;
  524.             centersNearEdges.edgePosition = {1, i};
  525.             centersNearEdges.strongestColor = getStrongestColor(m_possibility[2][0]->getColor(), m_possibility[1][i-1]->getColor());
  526.             int weakestColor = getWeakestColor(m_possibility[2][0]->getColor(), m_possibility[1][i-1]->getColor());
  527.             centersNearEdges.weakestColorPosition = weakestColor == m_possibility[2][0]->getColor() ? std::vector<int>{2,0} : std::vector<int>{1,i-1};
  528.             allEdges.push_back(centersNearEdges);
  529.         }
  530.     }
  531.     if (!prime) {
  532.         m_possibility[edges[0][0]][edges[0][1]] = edgesVector[3];
  533.         m_possibility[edges[1][0]][edges[1][1]] = edgesVector[0];
  534.         m_possibility[edges[2][0]][edges[2][1]] = edgesVector[1];
  535.         m_possibility[edges[3][0]][edges[3][1]] = edgesVector[2];
  536.         m_possibility[centers[0][0]][centers[0][1]] = centersVector[3];
  537.         m_possibility[centers[1][0]][centers[1][1]] = centersVector[0];
  538.         m_possibility[centers[2][0]][centers[2][1]] = centersVector[1];
  539.         m_possibility[centers[3][0]][centers[3][1]] = centersVector[2];
  540.     } else {
  541.         m_possibility[edges[0][0]][edges[0][1]] = edgesVector[1];
  542.         m_possibility[edges[1][0]][edges[1][1]] = edgesVector[2];
  543.         m_possibility[edges[2][0]][edges[2][1]] = edgesVector[3];
  544.         m_possibility[edges[3][0]][edges[3][1]] = edgesVector[0];
  545.         m_possibility[centers[0][0]][centers[0][1]] = centersVector[1];
  546.         m_possibility[centers[1][0]][centers[1][1]] = centersVector[2];
  547.         m_possibility[centers[2][0]][centers[2][1]] = centersVector[3];
  548.         m_possibility[centers[3][0]][centers[3][1]] = centersVector[0];
  549.     }
  550.     std::cout << "juste apres la rotation : " << *this;
  551.     std::vector<CentersNearEdges>::iterator it;
  552.     for (it = allEdges.begin(); it != allEdges.end(); it++) {
  553.         int weakestColor = getWeakestColor(it->strongestColor, m_possibility[it->weakestColorPosition[0]][it->weakestColorPosition[1]]->getColor());
  554.         if (weakestColor == it->strongestColor) {
  555.             m_possibility[it->edgePosition[0]][it->edgePosition[1]]->rotate();
  556.         }
  557.     }
  558. }
  559.  
  560. void RubiksCube::moveR() {
  561.     int corners[4][2] = {{0,7}, {0,5}, {2,5}, {2,7}};
  562.     int edges[4][2] = {{0,6}, {1,4}, {2,6}, {1,6}};
  563.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  564.     move(corners, edges, false, doEdgesRotate, Directions::x);
  565. }
  566.  
  567. void RubiksCube::moveRp() {
  568.     int corners[4][2] = {{0,7}, {0,5}, {2,5}, {2,7}};
  569.     int edges[4][2] = {{0,6}, {1,4}, {2,6}, {1,6}};
  570.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  571.     move(corners, edges, true, doEdgesRotate, Directions::x);
  572. }
  573.  
  574.  
  575. void RubiksCube::moveL() {
  576.     int corners[4][2] = {{0,3}, {0,1}, {2,1}, {2,3}};
  577.     int edges[4][2] = {{0,2}, {1,0}, {2,2}, {1,2}};
  578.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  579.     move(corners, edges, false, doEdgesRotate, Directions::x);
  580. }
  581.  
  582. void RubiksCube::moveLp() {
  583.     int corners[4][2] = {{0,3}, {0,1}, {2,1}, {2,3}};
  584.     int edges[4][2] = {{0,2}, {1,0}, {2,2}, {1,2}};
  585.     int doEdgesRotate = getFaceColor() == Colors::blue || getFaceColor() == Colors::green;
  586.     move(corners, edges, true, doEdgesRotate, Directions::x);
  587. }
  588.  
  589. void RubiksCube::moveU() {
  590.     int corners[4][2] = {{0,1}, {0,3}, {0,5}, {0,7}};
  591.     int edges[4][2] = {{0,2}, {0,4}, {0,6}, {0,8}};
  592.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  593.     move(corners, edges, false, doEdgesRotate, Directions::y);
  594. }
  595.  
  596. void RubiksCube::moveUp() {
  597.     int corners[4][2] = {{0,1}, {0,3}, {0,5}, {0,7}};
  598.     int edges[4][2] = {{0,2}, {0,4}, {0,6}, {0,8}};
  599.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  600.     move(corners, edges, true, false, Directions::y);
  601. }
  602.  
  603. void RubiksCube::moveD() {
  604.     int corners[4][2] = {{2,7}, {2,5}, {2,3}, {2,1}};
  605.     int edges[4][2] = {{2,8}, {2,6}, {2,4}, {2,2}};
  606.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  607.     move(corners, edges, false, false, Directions::y);
  608. }
  609.  
  610. void RubiksCube::moveDp() {
  611.     int corners[4][2] = {{2,7}, {2,5}, {2,3}, {2,1}};
  612.     int edges[4][2] = {{2,8}, {2,6}, {2,4}, {2,2}};
  613.     int doEdgesRotate = getFaceColor() == Colors::white || getFaceColor() == Colors::yellow;
  614.     move(corners, edges, true, false, Directions::y);
  615. }
  616.  
  617. void RubiksCube::moveF() {
  618.     int corners[4][2] = {{0,1}, {0,7}, {2,7}, {2,1}};
  619.     int edges[4][2] = {{0,8}, {1,6}, {2,8}, {1,0}};
  620.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::red;
  621.     move(corners, edges, false, doEdgesRotate, Directions::z);
  622. }
  623.  
  624. void RubiksCube::moveFp() {
  625.     int corners[4][2] = {{0,1}, {0,7}, {2,7}, {2,1}};
  626.     int edges[4][2] = {{0,8}, {1,6}, {2,8}, {1,0}};
  627.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::orange;
  628.     move(corners, edges, true, doEdgesRotate, Directions::z);
  629. }
  630.  
  631. void RubiksCube::moveB() {
  632.     int corners[4][2] = {{0,3}, {2,3}, {2,5}, {0,5}};
  633.     int edges[4][2] = {{0,4}, {1,2}, {2,4}, {1,4}};
  634.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::orange;
  635.     move(corners, edges, false, doEdgesRotate, Directions::z);
  636. }
  637.  
  638. void RubiksCube::moveBp() {
  639.     int corners[4][2] = {{0,3}, {2,3}, {2,5}, {0,5}};
  640.     int edges[4][2] = {{0,4}, {1,2}, {2,4}, {1,4}};
  641.     int doEdgesRotate = getFaceColor() == Colors::red || getFaceColor() == Colors::orange;
  642.     move(corners, edges, true, doEdgesRotate, Directions::z);
  643. }
  644.  
  645. void RubiksCube::moveM() {
  646.     int edges[4][2] = {{0,8}, {2,8}, {2,4}, {0,4}};
  647.     int centers[4][2] = {{0,0}, {1,7}, {2,0}, {1,3}};
  648.     moveInterior(edges, centers, false);
  649. }
  650.  
  651. void RubiksCube::movem() {
  652.     int edges[4][2] = {{0,8}, {2,8}, {2,4}, {0,4}};
  653.     int centers[4][2] = {{0,0}, {1,7}, {2,0}, {1,3}};
  654.     moveInterior(edges, centers, true);
  655. }
  656.  
  657. void RubiksCube::moveE() {
  658.     int edges[4][2] = {{1,0}, {1,2}, {1,4}, {1,6}};
  659.     int centers[4][2] = {{1,7}, {1,1}, {1,3}, {1,5}};
  660.     moveInterior(edges, centers, false);
  661. }
  662.  
  663. void RubiksCube::movee() {
  664.     int edges[4][2] = {{1,0}, {1,2}, {1,4}, {1,6}};
  665.     int centers[4][2] = {{1,7}, {1,1}, {1,3}, {1,5}};
  666.     moveInterior(edges, centers, true);
  667. }
  668.  
  669. void RubiksCube::moveS() {
  670.     int edges[4][2] = {{0,6}, {2,6}, {2,2}, {0,2}};
  671.     int centers[4][2] = {{0,0}, {1,5}, {2,0}, {1,1}};
  672.     moveInterior(edges, centers, false);
  673. }
  674.  
  675. void RubiksCube::moves() {
  676.     int edges[4][2] = {{0,6}, {2,6}, {2,2}, {0,2}};
  677.     int centers[4][2] = {{0,0}, {1,5}, {2,0}, {1,1}};
  678.     moveInterior(edges, centers, true);
  679. }
  680.  
  681. void RubiksCube::movex() {
  682.     moveR();
  683.     movem();
  684.     moveLp();
  685. }
  686.  
  687. void RubiksCube::movexp() {
  688.     moveRp();
  689.     moveM();
  690.     moveL();
  691. }
  692.  
  693. void RubiksCube::movey() {
  694.     moveU();
  695.     moveE();
  696.     moveDp();
  697. }
  698.  
  699. void RubiksCube::moveyp() {
  700.     moveUp();
  701.     movee();
  702.     moveD();
  703. }
  704.  
  705. void RubiksCube::movez() {
  706.     moveF();
  707.     moveS();
  708.     moveBp();
  709. }
  710.  
  711.  
  712. void RubiksCube::movezp() {
  713.     moveFp();
  714.     moveS();
  715.     moveB();
  716. }
  717.  
  718. void RubiksCube::silentMovex() {
  719.     moveR();
  720.     movem();
  721.     moveLp();
  722. }
  723.  
  724. void RubiksCube::silentMovexp() {
  725.     moveRp();
  726.     moveM();
  727.     moveL();
  728. }
  729.  
  730. void RubiksCube::silentMovey() {
  731.     moveU();
  732.     moveE();
  733.     moveDp();
  734. }
  735.  
  736. void RubiksCube::silentMoveyp() {
  737.     moveUp();
  738.     movee();
  739.     moveD();
  740. }
  741.  
  742. void RubiksCube::silentMovez() {
  743.     moveF();
  744.     moveS();
  745.     moveBp();
  746. }
  747.  
  748. void RubiksCube::silentMovezp() {
  749.     moveFp();
  750.     moveS();
  751.     moveB();
  752. }
  753.  
  754. RubiksCube RubiksCube::askForCube() {
  755.     int faces[6][9];
  756.     std::cout << "Les couleurs"
  757.     << std::endl << "\t- Blanc : 0"
  758.     << std::endl << "\t- Jaune : 1"
  759.     << std::endl << "\t- Rouge : 2"
  760.     << std::endl << "\t- Vert : 3"
  761.     << std::endl << "\t- Orange : 4"
  762.     << std::endl << "\t- Bleu : 5" << std::endl;
  763.     std::string facesNames[6] = {"blanche", "jaune", "rouge", "verte", "orange", "bleue"};
  764.     for (int face = 0; face < 6; face++) {
  765.         std::cout << "Entrez la face " << facesNames[face] << " : (centre en premier)" << std::endl;
  766.         for (int i = 0; i < 9; i++) {
  767.             std::cout << "\t> ";
  768.             std::cin >> faces[face][i];
  769.         }
  770.     }
  771.     vectorOfPieces possibility = {
  772.         {
  773.             std::shared_ptr<Piece>(new Center(faces[0][0])),
  774.             std::shared_ptr<Piece>(new Corner(faces[3][5], faces[0][1], faces[2][3])),
  775.             std::shared_ptr<Piece>(new Edge(faces[0][2], faces[3][4])),
  776.             std::shared_ptr<Piece>(new Corner(faces[3][3], faces[0][3], faces[4][5])),
  777.             std::shared_ptr<Piece>(new Edge(faces[0][4], faces[4][4])),
  778.             std::shared_ptr<Piece>(new Corner(faces[5][5], faces[0][5], faces[4][3])),
  779.             std::shared_ptr<Piece>(new Edge(faces[0][6], faces[5][4])),
  780.             std::shared_ptr<Piece>(new Corner(faces[5][3], faces[0][7], faces[2][5])),
  781.             std::shared_ptr<Piece>(new Edge(faces[0][8], faces[2][4])),
  782.         },
  783.         {
  784.             std::shared_ptr<Piece>(new Edge(faces[2][2], faces[3][6])),
  785.             std::shared_ptr<Piece>(new Center(faces[3][0])),
  786.             std::shared_ptr<Piece>(new Edge(faces[4][6], faces[3][2])),
  787.             std::shared_ptr<Piece>(new Center(faces[4][0])),
  788.             std::shared_ptr<Piece>(new Edge(faces[4][2], faces[5][6])),
  789.             std::shared_ptr<Piece>(new Center(faces[5][0])),
  790.             std::shared_ptr<Piece>(new Edge(faces[2][6], faces[5][2])),
  791.             std::shared_ptr<Piece>(new Center(faces[2][0])),
  792.         },
  793.         {
  794.             std::shared_ptr<Piece>(new Center(faces[1][0])),
  795.             std::shared_ptr<Piece>(new Corner(faces[3][7], faces[1][3], faces[2][1])),
  796.             std::shared_ptr<Piece>(new Edge(faces[1][2], faces[3][8])),
  797.             std::shared_ptr<Piece>(new Corner(faces[3][1], faces[1][1], faces[4][7])),
  798.             std::shared_ptr<Piece>(new Edge(faces[1][8], faces[4][8])),
  799.             std::shared_ptr<Piece>(new Corner(faces[5][7], faces[1][7], faces[4][1])),
  800.             std::shared_ptr<Piece>(new Edge(faces[1][6], faces[5][8])),
  801.             std::shared_ptr<Piece>(new Corner(faces[5][1], faces[1][5], faces[2][7])),
  802.             std::shared_ptr<Piece>(new Edge(faces[1][4], faces[2][8])),
  803.         }
  804.     };
  805.     RubiksCube cube(possibility);
  806.     return cube;
  807. }
  808.  
  809. RubiksCube RubiksCube::makeRandomCube(vectorOfPieces possibility, int seed) {
  810.     for (int i = 0; i < 9; i++) {
  811.         possibility[0][i] = possibility[0][i]->copy();
  812.     }
  813.     for (int i = 0; i < 8; i++) {
  814.         possibility[1][i] = possibility[1][i]->copy();
  815.     }
  816.     for (int i = 0; i < 9; i++) {
  817.         possibility[2][i] = possibility[2][i]->copy();
  818.     }
  819.     srand(seed);
  820.     RubiksCube cube(possibility);
  821.     for (int i = 0; i < 100; i++) {
  822.         switch(rand() % 11) {
  823.             case Movements::R: cube.moveR();break;
  824.             case Movements::Rp: cube.moveRp();break;
  825.             case Movements::L: cube.moveL();break;
  826.             case Movements::Lp: cube.moveLp();break;
  827.             case Movements::U: cube.moveU();break;
  828.             case Movements::Up: cube.moveUp();break;
  829.             case Movements::D: cube.moveD();break;
  830.             case Movements::Dp: cube.moveDp();break;
  831.             case Movements::F: cube.moveF();break;
  832.             case Movements::Fp: cube.moveFp();break;
  833.             case Movements::B: cube.moveB();break;
  834.             case Movements::Bp: cube.moveBp();break;
  835.         }
  836.     } return cube;
  837. }
  838.  
  839. RubiksCube RubiksCube::makeRandomCube(vectorOfPieces possibility) {
  840.     return makeRandomCube(possibility, time(NULL));
  841. }
  842.  
  843. RubiksCube RubiksCube::makeRandomCube() {
  844.     return makeRandomCube(RUBIKS_CUBE_FINISHED, time(NULL));
  845. }
  846.  
  847. std::vector<int> RubiksCube::findPlaceOfPiece(std::shared_ptr<Piece> piece, vectorOfPieces possibility) {
  848.     for (int i = 0; i < 9; i++) {
  849.         if (!(possibility[0][i] != piece)) return std::vector<int> {0, i};
  850.     }
  851.     for (int i = 0; i < 8; i++) {
  852.         if (!(possibility[1][i] != piece)) return std::vector<int> {1, i};
  853.     }
  854.     for (int i = 0; i < 9; i++) {
  855.         if (!(possibility[2][i] != piece)) return std::vector<int> {2, i};
  856.     }
  857.     std::cout << "ERROR : Piece not found " << piece << std::endl;
  858.     return std::vector<int> {-1, -1};
  859. }
  860.  
  861. bool RubiksCube::isPieceWellPlaced(vectorOfPieces objective, std::shared_ptr<Piece> piece) {
  862.     std::vector<int> movements;
  863.     if (m_possibility[1][1]->getColor() == Colors::white || m_possibility[1][5]->getColor() == Colors::white) {
  864.         silentMovez();
  865.         movements.push_back(Directions::z);
  866.     }
  867.     while (m_possibility[0][0]->getColor() != Colors::white) {
  868.         silentMovex();
  869.         movements.push_back(Directions::x);
  870.     }
  871.     while (m_possibility[1][7]->getColor() != Colors::red) {
  872.         silentMovey();
  873.         movements.push_back(Directions::y);
  874.     }
  875.     std::vector<int> placeOnObjective = findPlaceOfPiece(piece, objective);
  876.     std::vector<int> placeOnPossibility =  findPlaceOfPiece(piece, m_possibility);
  877.     bool response = objective[placeOnObjective[0]][placeOnObjective[1]] == m_possibility[placeOnPossibility[0]][placeOnPossibility[1]];//placeOnObjective == placeOnPossibility;
  878.     for (int i = movements.size() - 1; i >= 0; i--) {
  879.         switch (movements[i]) {
  880.             case Directions::x: silentMovexp();break;
  881.             case Directions::y: silentMoveyp();break;
  882.             case Directions::z: silentMovezp();break;
  883.         }
  884.     }
  885.     return response;
  886. }
  887.  
  888. Sequence RubiksCube::goTo(vectorOfPieces objective) {
  889.     solveFirstCross(objective);
  890.     //finishFirstFace(objective);
  891.     //solveSecondLayer(objective);
  892.     Sequence s;
  893.     return s;
  894. }
  895.  
  896. void RubiksCube::solveFirstCross(vectorOfPieces objective) {
  897.     std::vector<std::shared_ptr<Piece>> edges = {
  898.         objective[0][2],
  899.         objective[0][4],
  900.         objective[0][6],
  901.         objective[0][8]
  902.     };
  903.     for (int i = 0; i < 4; i++) {
  904.         moveyp();
  905.         if (!isPieceWellPlaced(objective, edges[i])) {
  906.             std::cout << "Piece mal placee" << std::endl;
  907.             putEdgeDown(edges[i]);
  908.             placeEdge(objective, edges[i]);
  909.         }
  910.     }
  911. }
  912.  
  913. void RubiksCube::putEdgeDown(std::shared_ptr<Piece> edge) {
  914.     std::vector<int> pos = findPlaceOfPiece(edge, m_possibility);
  915.     for (int i = 0; i < pos[1] / 2; i++) {
  916.         moveyp();
  917.     }
  918.     if (pos[0] == 0) {
  919.         moveM();
  920.         std::cout << *this;
  921.         moveDp();
  922.         std::cout << *this;
  923.         movem();
  924.         std::cout << *this;
  925.         moveD();
  926.         std::cout << *this;
  927.     } else if (pos[0] == 1) {
  928.         moveL();
  929.         moveD();
  930.         moveLp();
  931.     }
  932.     for (int i = 0; i < pos[1] / 2; i++) {
  933.         movey();
  934.         moveD();
  935.     }
  936.     std::cout << *this;
  937. }
  938.  
  939. void RubiksCube::placeEdge(vectorOfPieces objective, std::shared_ptr<Piece> edge) {
  940.     if (m_possibility[2][8]->getColor(1) == objective[0][findPlaceOfPiece(edge, objective)[1]]->getColor(0)) {   // GOOD ORIENTATION
  941.         moveDp();
  942.         moveM();
  943.         moveD();
  944.         movem();
  945.     } else {    // BAD ORIENTATION
  946.         moveM();
  947.         moveD();
  948.         moveD();
  949.         movem();
  950.     }
  951. }
  952.  
  953.  
  954. void RubiksCube::finishFirstFace(vectorOfPieces objective) {
  955.     std::vector<std::shared_ptr<Piece>> corners = {
  956.         objective[0][1],
  957.         objective[0][3],
  958.         objective[0][5],
  959.         objective[0][7]
  960.     };
  961.     for (int i = 0; i < 4; i++) {
  962.         moveyp();
  963.         if (!isPieceWellPlaced(objective, corners[i])) {
  964.             putCornerDown(corners[i]);
  965.             placeCorner(objective, corners[i]);
  966.         }
  967.     }
  968. }
  969.  
  970. void RubiksCube::putCornerDown(std::shared_ptr<Piece> corner) {
  971.     std::vector<int> pos = findPlaceOfPiece(corner, m_possibility);
  972.     for (int i = 0; i < (pos[1] + 1) / 2; i++) {
  973.         moveyp();
  974.     }
  975.     if (pos[0] == 0) {
  976.         moveRp();
  977.         moveDp();
  978.         moveR();
  979.         moveD();
  980.     }
  981.     for (int i = 0; i < (pos[1] + 1) / 2; i++) {
  982.         movey();
  983.         moveD();
  984.     }
  985. }
  986.  
  987.  
  988.  
  989.  
  990. void RubiksCube::placeCorner(vectorOfPieces objective, std::shared_ptr<Piece> corner) {
  991.     int color = objective[0][findPlaceOfPiece(corner, objective)[1]]->getColor(1);      // COLOR OF WHITE FACE
  992.     //std::cout << objective << std::endl;
  993.     //std::cout << color << findPlaceOfPiece(corner, objective)[0] << findPlaceOfPiece(corner, objective)[1];
  994.     //std::cout << m_possibility[2][7] << std::endl;
  995.     if (m_possibility[2][7]->getColor(0) == color) {
  996.         moveRp();
  997.         moveDp();
  998.         moveR();
  999.     } else if (m_possibility[2][7]->getColor(1) == color) {
  1000.         moveRp();
  1001.         moveD();
  1002.         moveD();
  1003.         moveR();
  1004.         moveD();
  1005.         moveRp();
  1006.         moveDp();
  1007.         moveR();
  1008.     } else if (m_possibility[2][7]->getColor(2) == color) {
  1009.         moveDp();
  1010.         moveRp();
  1011.         moveD();
  1012.         moveR();
  1013.     }
  1014. }
  1015.  
  1016. void RubiksCube::solveSecondLayer(vectorOfPieces objective) {
  1017.     std::vector<std::shared_ptr<Piece>> edges = {
  1018.         objective[1][0],
  1019.         objective[1][2],
  1020.         objective[1][4],
  1021.         objective[1][6]
  1022.     };
  1023.     for (int i = 0; i < 4; i++) {
  1024.         //std::cout << "apres le move" << *this;
  1025.         moveyp();
  1026.         //std::cout << "avant le move" << *this;
  1027.         std::cout << edges[i] << isPieceWellPlaced(objective, edges[i]) << std::endl;
  1028.         if (!isPieceWellPlaced(objective, edges[i])) {
  1029.             put2ndLayerEdgeDown(edges[i]);
  1030.             //std::cout << *this;
  1031.             place2ndLayerEdgeDown(objective, edges[i]);
  1032.         }
  1033.     }
  1034. }
  1035.  
  1036. void RubiksCube::put2ndLayerEdgeDown(std::shared_ptr<Piece> edge) {
  1037.     std::vector<int> pos = findPlaceOfPiece(edge, m_possibility);
  1038.     for (int i = 0; i < (pos[1] + (pos[0] == 1 ? 2 : 0)) / 2; i++) {
  1039.         moveyp();
  1040.     }
  1041.     if (pos[0] == 1) {
  1042.         moveRp();
  1043.         moveD();
  1044.         moveR();
  1045.         moveD();
  1046.         moveF();
  1047.         moveDp();
  1048.         moveFp();
  1049.     }
  1050.     for (int i = 0; i < (pos[1] + (pos[0] == 1 ? 2 : 0)) / 2; i++) {
  1051.         movey();
  1052.         moveD();
  1053.     }
  1054.     //std::cout << *this << std::endl;
  1055. }
  1056.  
  1057. void RubiksCube::place2ndLayerEdgeDown(vectorOfPieces objective, std::shared_ptr<Piece> edge) {
  1058.     std::vector<int> colors = objective[1][findPlaceOfPiece(edge, objective)[1]]->getAllColors();      // COLORS OF EDGE
  1059.     int centerColor = m_possibility[1][7]->getColor();      // FRONT FACE COLOR
  1060.     //std::cout << *this << std::endl;
  1061.     if (m_possibility[2][8]->getColor(1) == colors[centerColor == Colors::red || centerColor == Colors::orange ? 0 : 1]) {
  1062.         std::cout << "number 1" << std::endl;
  1063.         moveDp();
  1064.         moveRp();
  1065.         moveD();
  1066.         moveR();
  1067.         moveD();
  1068.         moveF();
  1069.         moveDp();
  1070.         moveFp();
  1071.     } else {
  1072.         std::cout << "number 2" << std::endl;
  1073.         movey();
  1074.         moveD();
  1075.         moveD();
  1076.         moveL();
  1077.         moveDp();
  1078.         moveLp();
  1079.         moveDp();
  1080.         moveFp();
  1081.         moveD();
  1082.         moveF();
  1083.         moveyp();
  1084.     }
  1085. }
  1086.  
  1087. void RubiksCube::test() {
  1088.     std::cout << m_possibility.size() << m_possibility[0].size() << m_possibility[1].size() << m_possibility[2].size();
  1089. }
  1090.  
  1091. void getStats(bool debug) {
  1092.     std::vector<std::vector<int>> TO_VERIFY {
  1093.         {0, 0},
  1094.         {0, 1},
  1095.         {0, 2},
  1096.         {0, 3},
  1097.         {0, 4},
  1098.         {0, 5},
  1099.         {0, 6},
  1100.         {0, 7},
  1101.         {0, 8},
  1102.     };
  1103.     srand(time(NULL));
  1104.     int rights = 0;
  1105.     int tests = 1;
  1106.     double startTime = time(NULL);
  1107.     for (int i = 0; i < tests; i++) {
  1108.         int seed = rand();
  1109.         RubiksCube cube = RubiksCube::makeRandomCube(RUBIKS_CUBE_FINISHED, seed);
  1110.         cube.goTo(RUBIKS_CUBE_FINISHED);
  1111.         bool error = false;
  1112.         for (int j = 0; j < TO_VERIFY.size(); j++) {
  1113.             if (!(cube.getPiece(TO_VERIFY[j][0], TO_VERIFY[j][1]) == RUBIKS_CUBE_FINISHED[TO_VERIFY[j][0]][TO_VERIFY[j][1]])) {
  1114.                 error = true;
  1115.             }
  1116.         }
  1117.         if (!error) {
  1118.             rights += 1;
  1119.         } else if (debug) {
  1120.             std::cout << "FAILURE WITH SEED : " << seed << std::endl;
  1121.         }
  1122.         if (tests / 100 != 0 && i % (tests/100) == 0) {
  1123.             std::cout << i / (tests/100) << "% made" << std::endl;
  1124.         }
  1125.         std::cout << cube;
  1126.     }
  1127.     double endTime = time(NULL);
  1128.     std::cout << std::endl << std::endl;
  1129.     std::cout << "\t- Number of tests : " << tests << std::endl;
  1130.     std::cout << "\t- " << (((double)rights)/tests) * 100 << "% tests successfull (" << tests - rights << " failed)" << std::endl;
  1131.     std::cout << "\t- Execution time : " << endTime - startTime << "s" << std::endl;
  1132.     std::cout << "\t- " << (endTime - startTime) / tests << " s/test" << std::endl;
  1133.     std::cout << "\t- " << tests / (endTime - startTime) << " tests/s" << std::endl;
  1134. }
  1135.  
  1136.  
  1137.  
  1138.  
  1139. vectorOfPieces TEST_RUBIKS_CUBE = {
  1140.     {
  1141.         std::shared_ptr<Piece>(new Center(Colors::white)),
  1142.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::white, Colors::red)),
  1143.         std::shared_ptr<Piece>(new Edge(Colors::green, Colors::white)),
  1144.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::white, Colors::orange)),
  1145.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::orange)),
  1146.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::white, Colors::orange)),
  1147.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::blue)),
  1148.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::white, Colors::red)),
  1149.         std::shared_ptr<Piece>(new Edge(Colors::white, Colors::red))
  1150.     },
  1151.     {
  1152.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::green)),
  1153.         std::shared_ptr<Piece>(new Center(Colors::green)),
  1154.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::blue)),
  1155.         std::shared_ptr<Piece>(new Center(Colors::orange)),
  1156.         std::shared_ptr<Piece>(new Edge(Colors::orange, Colors::blue)),
  1157.         std::shared_ptr<Piece>(new Center(Colors::blue)),
  1158.         std::shared_ptr<Piece>(new Edge(Colors::blue, Colors::red)),
  1159.         std::shared_ptr<Piece>(new Center(Colors::red))
  1160.     },
  1161.     {
  1162.         std::shared_ptr<Piece>(new Center(Colors::yellow)),
  1163.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::yellow, Colors::red)),
  1164.         std::shared_ptr<Piece>(new Edge(Colors::orange, Colors::green)),
  1165.         std::shared_ptr<Piece>(new Corner(Colors::green, Colors::yellow, Colors::orange)),
  1166.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::orange)),
  1167.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::yellow, Colors::orange)),
  1168.         std::shared_ptr<Piece>(new Edge(Colors::red, Colors::green)),
  1169.         std::shared_ptr<Piece>(new Corner(Colors::blue, Colors::yellow, Colors::red)),
  1170.         std::shared_ptr<Piece>(new Edge(Colors::yellow, Colors::red))
  1171.     }
  1172. };
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178. int main() {
  1179.     //RubiksCube cube = RubiksCube::makeRandomCube();
  1180.     RubiksCube cube(RUBIKS_CUBE_FINISHED);
  1181.     cube.moveS();
  1182.     //cube.goTo(RUBIKS_CUBE_FINISHED);
  1183.     std::cout << cube;
  1184.     //getStats(false);
  1185.     return 0;
  1186. }
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