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