1 |
b95ceafc
|
Leszek Koltunski
|
package org.distorted.solvers.cube3;
|
2 |
|
|
|
3 |
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
4 |
|
|
//Cube on the facelet level
|
5 |
|
|
class FaceCube {
|
6 |
|
|
public int[] f = new int[54];
|
7 |
|
|
|
8 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
9 |
|
|
// Map the corner positions to facelet positions. cornerFacelet[URF.ordinal()][0] e.g. gives the position of the
|
10 |
|
|
// facelet in the URF corner position, which defines the orientation.<br>
|
11 |
|
|
// cornerFacelet[URF.ordinal()][1] and cornerFacelet[URF.ordinal()][2] give the position of the other two facelets
|
12 |
|
|
// of the URF corner (clockwise).
|
13 |
|
|
final static int[][] cornerFacelet =
|
14 |
|
|
{ { Facelet.U9, Facelet.R1, Facelet.F3 }, { Facelet.U7, Facelet.F1, Facelet.L3 },
|
15 |
|
|
{ Facelet.U1, Facelet.L1, Facelet.B3 }, { Facelet.U3, Facelet.B1, Facelet.R3 },
|
16 |
|
|
{ Facelet.D3, Facelet.F9, Facelet.R7 }, { Facelet.D1, Facelet.L9, Facelet.F7 },
|
17 |
|
|
{ Facelet.D7, Facelet.B9, Facelet.L7 }, { Facelet.D9, Facelet.R9, Facelet.B7 } };
|
18 |
|
|
|
19 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
20 |
|
|
// Map the edge positions to facelet positions. edgeFacelet[UR.ordinal()][0] e.g. gives the position of the facelet in
|
21 |
|
|
// the UR edge position, which defines the orientation.<br>
|
22 |
|
|
// edgeFacelet[UR.ordinal()][1] gives the position of the other facelet
|
23 |
|
|
final static int[][] edgeFacelet =
|
24 |
|
|
{ { Facelet.U6, Facelet.R2 }, { Facelet.U8, Facelet.F2 }, { Facelet.U4, Facelet.L2 },
|
25 |
|
|
{ Facelet.U2, Facelet.B2 }, { Facelet.D6, Facelet.R8 }, { Facelet.D2, Facelet.F8 },
|
26 |
|
|
{ Facelet.D4, Facelet.L8 }, { Facelet.D8, Facelet.B8 }, { Facelet.F6, Facelet.R4 },
|
27 |
|
|
{ Facelet.F4, Facelet.L6 }, { Facelet.B6, Facelet.L4 }, { Facelet.B4, Facelet.R6 } };
|
28 |
|
|
|
29 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
30 |
|
|
// Map the corner positions to facelet colors.
|
31 |
|
|
final static int[][] cornerColor =
|
32 |
|
|
{ { Color.U, Color.R, Color.F }, { Color.U, Color.F, Color.L },
|
33 |
|
|
{ Color.U, Color.L, Color.B }, { Color.U, Color.B, Color.R },
|
34 |
|
|
{ Color.D, Color.F, Color.R }, { Color.D, Color.L, Color.F },
|
35 |
|
|
{ Color.D, Color.B, Color.L }, { Color.D, Color.R, Color.B } };
|
36 |
|
|
|
37 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
38 |
|
|
// Map the edge positions to facelet colors.
|
39 |
|
|
final static int[][] edgeColor =
|
40 |
|
|
{ { Color.U, Color.R }, { Color.U, Color.F }, { Color.U, Color.L },
|
41 |
|
|
{ Color.U, Color.B }, { Color.D, Color.R }, { Color.D, Color.F },
|
42 |
|
|
{ Color.D, Color.L }, { Color.D, Color.B }, { Color.F, Color.R },
|
43 |
|
|
{ Color.F, Color.L }, { Color.B, Color.L }, { Color.B, Color.R } };
|
44 |
|
|
|
45 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
46 |
|
|
FaceCube()
|
47 |
|
|
{
|
48 |
|
|
String s = "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB";
|
49 |
|
|
|
50 |
|
|
for (int i = 0; i < 54; i++)
|
51 |
|
|
f[i] = Color.toInt(s.substring(i, i + 1));
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
55 |
|
|
// Construct a facelet cube from a string
|
56 |
|
|
FaceCube(String cubeString)
|
57 |
|
|
{
|
58 |
|
|
for (int i = 0; i < cubeString.length(); i++)
|
59 |
|
|
f[i] = Color.toInt(cubeString.substring(i, i + 1));
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
63 |
|
|
// Gives string representation of a facelet cube
|
64 |
|
|
String to_String()
|
65 |
|
|
{
|
66 |
|
|
String s = "";
|
67 |
|
|
|
68 |
|
|
for (int i = 0; i < 54; i++)
|
69 |
|
|
s += Color.toString(f[i]);
|
70 |
|
|
|
71 |
|
|
return s;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
75 |
|
|
// Gives CubieCube representation of a faceletcube
|
76 |
|
|
CubieCube toCubieCube()
|
77 |
|
|
{
|
78 |
|
|
byte ori;
|
79 |
|
|
CubieCube ccRet = new CubieCube();
|
80 |
|
|
|
81 |
|
|
for (int i = 0; i < 8; i++) ccRet.cp[i] = Corner.URF; // invalidate corners
|
82 |
|
|
for (int i = 0; i < 12; i++) ccRet.ep[i] = Edge.UR; // and edges
|
83 |
|
|
|
84 |
|
|
int col1, col2;
|
85 |
|
|
|
86 |
|
|
for ( int i=Corner.URF; i<=Corner.DRB; i++)
|
87 |
|
|
{
|
88 |
|
|
// get the colors of the cubie at corner i, starting with U/D
|
89 |
|
|
for (ori = 0; ori < 3; ori++)
|
90 |
|
|
if (f[cornerFacelet[i][ori]] == Color.U || f[cornerFacelet[i][ori]] == Color.D)
|
91 |
|
|
break;
|
92 |
|
|
|
93 |
|
|
col1 = f[cornerFacelet[i][(ori + 1) % 3]];
|
94 |
|
|
col2 = f[cornerFacelet[i][(ori + 2) % 3]];
|
95 |
|
|
|
96 |
|
|
for ( int j=Corner.URF; j<=Corner.DRB; j++)
|
97 |
|
|
{
|
98 |
|
|
if (col1 == cornerColor[j][1] && col2 == cornerColor[j][2])
|
99 |
|
|
{
|
100 |
|
|
// in cornerposition i we have cornercubie j
|
101 |
|
|
ccRet.cp[i] = j;
|
102 |
|
|
ccRet.co[i] = (byte) (ori % 3);
|
103 |
|
|
break;
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
for ( int i=Edge.UR; i<=Edge.BR; i++)
|
109 |
|
|
{
|
110 |
|
|
for ( int j=Edge.UR; j<=Edge.BR; j++)
|
111 |
|
|
{
|
112 |
|
|
if (f[edgeFacelet[i][0]] == edgeColor[j][0] && f[edgeFacelet[i][1]] == edgeColor[j][1])
|
113 |
|
|
{
|
114 |
|
|
ccRet.ep[i] = j;
|
115 |
|
|
ccRet.eo[i] = 0;
|
116 |
|
|
break;
|
117 |
|
|
}
|
118 |
|
|
if (f[edgeFacelet[i][0]] == edgeColor[j][1] && f[edgeFacelet[i][1]] == edgeColor[j][0])
|
119 |
|
|
{
|
120 |
|
|
ccRet.ep[i] = j;
|
121 |
|
|
ccRet.eo[i] = 1;
|
122 |
|
|
break;
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
return ccRet;
|
128 |
|
|
};
|
129 |
|
|
}
|