Project

General

Profile

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

magiccube / src / main / java / org / distorted / solvers / Solver.java @ f0336037

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.main.RubikActivity;
26
import org.distorted.states.RubikState;
27
import org.distorted.states.RubikStateSolver;
28

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

    
31
public class Solver implements Runnable
32
{
33
  private String mObjectPosition;
34
  private RubikActivity mAct;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
  public Solver(RubikActivity act, String position )
39
    {
40
    mObjectPosition = position;
41
    mAct            = act;
42
    }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  public void start()
47
    {
48
    Thread thr = new Thread(this);
49
    thr.start();
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public void interrupt()
55
    {
56
    org.distorted.solvers.cube3.Search.interrupt();
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  public void run()
62
    {
63
    Resources res = mAct.getResources();
64
    RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass();
65
    String result;
66

    
67
    if( !org.distorted.solvers.cube3.Search.prepare(res) )
68
      result= "Error 9";
69
    else
70
      result = org.distorted.solvers.cube3.Search.solution(mObjectPosition, 24, 20);
71

    
72
    if (result.contains("Error"))
73
      {
74
      switch (result.charAt(result.length() - 1))
75
        {
76
        case '1': result = res.getString(R.string.error1); break;
77
        case '2': result = res.getString(R.string.error2); break;
78
        case '3': result = res.getString(R.string.error3); break;
79
        case '4': result = res.getString(R.string.error4); break;
80
        case '5': result = res.getString(R.string.error5); break;
81
        case '6': result = res.getString(R.string.error6); break;
82
        case '7': result = res.getString(R.string.error7); break;
83
        case '8': result = res.getString(R.string.error8); break;
84
        case '9': result = res.getString(R.string.error9); break;
85
        }
86

    
87
      solver.displayErrorDialog(mAct,result);
88
      }
89
    else
90
      {
91
      solver.setSolved( mAct, org.distorted.solvers.cube3.Search.numMoves(), result);
92
      }
93
    }
94
}  
95

    
    (1-1/1)