Project

General

Profile

« Previous | Next » 

Revision 121e4a39

Added by Leszek Koltunski about 3 years ago

Fix solved state detection of the Dino4

View differences:

src/main/java/org/distorted/objects/TwistyDino4.java
26 26
import org.distorted.library.mesh.MeshSquare;
27 27
import org.distorted.library.type.Static4D;
28 28
import org.distorted.main.R;
29
import org.distorted.main.RubikSurfaceView;
29 30

  
30 31
import java.util.Random;
31 32

  
......
33 34

  
34 35
public class TwistyDino4 extends TwistyDino
35 36
{
36
  private static final int[] mFaceMap = {4,4, 2,2, 2,2, 4,4,
37
                                         0,0, 2,2, 1,1, 4,4,
38
                                         0,0, 0,0, 1,1, 1,1 };
37
  private static final int[] mFaceMap = { 4, 2, 2, 4, 0, 2, 1, 4, 0, 0, 1, 1 };
38
  private static final int[][] mScramble;
39

  
40
  static
41
    {
42
    int numQuats = QUATS.length;
43
    int numCenters = CENTERS.length;
44

  
45
    mScramble = new int[numQuats][numCenters];
46

  
47
    for(int q=0; q<numQuats; q++)
48
      for(int c=0; c<numCenters; c++) mScramble[q][c] = computeScramble(q,c);
49
    }
50

  
51
  private final int[] mColors = new int[CENTERS.length];
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  private static int computeScramble(int quatNum, int centerNum)
56
    {
57
    float MAXDIFF = 0.01f;
58
    float[] center= CENTERS[centerNum];
59
    Static4D sc = new Static4D(center[0], center[1], center[2], 1.0f);
60
    Static4D result = RubikSurfaceView.rotateVectorByQuat(sc,QUATS[quatNum]);
61
    int numCenters = CENTERS.length;
62

  
63
    float x = result.get0();
64
    float y = result.get1();
65
    float z = result.get2();
66

  
67
    for(int c=0; c<numCenters; c++)
68
      {
69
      float[] cent = CENTERS[c];
70

  
71
      float qx = cent[0] - x;
72
      float qy = cent[1] - y;
73
      float qz = cent[2] - z;
74

  
75
      if( qx>-MAXDIFF && qx<MAXDIFF &&
76
          qy>-MAXDIFF && qy<MAXDIFF &&
77
          qz>-MAXDIFF && qz<MAXDIFF  ) return c;
78
      }
79

  
80
    return -1;
81
    }
39 82

  
40 83
///////////////////////////////////////////////////////////////////////////////////////////////////
41 84

  
......
49 92

  
50 93
  int getFaceColor(int cubit, int cubitface, int size)
51 94
    {
52
    switch(cubitface)
53
      {
54
      case 0 : return mFaceMap[2*cubit];
55
      case 1 : return mFaceMap[2*cubit+1];
56
      default: return NUM_FACES;
57
      }
95
    return (cubitface==0 || cubitface==1) ? mFaceMap[cubit] : NUM_TEXTURES;
58 96
    }
59 97

  
60 98
///////////////////////////////////////////////////////////////////////////////////////////////////
......
88 126
    }
89 127

  
90 128
///////////////////////////////////////////////////////////////////////////////////////////////////
91
// Dino4 is solved if and only if the four groups of three same-colored cubits are each 'together'
92
// (actually we need to check only 3 first groups - if those are correct, the fourth one also needs
93
// to be correct).
94
//
95
// White group : (X,Y,Z) = 10,11,6
96
// Red group   : (X,Y,Z) = 0,3,7
97
// Blue group  : (X,Y,Z) = 2,1,5
98
// Yellow group: (X,Y,Z) = 8,9,4
99
//
100
// A group of 3 cubits is 'together' if and only if they are all rotated with one quat - but we cannot
101
// forget that the whole Dino can be mirrored! (so then qY = qX*Q2 and qZ = qX*Q8 )
102
//
103
// X cubits: 0, 2, 8, 10
104
// Y cubits: 1, 3, 9, 11
105
// Z cubits: 4, 5, 6, 7
129
// Dino4 is solved if and only if groups of cubits
130
// (0,3,7), (1,2,5), (4,8,9), (6,10,11)
131
// or
132
// (0,1,4), (2,3,6), (5,9,10), (7,8,11)
133
// are all the same color.
106 134

  
107 135
  public boolean isSolved()
108 136
    {
109
android.util.Log.e("D",
110

  
111
CUBITS[ 0].mQuatIndex+" "+
112
CUBITS[ 1].mQuatIndex+" "+
113
CUBITS[ 2].mQuatIndex+" "+
114
CUBITS[ 3].mQuatIndex+" "+
115
CUBITS[ 4].mQuatIndex+" "+
116
CUBITS[ 5].mQuatIndex+" "+
117
CUBITS[ 6].mQuatIndex+" "+
118
CUBITS[ 7].mQuatIndex+" "+
119
CUBITS[ 8].mQuatIndex+" "+
120
CUBITS[ 9].mQuatIndex+" "+
121
CUBITS[10].mQuatIndex+" "+
122
CUBITS[11].mQuatIndex
123

  
124
);
125

  
126
    int redX = CUBITS[0].mQuatIndex;
127
    int bluX = CUBITS[2].mQuatIndex;
128
    int yelX = CUBITS[8].mQuatIndex;
129

  
130
    if (CUBITS[3].mQuatIndex == redX && CUBITS[7].mQuatIndex == redX &&
131
        CUBITS[1].mQuatIndex == bluX && CUBITS[5].mQuatIndex == bluX &&
132
        CUBITS[9].mQuatIndex == yelX && CUBITS[4].mQuatIndex == yelX  ) return true;
133

  
134
    if (CUBITS[3].mQuatIndex != mulQuat(redX,2))
135
      {
136
      android.util.Log.e("D", "FALSE 1");
137
      return false;
138
      }
139
    if (CUBITS[7].mQuatIndex != mulQuat(redX,8))
140
      {
141
      android.util.Log.e("D", "FALSE 2");
142
      return false;
143
      }
144
    if (CUBITS[1].mQuatIndex != mulQuat(bluX,2))
145
      {
146
      android.util.Log.e("D", "FALSE 3");
147
      return false;
148
      }
149
    if (CUBITS[5].mQuatIndex != mulQuat(bluX,8))
150
      {
151
      android.util.Log.e("D", "FALSE 4");
152
      return false;
153
      }
154
    if (CUBITS[9].mQuatIndex != mulQuat(yelX,2))
155
      {
156
      android.util.Log.e("D", "FALSE 5");
157
      return false;
158
      }
159
    if (CUBITS[4].mQuatIndex != mulQuat(yelX,8))
137
    int numCenters = CENTERS.length;
138

  
139
    for(int c=0; c<numCenters; c++)
160 140
      {
161
      android.util.Log.e("D", "FALSE 6");
162
      return false;
141
      int index = mScramble[CUBITS[c].mQuatIndex][c];
142
      mColors[c] = mFaceMap[index];
163 143
      }
164 144

  
165
    return true;
145
    if( mColors[0]==mColors[3] && mColors[0]==mColors[7] &&
146
        mColors[1]==mColors[2] && mColors[1]==mColors[5] &&
147
        mColors[4]==mColors[8] && mColors[4]==mColors[9]  ) return true;
148

  
149
    if( mColors[0]==mColors[1] && mColors[0]==mColors[4] &&
150
        mColors[2]==mColors[3] && mColors[2]==mColors[6] &&
151
        mColors[5]==mColors[9] && mColors[5]==mColors[10] ) return true;
152

  
153
    return false;
166 154
    }
167 155

  
168 156
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff