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