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