rubikscube

college code for finding optimal rubiks cube solutions in java

git clone https://9o.is/git/rubikscube.git

RubiksTest.java

(6287B)


      1 import java.io.FileNotFoundException;
      2 import java.io.FileReader;
      3 import java.util.PriorityQueue;
      4 
      5 class RubiksTest
      6 {
      7     public static void main(String[] args)
      8     {
      9         /*RubiksCube cube = new RubiksCube(true);
     10         String[][] export = cube.getState();
     11         String corners = export[0][0];
     12         String halfEdges = export[1][0];
     13         //String half2Edges = export[2][0];
     14         System.out.println(corners);
     15         System.out.println(halfEdges);
     16         //System.out.println(half2Edges);
     17 
     18         PatternTable cornersTable = new PatternTable("corners.txt");
     19         cornersTable.updateTable(corners, "1");
     20         cornersTable.updateTable(halfEdges, "2");  */
     21         //PatternTable cornersTable = new PatternTable("corners.txt");
     22         //System.out.println(cornersTable.valueOf("WYWWRORBRBYY"));
     23         //cornersTable.clearTable();
     24 
     25         //RubiksCube cube = new RubiksCube(true);
     26         //cube.rotate(3, RubiksColor.WHITE);
     27         //cube.printState();
     28 
     29         //RubiksPatternTable patternTable = new RubiksPatternTable();
     30 
     31         /*byte[] corners =
     32                 new  byte[88179840];
     33         byte[] halfEdges =
     34                 new byte[42577920];
     35         byte[] half2Edges =
     36                 new byte[42577920];
     37 
     38         String[][] COMBINATIONS = {
     39                 {"RGW", "GWR", "WRG"},
     40                 {"RBW", "BWR", "WRB"},
     41                 {"YGR", "GRY", "RYG"},
     42                 {"YBR", "BRY", "RYB"},
     43                 {"OGY", "GYO", "YOG"},
     44                 {"OBY", "BYO", "YOB"},
     45                 {"WGO", "GOW", "OWG"},
     46                 {"WBO", "BOW", "OWB"}};
     47         System.out.println(COMBINATIONS.length);
     48 
     49         String A="RGW";
     50         String B="RBW";
     51         String C="YGR";
     52         String D="YBR";
     53         String E="OGY";
     54         String F="OBY";
     55         String G="WGO";
     56         String H="WBO";
     57 
     58         String I = "GR";
     59         String J = "WR";
     60         String K = "BR";
     61         String L = "YR";
     62         String M = "GY";
     63         String N = "BY";
     64 
     65         String O = "YO";
     66         String P = "OG";
     67         String Q = "OB";
     68         String R = "OW";
     69         String S = "WG";
     70         String T = "WB";
     71 
     72         try {
     73             RubiksSubState cornerState = new RubiksCornerState(A+B+C+D+E+F+H+G,0);
     74             RubiksSubState edgeState = new RubiksHalfEdgeState(I+J+K+L+N+M,0);
     75             RubiksSubState edge2State = new RubiksHalf2EdgeState(O+P+Q+R+S+T,0);
     76         } catch (Exception e) {
     77             e.printStackTrace();
     78         }             */
     79 
     80 
     81         // test if setState works
     82         /*RubiksCube randomCube = new RubiksCube(true);
     83         System.out.println("Goal State Cube:");
     84         cube.printState();
     85         System.out.println("Random State Cube:");
     86         randomCube.printState();
     87 
     88         randomCube.setState(cube.getState());
     89         System.out.println("Random Cube in Goal State:");
     90         randomCube.printState();*/
     91 
     92 
     93 
     94         // all possible rotations (18)
     95         //cube.rotate(0, RubiksRotation.VERTICAL_CLOCKWISE); //CORRECT 1
     96         //cube.rotate(1, RubiksRotation.VERTICAL_CLOCKWISE); //CORRECT 2
     97         //cube.rotate(0, RubiksRotation.VERTICAL_COUNTERCLOCKWISE); //CORRECT 3
     98         //cube.rotate(1, RubiksRotation.VERTICAL_COUNTERCLOCKWISE); //CORRECT 4
     99         //cube.rotate(0, RubiksRotation.VERTICAL_180); //CORRECT 5
    100         //cube.rotate(1, RubiksRotation.VERTICAL_180); //CORRECT 6
    101         //cube.rotate(0, RubiksRotation.HORIZONTAL_CLOCKWISE); //CORRECT 7
    102         //cube.rotate(1, RubiksRotation.HORIZONTAL_CLOCKWISE); //CORRECT 8
    103         //cube.rotate(0, RubiksRotation.HORIZONTAL_COUNTERCLOCKWISE); //CORRECT 9
    104         //cube.rotate(1, RubiksRotation.HORIZONTAL_COUNTERCLOCKWISE); //CORRECT 10
    105         //cube.rotate(0, RubiksRotation.HORIZONTAL_180); //CORRECT 11
    106         //cube.rotate(1, RubiksRotation.HORIZONTAL_180); //CORRECT 12
    107         //cube.rotate(0, RubiksRotation.SIDE_VERTICAL_CLOCKWISE); //CORRECT 13
    108         //cube.rotate(1, RubiksRotation.SIDE_VERTICAL_CLOCKWISE); //CORRECT 14
    109         //cube.rotate(0, RubiksRotation.SIDE_VERTICAL_COUNTERCLOCKWISE); //CORRECT 15
    110         //cube.rotate(1, RubiksRotation.SIDE_VERTICAL_COUNTERCLOCKWISE); //CORRECT 16
    111         //cube.rotate(0, RubiksRotation.SIDE_VERTICAL_180); //CORRECT 17
    112         //cube.rotate(1, RubiksRotation.SIDE_VERTICAL_180); //CORRECT 18
    113 
    114         // checks if all neighbor states are unique
    115         /*RubiksState[] states = cube.getNeighborStates();
    116         for(int i=0; i<states.length;i++) {
    117             RubiksState state = states[i];
    118             for(int j=0; j<states.length;j++) {
    119                 RubiksState checkme = states[j];
    120                 if(checkme.equals(state) && i != j) System.out.println("FAILED");
    121             }
    122             System.out.println(state.getState());
    123         }
    124         System.out.println("Done");  */
    125 
    126         //RubiksState s = cube.getState();
    127         //System.out.println(s.getHalfEdges());
    128         //cube.printState();
    129 
    130         /*RubiksPatternTable patternTable = new RubiksPatternTable();
    131         try {
    132             RubiksCube cube0 =
    133                     new RubiksCube(new FileReader("test_cases/cube0"));
    134 
    135             RubiksCubeSolver solver = new RubiksCubeSolver(patternTable);
    136 
    137             System.out.println(solver.solve(cube0));
    138 
    139         } catch (Exception e) {
    140             System.err.println(e.getMessage());
    141             e.printStackTrace();
    142         } */
    143 
    144         /*try {
    145             RubiksCube cube0 = new RubiksCube(new FileReader("test_cases/cube0"));
    146             RubiksCube cube1 = new RubiksCube(new FileReader("test_cases/cube1"));
    147             RubiksCube cube2 = new RubiksCube(new FileReader("test_cases/cube2"));
    148             RubiksCube cube3 = new RubiksCube(new FileReader("test_cases/cube3"));
    149             RubiksCube cube4 = new RubiksCube(new FileReader("test_cases/cube4"));
    150             RubiksCube cube5 = new RubiksCube(new FileReader("test_cases/cube5"));
    151             RubiksCube cube6 = new RubiksCube(new FileReader("test_cases/cube6"));
    152             RubiksCube cube7 = new RubiksCube(new FileReader("test_cases/cube7"));
    153             RubiksCube cube8 = new RubiksCube(new FileReader("test_cases/cube8"));
    154             RubiksCube cube9 = new RubiksCube(new FileReader("test_cases/cube9"));
    155         } catch (FileNotFoundException e) {
    156             e.printStackTrace();
    157         }   */
    158     }
    159 }