Project

General

Profile

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

magiccube / src / main / java / org / distorted / solvers / SolverTablebaseDINO4.java @ b35900ee

1 8afa10ef Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 da57afae Leszek Koltunski
import org.distorted.objectlib.helpers.OperatingSystemInterface;
16 8afa10ef Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
17 cf14e8f1 leszek
import org.distorted.objectlib.shape.ShapeColors;
18 2ee27c13 Leszek Koltunski
import org.distorted.objectlib.shape.ShapeHexahedron;
19 8afa10ef Leszek Koltunski
import org.distorted.objectlib.tablebases.TBDino4;
20
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22
23 1d1f9ccf leszek
public class SolverTablebaseDINO4 extends SolverTablebase
24 8afa10ef Leszek Koltunski
{
25
  private static final int ERROR_EDGE_THREE  = -1;
26
  private int mErrorColor;
27
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
30 1d1f9ccf leszek
  public SolverTablebaseDINO4(OperatingSystemInterface os, Resources res, TwistyObject object)
31 8afa10ef Leszek Koltunski
    {
32 da57afae Leszek Koltunski
    super(os, res,object);
33 8afa10ef Leszek Koltunski
    }
34
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37
  private void getEdges(TwistyObject object, int[][] edges)
38
    {
39
    for(int i=0; i<12; i++)
40
      {
41
      edges[0][i] = object.getCubitFaceStickerIndex(i,0);
42
      edges[1][i] = object.getCubitFaceStickerIndex(i,1);
43
      }
44
    }
45
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48
  private int checkEdges(int[][] edges)
49
    {
50 2ee27c13 Leszek Koltunski
    int numB=0,numR=0, numY=0, numW=0;
51
    int indB=0,indY=0, indW=0, indR=0;
52
53
    int[] hexColors = ShapeHexahedron.FACE_COLORS;
54
55
    for(int i=0; i<6; i++)
56
      {
57
      int color = hexColors[i];
58
59 99c2e327 leszek
      if( color == ShapeColors.COLOR_WHITE) indW = i;
60
      if( color == ShapeColors.COLOR_YELLOW) indY = i;
61
      if( color == ShapeColors.COLOR_RED) indR = i;
62
      if( color == ShapeColors.COLOR_BLUE) indB = i;
63 2ee27c13 Leszek Koltunski
      }
64 8afa10ef Leszek Koltunski
65
    for(int i=0; i<12; i++)
66
      {
67
      int e = edges[0][i];
68
69
      if( e==edges[1][i] )
70 2ee27c13 Leszek Koltunski
        {
71
        if( e==indY ) numY++;
72
        if( e==indW ) numW++;
73
        if( e==indR ) numR++;
74
        if( e==indB ) numB++;
75
        }
76 8afa10ef Leszek Koltunski
      }
77
78 2ee27c13 Leszek Koltunski
    if( numY !=3 ) { mErrorColor=0; return ERROR_EDGE_THREE; }
79
    if( numW !=3 ) { mErrorColor=1; return ERROR_EDGE_THREE; }
80
    if( numB !=3 ) { mErrorColor=2; return ERROR_EDGE_THREE; }
81
    if( numR !=3 ) { mErrorColor=3; return ERROR_EDGE_THREE; }
82 8afa10ef Leszek Koltunski
83
    return 0;
84
    }
85
86 8316f9ab Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88
  private void remap(int[] perm, int[] edges, int index, int section)
89
    {
90
    int val = edges[index];
91
92
    for(int i=index;i<12; i++)
93
      if( edges[i]==val )
94
        {
95
        edges[i]=-1;
96
        perm[i] = section;
97
        }
98
    }
99
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
102
  private int[] getPermutation(int[] edges)
103
    {
104
    int[] perm = new int[12];
105
106
    int index0 = 0;
107
    remap(perm,edges,index0,0);
108
109
    int index1 = index0+1;
110
111
    for(;index1<12;index1++)
112
      if( edges[index1]>=0 ) break;
113
    remap(perm,edges,index1,1);
114
115
    int index2 = index1+1;
116
117
    for(;index2<12;index2++)
118
      if( edges[index2]>=0 ) break;
119
    remap(perm,edges,index2,2);
120
121
    int index3 = index2+1;
122
123
    for(;index3<12;index3++)
124
      if( edges[index3]>=0 ) break;
125
    remap(perm,edges,index3,3);
126
127
    return perm;
128
    }
129
130 8afa10ef Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
131
132
  public int tablebaseIndex(TwistyObject object)
133
    {
134
    int[][] edges = new int[2][12];
135
    getEdges(object,edges);
136
137
    int result1 = checkEdges(edges);
138
    if( result1<0 ) return result1;
139
140 8316f9ab Leszek Koltunski
    int[] perm = getPermutation(edges[0]);
141
    return TBDino4.indexFromPartition(perm);
142 8afa10ef Leszek Koltunski
    }
143
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
146
  private int getColorIndex7(int color)
147
    {
148
    switch(color)
149
      {
150
      case 0: return R.string.color_yellow7;
151
      case 1: return R.string.color_white7;
152
      case 2: return R.string.color_blue7;
153
      case 3: return R.string.color_red7;
154
      }
155
156
    return -1;
157
    }
158
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
161
  public String error(int index, Resources res)
162
    {
163
    int i = getColorIndex7(mErrorColor);
164
    String color = res.getString(i);
165
166
    return res.getString(R.string.solver_generic_edge_three,color);
167
    }
168
}