Project

General

Profile

Download (3.31 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / solvers / SolverMain.java @ 5da7a80b

1 f0336037 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 bb62ca3f Leszek Koltunski
// 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 f0336037 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.solvers;
11
12
import android.content.res.Resources;
13
14 e4733ed7 Leszek Koltunski
import org.distorted.objectlib.main.ObjectSignatures;
15 3f7a4363 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
16
17 f0336037 Leszek Koltunski
import org.distorted.main.R;
18 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
19
import org.distorted.screens.RubikScreenSolver;
20 420eb96d Leszek Koltunski
import org.distorted.solvers.pduo.SolverPyraminxDuo;
21 f0336037 Leszek Koltunski
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
24 a304ee64 Leszek Koltunski
public class SolverMain implements Runnable
25 f0336037 Leszek Koltunski
{
26 c494476f Leszek Koltunski
  private final Resources mRes;
27 7e4f3e04 Leszek Koltunski
  private final long mSignature;
28 420eb96d Leszek Koltunski
  private final TwistyObject mObject;
29 f0336037 Leszek Koltunski
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
32 ecf3f149 Leszek Koltunski
  public SolverMain(Resources res, TwistyObject object)
33 f0336037 Leszek Koltunski
    {
34 7e4f3e04 Leszek Koltunski
    mRes       = res;
35
    mObject    = object;
36 7ed91391 Leszek Koltunski
    long[] sig = object.getSignature().getArray();
37
    mSignature = sig[sig.length-1];
38 f0336037 Leszek Koltunski
    }
39
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41 46a961fd Leszek Koltunski
// certain objects have certain cubits locked - for example, the Cube3's centers of
42
// sides always have the same color.
43
// If a certain cubit is locked, return the color (index into it's FACE_COLORS array) it
44
// must have. Otherwise return -1.
45
46 d433b50e Leszek Koltunski
  public static int cubitIsLocked(int object, int cubit)
47 46a961fd Leszek Koltunski
    {
48 e4733ed7 Leszek Koltunski
    if( object == ObjectSignatures.CUBE_3 )
49 46a961fd Leszek Koltunski
      {
50 09b2bd31 Leszek Koltunski
      if( cubit==20 ) return 0; // center of the right  face
51
      if( cubit==21 ) return 1; // center of the left   face
52
      if( cubit==22 ) return 2; // center of the up     face
53
      if( cubit==23 ) return 3; // center of the bottom face
54
      if( cubit==24 ) return 4; // center of the front  face
55
      if( cubit==25 ) return 5; // center of the back   face
56 46a961fd Leszek Koltunski
      }
57
58
    return -1;
59
    }
60
61 373fa45f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
62
63
  public void start()
64
    {
65
    Thread thr = new Thread(this);
66
    thr.start();
67
    }
68
69 f0336037 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71
  public void run()
72
    {
73 420eb96d Leszek Koltunski
    RubikScreenSolver screen = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
74 f0336037 Leszek Koltunski
75 fcbf34af Leszek Koltunski
    if( mSignature==ObjectSignatures.CUBE_3 )
76 f0336037 Leszek Koltunski
      {
77 420eb96d Leszek Koltunski
      SolverCube3 solver = new SolverCube3(mRes,mObject);
78
      solver.solve(screen);
79
      }
80 5da7a80b Leszek Koltunski
    else if( mSignature==ObjectSignatures.PDUO_2 )
81 420eb96d Leszek Koltunski
      {
82
      SolverTablebase solver = new SolverPyraminxDuo(mRes,mObject);
83
      solver.solve(screen);
84 f0336037 Leszek Koltunski
      }
85
    else
86
      {
87 420eb96d Leszek Koltunski
      screen.displayErrorDialog(mRes.getString(R.string.solver_generic_error1));
88 f0336037 Leszek Koltunski
      }
89
    }
90
}