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.objectlib.tablebases.ImplementedTablebasesList;
|
17
|
import org.distorted.objectlib.tablebases.TablebasesAbstract;
|
18
|
import org.distorted.solverui.ScreenSolver;
|
19
|
|
20
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
21
|
|
22
|
public abstract class SolverTablebase implements SolvingInterface
|
23
|
{
|
24
|
private final OperatingSystemInterface mOS;
|
25
|
private final Resources mRes;
|
26
|
private final TwistyObject mObject;
|
27
|
private TablebasesAbstract mSolver;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public abstract int tablebaseIndex(TwistyObject object);
|
32
|
public abstract String error(int index, Resources res);
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
// PUBLIC API
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public SolverTablebase(OperatingSystemInterface os, Resources res, TwistyObject object)
|
39
|
{
|
40
|
mOS = os;
|
41
|
mRes = res;
|
42
|
mObject= object;
|
43
|
}
|
44
|
|
45
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46
|
|
47
|
int[] getExtra() { return null; }
|
48
|
|
49
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
|
51
|
public void solve(ScreenSolver screen)
|
52
|
{
|
53
|
int index = tablebaseIndex(mObject);
|
54
|
|
55
|
if( index>=0 )
|
56
|
{
|
57
|
if( mSolver==null )
|
58
|
{
|
59
|
mSolver = ImplementedTablebasesList.createPacked(mOS, mObject.getShortName() );
|
60
|
}
|
61
|
|
62
|
mSolver.initialize();
|
63
|
int[][] moves = mSolver!=null ? mSolver.solution(index,getExtra(),mOS) : null;
|
64
|
screen.setSolved(moves);
|
65
|
}
|
66
|
else
|
67
|
{
|
68
|
String error = error(index,mRes);
|
69
|
screen.displayImpossibleDialog(error);
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
|