Skip to content

Comparing Cubots

Akshath Raghav edited this page Jun 28, 2021 · 2 revisions

compareTo(Cubot other)

--> returns true if this and other have the same Cubot

  • if this and other have different cubeTypes, an IllegalArgumentException is thrown
Cubot cube = new Cubot();
Cubot cube2 = new Cubot() ;
System.out.println("Same Cube? -- " + cube.compareTo(cube2)) ;
// -- true 
Cubot cube = new Cubot();
String[] end2  = {"RRRR", "GGGG", "OOOO", "BBBB", "WWWW", "YYYY"};
Cubot cube2 = new Cubot(temp2) ;
System.out.println("Same Cube? -- " + cube.compareTo(cube2)) ;
// -- Exception in thread "main" java.lang.IllegalArgumentException: Error: Unmatched cubeTypes
//	at Cubot.compareTo(Cubot.java:134)

example

You can also do this manually if you wish to.
  • getCube() returns the Cube object ( it can be Cube2 or Cube3 -- exceptions shouldn't go unhandled )
  • solved() is a Cube(2/3) method
Cubot cube = new Cubot();
Cubot cube2 = new Cubot() ; 
System.out.println(((Cube3) cube.getCube()).solved((Cube3) cube2.getCube())) ;
// -- true 

compareToSolved

--> Returns an ArrayList containing the positions and colors on the pieces which are not solved ( i.e not in the solved positions ).

Generally, this is used to check the exact positions which aren't solved during any solve or move.

Cubot cube = new Cubot() ; 
cube.stringalg("R U R'") ; 
ArrayList<String> positionsNotDone = cube.compareToSolved() ; 
System.out.println(positionsNotDone) ; 
for (String i : positionsNotDone) {
       System.out.println(i);
}

example