Project

General

Profile

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

magiccube / src / main / java / org / distorted / solvers / SolverDino4.java @ 8afa10ef

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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.main.R;
15
import org.distorted.objectlib.main.ObjectSignatures;
16
import org.distorted.objectlib.main.TwistyObject;
17
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
18
import org.distorted.objectlib.tablebases.TBDino4;
19
import org.distorted.objectlib.tablebases.TablebasesAbstract;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public class SolverDino4 extends SolverTablebase
24
{
25
  private static final int ERROR_EDGE_THREE  = -1;
26
  private TablebasesAbstract mSolver;
27
  private int mErrorColor;
28

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

    
31
  public SolverDino4(Resources res, TwistyObject object)
32
    {
33
    super(res,object);
34
    }
35

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

    
38
  private void getEdges(TwistyObject object, int[][] edges)
39
    {
40
    for(int i=0; i<12; i++)
41
      {
42
      edges[0][i] = object.getCubitFaceStickerIndex(i,0);
43
      edges[1][i] = object.getCubitFaceStickerIndex(i,1);
44
      }
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  private int checkEdges(int[][] edges)
50
    {
51
    int numBlue=0,numRed=0, numYellow=0, numWhite=0;
52

    
53
    for(int i=0; i<12; i++)
54
      {
55
      int e = edges[0][i];
56

    
57
      if( e==edges[1][i] )
58
        switch(e)
59
          {
60
          case 0: numYellow++; break;
61
          case 1: numWhite++ ; break;
62
          case 2: numBlue++  ; break;
63
          case 3: numRed++   ; break;
64
          }
65
      }
66

    
67
    if( numYellow!=3 ) { mErrorColor=0; return ERROR_EDGE_THREE; }
68
    if( numWhite !=3 ) { mErrorColor=1; return ERROR_EDGE_THREE; }
69
    if( numBlue  !=3 ) { mErrorColor=2; return ERROR_EDGE_THREE; }
70
    if( numRed   !=3 ) { mErrorColor=3; return ERROR_EDGE_THREE; }
71

    
72
    return 0;
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public int tablebaseIndex(TwistyObject object)
78
    {
79
    int[][] edges = new int[2][12];
80
    getEdges(object,edges);
81

    
82
    int result1 = checkEdges(edges);
83
    if( result1<0 ) return result1;
84

    
85
    return TBDino4.indexFromPartition(edges[0]);
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  private int getColorIndex7(int color)
91
    {
92
    switch(color)
93
      {
94
      case 0: return R.string.color_yellow7;
95
      case 1: return R.string.color_white7;
96
      case 2: return R.string.color_blue7;
97
      case 3: return R.string.color_red7;
98
      }
99

    
100
    return -1;
101
    }
102

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

    
105
  public String error(int index, Resources res)
106
    {
107
    int i = getColorIndex7(mErrorColor);
108
    String color = res.getString(i);
109

    
110
    return res.getString(R.string.solver_generic_edge_three,color);
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public int[][] solution(int index, Resources res)
116
    {
117
    if( mSolver==null )
118
      {
119
      mSolver = ImplementedTablebasesList.createUnpacked(ObjectSignatures.DIN4_3);
120
      if( mSolver!=null ) mSolver.createTablebase(-1);
121
      }
122

    
123
    return mSolver!=null ? mSolver.solution(index,null) : null;
124
    }
125
}  
126

    
(5-5/14)