Project

General

Profile

« Previous | Next » 

Revision 7464b393

Added by Leszek Koltunski about 23 hours ago

Beginning of support for more than one solver per object.

View differences:

src/main/java/org/distorted/objects/RubikObject.java
39 39
  private final int mIconID;
40 40
  private final String[][] mPatterns;
41 41
  private final int mPrice;
42
  private final int mSolverOrdinal;
42
  private final int[] mSolverOrdinals;
43 43
  private final int mObjectOrdinal;
44 44
  private final boolean mIsLocal;
45 45
  private final int mCategory, mYear;
......
81 81
    int patternOrdinal  = RubikPatternList.getOrdinal(mObjectIndex);
82 82
    mPatterns = RubikPatternList.getPatterns(patternOrdinal);
83 83

  
84
    mSolverOrdinal = SolvingList.getSolverOrdinal(mObjectOrdinal);
84
    mSolverOrdinals= SolvingList.getSolverOrdinals(mObjectOrdinal);
85 85
    mExtrasOrdinal = -1;
86 86

  
87 87
    mObjectVersion = meta.objectVersion();
......
110 110

  
111 111
    mPatterns      = null;
112 112
    mExtrasOrdinal = -1;
113
    mSolverOrdinal = -1;
113
    mSolverOrdinals= null;
114 114
    mObjectOrdinal = -1;
115 115
    mIsLocal       = true;
116 116

  
......
355 355

  
356 356
  public boolean hasSolver()
357 357
    {
358
    return mSolverOrdinal>=0;
359
    }
360

  
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

  
363
  public int getSolverOrdinal()
364
    {
365
    return mSolverOrdinal;
358
    return mSolverOrdinals!=null;
366 359
    }
367 360

  
368 361
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/solvers/SolvingList.java
27 27
{
28 28
  CUBE2          (CUBE_2.ordinal(), SolverTablebaseCUBE2.class, R.string.solver_cube2_title, R.string.solver_cube2_description, true),
29 29
  CUBE3_KOCIEMBA (CUBE_3.ordinal(), SolverKociembaCUBE3.class , R.string.solver_cube3_title, R.string.solver_cube3_description, true),
30
  //CUBE3_FAKE     (CUBE_3.ordinal(), SolverKociembaCUBE3.class , R.string.solver_cube3_title, R.string.solver_cube3_description, true),
31

  
30 32
  CU232          (CU_232.ordinal(), SolverTablebaseCU232.class, R.string.solver_cu232_title, R.string.solver_cu232_description, true),
31 33
  CU323          (CU_323.ordinal(), SolverTablebaseCU323.class, R.string.solver_cu323_title, R.string.solver_cu323_description, true),
32 34
  PYRAMINX       (PYRA_3.ordinal(), SolverTablebasePYRA3.class, R.string.solver_pyra3_title, R.string.solver_pyra3_description, true),
......
70 72

  
71 73
///////////////////////////////////////////////////////////////////////////////////////////////////
72 74

  
73
  public static int getSolverOrdinal(int objectOrdinal)
75
  public static int[] getSolverOrdinals(int objectOrdinal)
74 76
    {
77
    int num = 0;
78

  
75 79
    for(int o=0; o<NUM_OBJECTS; o++)
76
      if( objects[o].mObjectOrdinal==objectOrdinal ) return o;
80
      if( objects[o].mObjectOrdinal==objectOrdinal ) num++;
77 81

  
78
    return -1;
82
    if( num>0 )
83
      {
84
      int[] ret = new int[num];
85
      int index = 0;
86

  
87
      for(int o=0; o<NUM_OBJECTS; o++)
88
        if( objects[o].mObjectOrdinal==objectOrdinal ) ret[index++] = o;
89

  
90
      return ret;
91
      }
92
    return null;
79 93
    }
80 94

  
81 95
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/solverui/ScreenSolver.java
55 55
  private int mNumColors;
56 56
  private float mBitmapSize;
57 57
  private WeakReference<SolverActivity> mWeakAct;
58
  private SolvingList mList;
58
  private int mObjectOrdinal;
59 59

  
60 60
///////////////////////////////////////////////////////////////////////////////////////////////////
61 61

  
......
78 78
    mWeakAct = new WeakReference<>(act);
79 79
    mSolving = false;
80 80

  
81
    int solverIndex= act.getSolverOrdinal();
82
    mList = SolvingList.getSolver(solverIndex);
83
    int currentObject = mList.getObjectOrdinal();
81
    mObjectOrdinal = act.getObjectOrdinal();
84 82
    control.solveOnly();
85
    generateFaceColors(currentObject);
83
    generateFaceColors(mObjectOrdinal);
86 84

  
87 85
    final float BUTTON_RATIO = 0.75f;
88 86
    int sizeV = (int)(heigh*MainActivity.RATIO_BAR*BUTTON_RATIO);
......
239 237
    return color;
240 238
    }
241 239

  
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

  
242
  private boolean pressSolve(SolverActivity act)
243
    {
244
    int[] solverOrdinals = SolvingList.getSolverOrdinals(mObjectOrdinal);
245

  
246
    if( solverOrdinals!=null  )
247
      {
248
      int len = solverOrdinals.length;
249

  
250
      if( len==1 ) // just one solver - simply launch it and start finding the solution
251
        {
252
        SolvingList list = SolvingList.getSolver(solverOrdinals[0]);
253
        TwistyObject object = act.getObject();
254
        SolvingThread solver = new SolvingThread( act.getInterface(), act.getResources(), object, list );
255
        solver.start();
256
        return true;
257
        }
258
      else  // more than one solver - launch a choosing dialog
259
        {
260
        // TODO
261
        android.util.Log.e("D", len+" solvers found for object "+mObjectOrdinal);
262
        return false;
263
        }
264
      }
265
    else  // no solvers? Impossible!
266
      {
267
      android.util.Log.e("D", "No solvers found for object "+mObjectOrdinal);
268
      return false;
269
      }
270
    }
271

  
242 272
///////////////////////////////////////////////////////////////////////////////////////////////////
243 273

  
244 274
  private void setupColorButtons(final SolverActivity act, final float width)
......
304 334
      @Override
305 335
      public void onClick(View v)
306 336
        {
307
        if( !mSolving )
308
          {
309
          mSolving = true;
310
          TwistyObject object = act.getObject();
311
          SolvingThread solver = new SolvingThread( act.getInterface(), act.getResources(), object, mList );
312
          solver.start();
313
          }
337
        if( !mSolving && pressSolve(act) ) mSolving = true;
314 338
        }
315 339
      });
316 340
    }
src/main/java/org/distorted/solverui/SolverActivity.java
29 29
import org.distorted.objects.RubikObject;
30 30
import org.distorted.objects.RubikObjectList;
31 31
import org.distorted.os.OSInterface;
32
import org.distorted.solvers.SolvingList;
33 32

  
34 33
import java.io.InputStream;
35 34

  
......
46 45
    private static final int ACTIVITY_NUMBER = 4;
47 46
    private static final float RATIO_INSET= 0.09f;
48 47

  
49
    private int mSolverOrdinal;
50 48
    private int mObjectOrdinal;
51 49
    private boolean mDisplayMessageDialog;
52 50

  
......
61 59

  
62 60
      Bundle b = getIntent().getExtras();
63 61
      mObjectOrdinal = b!=null ? b.getInt("obj") : 0;
64
      RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
65
      mSolverOrdinal = object==null ? -1 : object.getSolverOrdinal();
66 62
      mDisplayMessageDialog = true;
67 63

  
68 64
      computeScreenDimensions();
......
211 207
      return view.getObjectControl();
212 208
      }
213 209

  
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

  
216
    public int getSolverOrdinal()
217
      {
218
      return mSolverOrdinal;
219
      }
220

  
221 210
///////////////////////////////////////////////////////////////////////////////////////////////////
222 211

  
223 212
    public int getObjectOrdinal()

Also available in: Unified diff