示例#1
0
 /** Updates the coordinates displayed on the GUI */
 public void updateC() {
   if (!canEdit) {
     jTextField6.setText("" + model.CornOriCoord(cube.c));
     jTextField5.setText("" + model.EdgeOriCoord(cube.e));
     jTextField4.setText("" + model.UDSliceCoord(cube));
     int flipUD = flip.FlipUDSliceCoord(cube);
     jTextField3.setText("" + (int) (flipUD / 16) + " " + (int) (flipUD % 16));
     jTextField2.setText(
         ""
             + prune.Phase1PruningTable[(int) (flipUD / 16)][
                 table.CornOriSym[model.CornOriCoord(cube.c)][flipUD % 16]]);
     jTextField11.setText("" + model.CornPermCoord(cube.c));
     jTextField10.setText("" + model.EdgePermCoord(cube.e));
     jTextField9.setText("" + model.UDSliceSortedCoord(cube));
     if (model.CornOriCoord(cube.c) == 0
         && model.EdgeOriCoord(cube.e) == 0
         && (int) (flipUD / 16) == 0) { // phase2
       jTextField12.setText("" + model.Phase2EdgePermCoord(cube));
       int CornPerm = perm.CornPermCoord(cube);
       jTextField8.setText("" + (int) (perm.CornPermCoord(cube) / 16) + " " + CornPerm % 16);
       jTextField7.setText(
           ""
               + prune.Phase2PruningTable[(int) (CornPerm / 16)][
                   table.P2EdgePermSym[model.Phase2EdgePermCoord(cube)][CornPerm % 16]]);
     }
     updateView();
   }
 }
示例#2
0
 /** Creates new form RubikDisplay */
 public RubikDisplay2() {
   try {
     UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
   } catch (Exception e) {
     e.printStackTrace();
   }
   initComponents();
   File input, output;
   ObjectInputStream in;
   ObjectOutputStream out;
   model = null;
   nextMove = 0;
   moveList = null;
   long time1 = System.currentTimeMillis();
   // Initializes each structure by testing if it exists
   try {
     input = new File("model.dat");
     in = new ObjectInputStream(new FileInputStream(input));
     model = (RubikModel2) in.readObject();
     in.close();
     System.out.println("Model read from file");
   } catch (Exception e) {
     System.out.println("Error reading model from file");
     // e.printStackTrace();
   }
   // if unable to read from file, will recalculate
   if (model == null) {
     model = new RubikModel2();
     try {
       output = new File("model.dat");
       out = new ObjectOutputStream(new FileOutputStream(output));
       out.writeObject(model);
       out.close();
     } catch (Exception e) {
       System.out.println("Error writing model");
       e.printStackTrace();
     }
     System.out.println("Model created and saved");
   }
   long time2 = System.currentTimeMillis();
   flip = null;
   try {
     input = new File("flip.dat");
     in = new ObjectInputStream(new FileInputStream(input));
     flip = (FlipUDSlice) in.readObject();
     flip.setModel(model);
     in.close();
     System.out.println("FlipUDSlice read from file");
   } catch (Exception e) {
     System.out.println("Error reading FlipUDSlice from file");
     // e.printStackTrace();
   }
   if (flip == null) {
     flip = new FlipUDSlice(model);
     try {
       output = new File("flip.dat");
       out = new ObjectOutputStream(new FileOutputStream(output));
       out.writeObject(flip);
       out.close();
     } catch (Exception e) {
       System.out.println("Error writing FlipUDSlice");
       e.printStackTrace();
     }
     System.out.println("FlipUDSlice created and saved");
   }
   long time6 = System.currentTimeMillis();
   perm = null;
   try {
     input = new File("perm.dat");
     in = new ObjectInputStream(new FileInputStream(input));
     perm = (CornerPerm) in.readObject();
     perm.setModel(model);
     in.close();
     System.out.println("CornerPerm read from file");
   } catch (Exception e) {
     System.out.println("Error reading CornerPerm from file");
     // e.printStackTrace();
   }
   if (perm == null) {
     perm = new CornerPerm(model);
     try {
       output = new File("perm.dat");
       out = new ObjectOutputStream(new FileOutputStream(output));
       out.writeObject(perm);
       out.close();
     } catch (Exception e) {
       System.out.println("Error writing CornerPerm");
       e.printStackTrace();
     }
     System.out.println("CornerPerm created and saved");
   }
   long time3 = System.currentTimeMillis();
   table = null;
   try {
     input = new File("twist.dat");
     in = new ObjectInputStream(new FileInputStream(input));
     table = (TwistMoveTable) in.readObject();
     in.close();
     System.out.println("TwistMoveTable read from file");
   } catch (Exception e) {
     System.out.println("Error reading TwistMoveTable from file");
     // e.printStackTrace();
   }
   if (table == null) {
     table = new TwistMoveTable(model, flip, perm);
     try {
       output = new File("twist.dat");
       out = new ObjectOutputStream(new FileOutputStream(output));
       out.writeObject(table);
       out.close();
     } catch (Exception e) {
       System.out.println("Error writing TwistMoveTable");
       e.printStackTrace();
     }
     System.out.println("TwistMoveTable created and saved");
   }
   long time4 = System.currentTimeMillis();
   prune = null;
   try {
     input = new File("prune.dat");
     in = new ObjectInputStream(new FileInputStream(input));
     prune = (PruningTables) in.readObject();
     in.close();
     System.out.println("PruningTables read from file");
   } catch (Exception e) {
     System.out.println("Error reading PruningTables from file");
     // e.printStackTrace();
   }
   if (prune == null) {
     prune = new PruningTables(model, flip, table, perm);
     try {
       output = new File("prune.dat");
       out = new ObjectOutputStream(new FileOutputStream(output));
       out.writeObject(prune);
       out.close();
     } catch (Exception e) {
       System.out.println("Error writing PruningTables");
       e.printStackTrace();
     }
     System.out.println("PruningTables created and saved");
   }
   long time5 = System.currentTimeMillis();
   System.out.println("Model Initialization took " + (time2 - time1) + "ms");
   System.out.println("FlipUDSlice Initialization took " + (time6 - time2) + "ms");
   System.out.println("CornerPerm Initialization took " + (time3 - time6) + "ms");
   System.out.println("Table Initialization took " + (time4 - time3) + "ms");
   System.out.println("PruningTable Initialization took " + (time5 - time4) + "ms");
   this.setSize(800, 600);
   up = new JButton[3][3];
   down = new JButton[3][3];
   left = new JButton[3][3];
   right = new JButton[3][3];
   back = new JButton[3][3];
   front = new JButton[3][3];
   for (int i = 0; i < 3; i++) {
     for (int j = 0; j < 3; j++) {
       up[i][j] = new JButton();
       up[i][j].addActionListener(this);
       up[i][j].setPreferredSize(new Dimension(30, 30));
       this.getContentPane()
           .add(up[i][j], new AbsoluteConstraints(461 + 110 + 35 * i, 110 + 5 + 35 * j));
       down[i][j] = new JButton();
       down[i][j].addActionListener(this);
       down[i][j].setPreferredSize(new Dimension(30, 30));
       this.getContentPane()
           .add(down[i][j], new AbsoluteConstraints(461 + 110 + 35 * i, 110 + 215 + 35 * j));
       left[i][j] = new JButton();
       left[i][j].addActionListener(this);
       left[i][j].setPreferredSize(new Dimension(30, 30));
       this.getContentPane()
           .add(left[i][j], new AbsoluteConstraints(461 + 5 + 35 * i, 110 + 110 + 35 * j));
       right[i][j] = new JButton();
       right[i][j].addActionListener(this);
       right[i][j].setPreferredSize(new Dimension(30, 30));
       this.getContentPane()
           .add(right[i][j], new AbsoluteConstraints(461 + 215 + 35 * i, 110 + 110 + 35 * j));
       back[i][j] = new JButton();
       back[i][j].addActionListener(this);
       back[i][j].setPreferredSize(new Dimension(30, 30));
       this.getContentPane()
           .add(back[i][j], new AbsoluteConstraints(461 + 110 + 35 * i, 110 + 320 + 35 * j));
       front[i][j] = new JButton();
       front[i][j].addActionListener(this);
       front[i][j].setPreferredSize(new Dimension(30, 30));
       this.getContentPane()
           .add(front[i][j], new AbsoluteConstraints(461 + 110 + 35 * i, 110 + 110 + 35 * j));
     }
   }
   cube = new CubieCube(true);
   updateC();
 }