Project

General

Profile

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

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

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
  CU_323   (ObjectSignatures.CU_323, TBCuboid323.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
  SKEW2    (ObjectSignatures.SKEW_2, TBSkewb.class),
32
  DINO6    (ObjectSignatures.DINO_3, TBDino6.class),
33
  DINO4    (ObjectSignatures.DIN4_3, TBDino4.class),
34
  PDIAM    (ObjectSignatures.PDIA_3, TBPyraminxDiamond.class),
35
  ;
36

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

    
39
  private final int mSignature;
40
  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
  public static boolean hasTablebase(int signature)
58
    {
59
    for(int i=0; i<NUM_OBJECTS; i++)
60
      if( objects[i].mSignature == signature ) return true;
61

    
62
    return false;
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

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

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

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

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

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

    
86
    for(int i=0; i<NUM_OBJECTS; i++)
87
      if( objects[i].mSignature == signature )
88
        {
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
        if( packed )
102
          {
103
          Object[] parameters = new Object[] { os };
104
          return (TablebasesAbstract)cons[1].newInstance(parameters);
105
          }
106
        else
107
          {
108
          return (TablebasesAbstract)cons[0].newInstance();
109
          }
110
        }
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
  public static TablebasesAbstract createPacked(OperatingSystemInterface os, int signature)
135
    {
136
    return create(os,signature,true);
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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