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.objectlib.main.TwistyObject;
|
15
|
import org.distorted.screens.RubikScreenSolver;
|
16
|
|
17
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
18
|
|
19
|
public abstract class SolverTablebase
|
20
|
{
|
21
|
private final Resources mRes;
|
22
|
private final TwistyObject mObject;
|
23
|
|
24
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25
|
|
26
|
public abstract int tablebaseIndex(TwistyObject object);
|
27
|
public abstract String error(int index, Resources res);
|
28
|
public abstract int[][] solution(int index, Resources res);
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
// PUBLIC API
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public SolverTablebase(Resources res, TwistyObject object)
|
35
|
{
|
36
|
mRes = res;
|
37
|
mObject= object;
|
38
|
}
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
public void solve(RubikScreenSolver screen)
|
43
|
{
|
44
|
int index = tablebaseIndex(mObject);
|
45
|
|
46
|
if( index>=0 )
|
47
|
{
|
48
|
int[][] moves = solution(index,mRes);
|
49
|
screen.setSolved(moves);
|
50
|
}
|
51
|
else
|
52
|
{
|
53
|
String error = error(index,mRes);
|
54
|
screen.displayErrorDialog(error);
|
55
|
}
|
56
|
}
|
57
|
}
|
58
|
|