Project

General

Profile

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

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

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 org.distorted.objectlib.helpers.OperatingSystemInterface;
13
import org.distorted.objectlib.main.ObjectSignatures;
14

    
15
import java.lang.reflect.Constructor;
16
import java.lang.reflect.InvocationTargetException;
17

    
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
public enum ImplementedTablebasesList
21
{
22
  PDUO     (ObjectSignatures.PDUO_2, TBPyraminxDuo.class),
23
  IVY      (ObjectSignatures.IVY_2 , TBIvyCube.class),
24
  CU_232   (ObjectSignatures.CU_232, TBCuboid232.class),
25
  PYRA_3   (ObjectSignatures.PYRA_3, TBPyraminx.class),
26
  DIAM2    (ObjectSignatures.DIAM_2, TBSkewbDiamond.class),
27
  CUBE2    (ObjectSignatures.CUBE_2, TBCube2.class),
28
  MIRR2    (ObjectSignatures.MIRR_2, TBCube2.class),
29
  JING2    (ObjectSignatures.JING_2, TBJing.class),
30
  SKEW2    (ObjectSignatures.SKEW_2, TBSkewb.class),
31
  DINO6    (ObjectSignatures.DINO_3, TBDino6.class),
32
  DINO4    (ObjectSignatures.DIN4_3, TBDino4.class),
33
  PDIAM    (ObjectSignatures.PDIA_3, TBPyraminxDiamond.class),
34
  ;
35

    
36
  public static final int NUM_OBJECTS = values().length;
37

    
38
  private final int mSignature;
39
  private final Class<? extends TablebasesAbstract> mClass;
40

    
41
  private static final ImplementedTablebasesList[] objects;
42

    
43
  static
44
    {
45
    objects = new ImplementedTablebasesList[NUM_OBJECTS];
46
    int i=0;
47

    
48
    for(ImplementedTablebasesList object: ImplementedTablebasesList.values())
49
      {
50
      objects[i++] = object;
51
      }
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  public static boolean hasTablebase(int signature)
57
    {
58
    for(int i=0; i<NUM_OBJECTS; i++)
59
      if( objects[i].mSignature == signature ) return true;
60

    
61
    return false;
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  ImplementedTablebasesList(int sig, final Class<? extends TablebasesAbstract> clazz)
67
    {
68
    mSignature = sig;
69
    mClass= clazz;
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  public int getSignature()
75
    {
76
    return mSignature;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  private static TablebasesAbstract create(OperatingSystemInterface os, int signature, boolean packed)
82
    {
83
    Class<? extends TablebasesAbstract> clazz=null;
84

    
85
    for(int i=0; i<NUM_OBJECTS; i++)
86
      if( objects[i].mSignature == signature )
87
        {
88
        clazz = objects[i].mClass;
89
        break;
90
        }
91

    
92
    if( clazz==null ) return null;
93

    
94
    try
95
      {
96
      Constructor<?>[] cons = clazz.getConstructors();
97

    
98
      if( cons.length==2 )
99
        {
100
        if( packed )
101
          {
102
          Object[] parameters = new Object[] { os };
103
          return (TablebasesAbstract)cons[1].newInstance(parameters);
104
          }
105
        else
106
          {
107
          return (TablebasesAbstract)cons[0].newInstance();
108
          }
109
        }
110
      else
111
        {
112
        android.util.Log.e("TablebasesList", "ERROR! number of TablebasesAbstract constructors="+cons.length);
113
        }
114
      }
115
    catch(IllegalAccessException iae)
116
      {
117
      android.util.Log.e("TablebasesList", "Illegal Access Exception: "+iae.getMessage());
118
      }
119
    catch(InstantiationException ie)
120
      {
121
      android.util.Log.e("TablebasesList", "Instantiation Exception: "+ie.getMessage());
122
      }
123
    catch(InvocationTargetException ite)
124
      {
125
      android.util.Log.e("TablebasesList", "Invocation Target Exception: "+ite.getMessage());
126
      }
127

    
128
    return null;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  public static TablebasesAbstract createPacked(OperatingSystemInterface os, int signature)
134
    {
135
    return create(os,signature,true);
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public static TablebasesAbstract createUnpacked(int signature)
141
    {
142
    return create(null,signature,false);
143
    }
144
}
(1-1/18)