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.objectlib.tablebases;
|
11
|
|
12
|
import android.content.res.Resources;
|
13
|
|
14
|
import org.distorted.objectlib.main.ObjectSignatures;
|
15
|
|
16
|
import java.lang.reflect.Constructor;
|
17
|
import java.lang.reflect.InvocationTargetException;
|
18
|
|
19
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20
|
|
21
|
public enum ImplementedTablebasesList
|
22
|
{
|
23
|
PDUO (ObjectSignatures.PDUO_2, TBPyraminxDuo.class),
|
24
|
IVY (ObjectSignatures.IVY_2 , TBIvyCube.class),
|
25
|
CU_232 (ObjectSignatures.CU_232, TBCuboid232.class),
|
26
|
PYRA_3 (ObjectSignatures.PYRA_3, TBPyraminx.class),
|
27
|
DIAM2 (ObjectSignatures.DIAM_2, TBSkewbDiamond.class),
|
28
|
CUBE2 (ObjectSignatures.CUBE_2, TBCube2.class),
|
29
|
MIRR2 (ObjectSignatures.MIRR_2, TBCube2.class),
|
30
|
JING2 (ObjectSignatures.JING_2, TBJing.class),
|
31
|
;
|
32
|
|
33
|
public static final int NUM_OBJECTS = values().length;
|
34
|
|
35
|
private final int mSignature;
|
36
|
private final Class<? extends TablebasesAbstract> mClass;
|
37
|
|
38
|
private static final ImplementedTablebasesList[] objects;
|
39
|
|
40
|
static
|
41
|
{
|
42
|
objects = new ImplementedTablebasesList[NUM_OBJECTS];
|
43
|
int i=0;
|
44
|
|
45
|
for(ImplementedTablebasesList object: ImplementedTablebasesList.values())
|
46
|
{
|
47
|
objects[i++] = object;
|
48
|
}
|
49
|
}
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
public static boolean hasTablebase(int signature)
|
54
|
{
|
55
|
for(int i=0; i<NUM_OBJECTS; i++)
|
56
|
if( objects[i].mSignature == signature ) return true;
|
57
|
|
58
|
return false;
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
ImplementedTablebasesList(int sig, final Class<? extends TablebasesAbstract> clazz)
|
64
|
{
|
65
|
mSignature = sig;
|
66
|
mClass= clazz;
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
public int getSignature()
|
72
|
{
|
73
|
return mSignature;
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
|
78
|
private static TablebasesAbstract create(Resources res, int signature, boolean packed)
|
79
|
{
|
80
|
Class<? extends TablebasesAbstract> clazz=null;
|
81
|
|
82
|
for(int i=0; i<NUM_OBJECTS; i++)
|
83
|
if( objects[i].mSignature == signature )
|
84
|
{
|
85
|
clazz = objects[i].mClass;
|
86
|
break;
|
87
|
}
|
88
|
|
89
|
if( clazz==null ) return null;
|
90
|
|
91
|
try
|
92
|
{
|
93
|
Constructor<?>[] cons = clazz.getConstructors();
|
94
|
|
95
|
if( cons.length==2 )
|
96
|
{
|
97
|
if( packed )
|
98
|
{
|
99
|
Object[] parameters = new Object[] { res };
|
100
|
return (TablebasesAbstract)cons[1].newInstance(parameters);
|
101
|
}
|
102
|
else
|
103
|
{
|
104
|
return (TablebasesAbstract)cons[0].newInstance();
|
105
|
}
|
106
|
}
|
107
|
else
|
108
|
{
|
109
|
android.util.Log.e("TablebasesList", "ERROR! number of TablebasesAbstract constructors="+cons.length);
|
110
|
}
|
111
|
}
|
112
|
catch(IllegalAccessException iae)
|
113
|
{
|
114
|
android.util.Log.e("TablebasesList", "Illegal Access Exception: "+iae.getMessage());
|
115
|
}
|
116
|
catch(InstantiationException ie)
|
117
|
{
|
118
|
android.util.Log.e("TablebasesList", "Instantiation Exception: "+ie.getMessage());
|
119
|
}
|
120
|
catch(InvocationTargetException ite)
|
121
|
{
|
122
|
android.util.Log.e("TablebasesList", "Invocation Target Exception: "+ite.getMessage());
|
123
|
}
|
124
|
|
125
|
return null;
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
public static TablebasesAbstract createPacked(Resources res, int signature)
|
131
|
{
|
132
|
return create(res,signature,true);
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
public static TablebasesAbstract createUnpacked(int signature)
|
138
|
{
|
139
|
return create(null,signature,false);
|
140
|
}
|
141
|
}
|