Project

General

Profile

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

magiccube / src / main / java / org / distorted / solvers / SolverMain.java @ fcd5b990

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.solvers;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.main.R;
25
import org.distorted.objects.ObjectList;
26
import org.distorted.screens.ScreenList;
27
import org.distorted.screens.RubikScreenSolver;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class SolverMain implements Runnable
32
{
33
  private String mObjectPosition;
34
  private Resources mRes;
35
  private ObjectList mObject;
36
  private int mSize;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  public SolverMain(Resources res, ObjectList object, int size, String position )
41
    {
42
    mRes            = res;
43
    mObject         = object;
44
    mSize           = size;
45
    mObjectPosition = position;
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
// certain objects have certain cubits locked - for example, the Cube3's centers of
50
// sides always have the same color.
51
// If a certain cubit is locked, return the color (index into it's FACE_COLORS array) it
52
// must have. Otherwise return -1.
53

    
54
  public static int cubitIsLocked(ObjectList object, int size, int cubit)
55
    {
56
    if( object == ObjectList.CUBE && size == 3)
57
      {
58
      if( cubit==21 ) return 0; // center of the right  face
59
      if( cubit== 4 ) return 1; // center of the left   face
60
      if( cubit==15 ) return 2; // center of the up     face
61
      if( cubit==10 ) return 3; // center of the bottom face
62
      if( cubit==13 ) return 4; // center of the front  face
63
      if( cubit==12 ) return 5; // center of the back   face
64
      }
65

    
66
    return -1;
67
    }
68

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

    
71
  private void solveCube3(RubikScreenSolver solver)
72
    {
73
    String result;
74

    
75
    if( !org.distorted.solvers.cube3.Search.prepare(mRes) )
76
      result= "Error 9";
77
    else
78
      result = org.distorted.solvers.cube3.Search.solution(mObjectPosition, 24, 20);
79

    
80
    if (result.contains("Error"))
81
      {
82
      switch (result.charAt(result.length() - 1))
83
        {
84
        case '1': result = mRes.getString(R.string.solver_cube3_error1); break;
85
        case '2': result = mRes.getString(R.string.solver_cube3_error2); break;
86
        case '3': result = mRes.getString(R.string.solver_cube3_error3); break;
87
        case '4': result = mRes.getString(R.string.solver_cube3_error4); break;
88
        case '5': result = mRes.getString(R.string.solver_cube3_error5); break;
89
        case '6': result = mRes.getString(R.string.solver_cube3_error6); break;
90
        case '7': result = mRes.getString(R.string.solver_cube3_error7); break;
91
        case '8': result = mRes.getString(R.string.solver_cube3_error8); break;
92
        case '9': result = mRes.getString(R.string.solver_cube3_error9); break;
93
        }
94

    
95
      solver.displayErrorDialog(result);
96
      }
97
    else
98
      {
99
      solver.setSolved(result);
100
      }
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  private void interruptCube3()
106
    {
107
    org.distorted.solvers.cube3.Search.interrupt();
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  public void start()
113
    {
114
    Thread thr = new Thread(this);
115
    thr.start();
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public void run()
121
    {
122
    RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getStateClass();
123

    
124
    if( mObject == ObjectList.CUBE && mSize == 3)
125
      {
126
      solveCube3(solver);
127
      }
128
    else
129
      {
130
      solver.displayErrorDialog(mRes.getString(R.string.solver_generic_error1));
131
      }
132
    }
133
}  
134

    
(2-2/2)