Project

General

Profile

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

magiccube / src / main / java / org / distorted / solvers / SolverMain.java @ 420eb96d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.solvers;
11

    
12
import android.content.res.Resources;
13

    
14
import org.distorted.objectlib.main.ObjectSignatures;
15
import org.distorted.objectlib.main.TwistyObject;
16

    
17
import org.distorted.main.R;
18
import org.distorted.screens.ScreenList;
19
import org.distorted.screens.RubikScreenSolver;
20
import org.distorted.solvers.pduo.SolverPyraminxDuo;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
public class SolverMain implements Runnable
25
{
26
  private final Resources mRes;
27
  private final long mSignature;
28
  private final TwistyObject mObject;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
  public SolverMain(Resources res, TwistyObject object)
33
    {
34
    mRes       = res;
35
    mObject    = object;
36
    long[] sig = object.getSignature().getArray();
37
    mSignature = sig[sig.length-1];
38
    }
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
// 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
  public static int cubitIsLocked(int object, int cubit)
47
    {
48
    if( object == ObjectSignatures.CUBE_3 )
49
      {
50
      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
      }
57

    
58
    return -1;
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  public void start()
64
    {
65
    Thread thr = new Thread(this);
66
    thr.start();
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  public void run()
72
    {
73
    RubikScreenSolver screen = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
74

    
75
    if( mSignature==ObjectSignatures.CUBE_3 )
76
      {
77
      SolverCube3 solver = new SolverCube3(mRes,mObject);
78
      solver.solve(screen);
79
      }
80
    if( mSignature==ObjectSignatures.PDUO_2 )
81
      {
82
      SolverTablebase solver = new SolverPyraminxDuo(mRes,mObject);
83
      solver.solve(screen);
84
      }
85
    else
86
      {
87
      screen.displayErrorDialog(mRes.getString(R.string.solver_generic_error1));
88
      }
89
    }
90
}  
91

    
(3-3/4)