Project

General

Profile

Download (4.84 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / ImplementedTablebasesList.java @ efc71331

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