1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.solvers;
|
11
|
|
12
|
import android.content.res.Resources;
|
13
|
|
14
|
import org.distorted.main.R;
|
15
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
16
|
import org.distorted.objectlib.metadata.ListObjects;
|
17
|
import org.distorted.objectlib.main.TwistyObject;
|
18
|
import org.distorted.objectlib.shape.ShapeColors;
|
19
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
20
|
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
|
21
|
import org.distorted.objectlib.tablebases.TBDino4;
|
22
|
import org.distorted.objectlib.tablebases.TablebasesAbstract;
|
23
|
|
24
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25
|
|
26
|
public class SolverDino4 extends SolverTablebase
|
27
|
{
|
28
|
private static final int ERROR_EDGE_THREE = -1;
|
29
|
private TablebasesAbstract mSolver;
|
30
|
private int mErrorColor;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public SolverDino4(OperatingSystemInterface os, Resources res, TwistyObject object)
|
35
|
{
|
36
|
super(os, res,object);
|
37
|
}
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
private void getEdges(TwistyObject object, int[][] edges)
|
42
|
{
|
43
|
for(int i=0; i<12; i++)
|
44
|
{
|
45
|
edges[0][i] = object.getCubitFaceStickerIndex(i,0);
|
46
|
edges[1][i] = object.getCubitFaceStickerIndex(i,1);
|
47
|
}
|
48
|
}
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
private int checkEdges(int[][] edges)
|
53
|
{
|
54
|
int numB=0,numR=0, numY=0, numW=0;
|
55
|
int indB=0,indY=0, indW=0, indR=0;
|
56
|
|
57
|
int[] hexColors = ShapeHexahedron.FACE_COLORS;
|
58
|
|
59
|
for(int i=0; i<6; i++)
|
60
|
{
|
61
|
int color = hexColors[i];
|
62
|
|
63
|
if( color == ShapeColors.COLOR_WHITE) indW = i;
|
64
|
if( color == ShapeColors.COLOR_YELLOW) indY = i;
|
65
|
if( color == ShapeColors.COLOR_RED) indR = i;
|
66
|
if( color == ShapeColors.COLOR_BLUE) indB = i;
|
67
|
}
|
68
|
|
69
|
for(int i=0; i<12; i++)
|
70
|
{
|
71
|
int e = edges[0][i];
|
72
|
|
73
|
if( e==edges[1][i] )
|
74
|
{
|
75
|
if( e==indY ) numY++;
|
76
|
if( e==indW ) numW++;
|
77
|
if( e==indR ) numR++;
|
78
|
if( e==indB ) numB++;
|
79
|
}
|
80
|
}
|
81
|
|
82
|
if( numY !=3 ) { mErrorColor=0; return ERROR_EDGE_THREE; }
|
83
|
if( numW !=3 ) { mErrorColor=1; return ERROR_EDGE_THREE; }
|
84
|
if( numB !=3 ) { mErrorColor=2; return ERROR_EDGE_THREE; }
|
85
|
if( numR !=3 ) { mErrorColor=3; return ERROR_EDGE_THREE; }
|
86
|
|
87
|
return 0;
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
private void remap(int[] perm, int[] edges, int index, int section)
|
93
|
{
|
94
|
int val = edges[index];
|
95
|
|
96
|
for(int i=index;i<12; i++)
|
97
|
if( edges[i]==val )
|
98
|
{
|
99
|
edges[i]=-1;
|
100
|
perm[i] = section;
|
101
|
}
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
private int[] getPermutation(int[] edges)
|
107
|
{
|
108
|
int[] perm = new int[12];
|
109
|
|
110
|
int index0 = 0;
|
111
|
remap(perm,edges,index0,0);
|
112
|
|
113
|
int index1 = index0+1;
|
114
|
|
115
|
for(;index1<12;index1++)
|
116
|
if( edges[index1]>=0 ) break;
|
117
|
remap(perm,edges,index1,1);
|
118
|
|
119
|
int index2 = index1+1;
|
120
|
|
121
|
for(;index2<12;index2++)
|
122
|
if( edges[index2]>=0 ) break;
|
123
|
remap(perm,edges,index2,2);
|
124
|
|
125
|
int index3 = index2+1;
|
126
|
|
127
|
for(;index3<12;index3++)
|
128
|
if( edges[index3]>=0 ) break;
|
129
|
remap(perm,edges,index3,3);
|
130
|
|
131
|
return perm;
|
132
|
}
|
133
|
|
134
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135
|
|
136
|
public int tablebaseIndex(TwistyObject object)
|
137
|
{
|
138
|
int[][] edges = new int[2][12];
|
139
|
getEdges(object,edges);
|
140
|
|
141
|
int result1 = checkEdges(edges);
|
142
|
if( result1<0 ) return result1;
|
143
|
|
144
|
int[] perm = getPermutation(edges[0]);
|
145
|
return TBDino4.indexFromPartition(perm);
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
private int getColorIndex7(int color)
|
151
|
{
|
152
|
switch(color)
|
153
|
{
|
154
|
case 0: return R.string.color_yellow7;
|
155
|
case 1: return R.string.color_white7;
|
156
|
case 2: return R.string.color_blue7;
|
157
|
case 3: return R.string.color_red7;
|
158
|
}
|
159
|
|
160
|
return -1;
|
161
|
}
|
162
|
|
163
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164
|
|
165
|
public String error(int index, Resources res)
|
166
|
{
|
167
|
int i = getColorIndex7(mErrorColor);
|
168
|
String color = res.getString(i);
|
169
|
|
170
|
return res.getString(R.string.solver_generic_edge_three,color);
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
public int[][] solution(int index, OperatingSystemInterface os)
|
176
|
{
|
177
|
if( mSolver==null )
|
178
|
{
|
179
|
mSolver = ImplementedTablebasesList.createPacked(os, ListObjects.DIN4_3.name() );
|
180
|
}
|
181
|
|
182
|
return mSolver!=null ? mSolver.solution(index,null,os) : null;
|
183
|
}
|
184
|
}
|
185
|
|