1 |
eaee1ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.objects;
|
21 |
|
|
|
22 |
|
|
import android.content.res.Resources;
|
23 |
|
|
|
24 |
|
|
import org.distorted.library.main.DistortedEffects;
|
25 |
|
|
import org.distorted.library.main.DistortedTexture;
|
26 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
27 |
|
|
import org.distorted.library.type.Static4D;
|
28 |
6fd4a72c
|
Leszek Koltunski
|
import org.distorted.main.R;
|
29 |
121e4a39
|
Leszek Koltunski
|
import org.distorted.main.RubikSurfaceView;
|
30 |
2067efd8
|
Leszek Koltunski
|
|
31 |
|
|
import java.util.Random;
|
32 |
|
|
|
33 |
eaee1ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
9c2f0c91
|
Leszek Koltunski
|
public class TwistyDino4 extends TwistyDino
|
36 |
eaee1ddc
|
Leszek Koltunski
|
{
|
37 |
121e4a39
|
Leszek Koltunski
|
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 |
|
|
}
|
82 |
eaee1ddc
|
Leszek Koltunski
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
9c2f0c91
|
Leszek Koltunski
|
TwistyDino4(int size, Static4D quat, DistortedTexture texture,
|
86 |
|
|
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
87 |
eaee1ddc
|
Leszek Koltunski
|
{
|
88 |
9c2f0c91
|
Leszek Koltunski
|
super(size, quat, texture, mesh, effects, moves, ObjectList.DIN4, res, scrWidth);
|
89 |
eaee1ddc
|
Leszek Koltunski
|
}
|
90 |
|
|
|
91 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
|
93 |
|
|
int getFaceColor(int cubit, int cubitface, int size)
|
94 |
|
|
{
|
95 |
121e4a39
|
Leszek Koltunski
|
return (cubitface==0 || cubitface==1) ? mFaceMap[cubit] : NUM_TEXTURES;
|
96 |
eaee1ddc
|
Leszek Koltunski
|
}
|
97 |
|
|
|
98 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99 |
|
|
|
100 |
|
|
boolean shouldResetTextureMaps()
|
101 |
|
|
{
|
102 |
|
|
return true;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
2067efd8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
|
107 |
5043d5d0
|
Leszek Koltunski
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
|
108 |
2067efd8
|
Leszek Koltunski
|
{
|
109 |
5043d5d0
|
Leszek Koltunski
|
if( num==0 )
|
110 |
bbc6471c
|
Leszek Koltunski
|
{
|
111 |
582617c1
|
Leszek Koltunski
|
scramble[num][0] = rnd.nextInt(NUM_AXIS);
|
112 |
5043d5d0
|
Leszek Koltunski
|
scramble[num][1] = (scramble[num][0]==1 || scramble[num][0]==2) ? 0:2;
|
113 |
bbc6471c
|
Leszek Koltunski
|
}
|
114 |
|
|
else
|
115 |
|
|
{
|
116 |
582617c1
|
Leszek Koltunski
|
int newVector = rnd.nextInt(NUM_AXIS -1);
|
117 |
5043d5d0
|
Leszek Koltunski
|
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
118 |
|
|
scramble[num][1] = scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1];
|
119 |
bbc6471c
|
Leszek Koltunski
|
}
|
120 |
|
|
|
121 |
5043d5d0
|
Leszek Koltunski
|
switch( rnd.nextInt(2) )
|
122 |
|
|
{
|
123 |
|
|
case 0: scramble[num][2] = -1; break;
|
124 |
|
|
case 1: scramble[num][2] = 1; break;
|
125 |
|
|
}
|
126 |
2067efd8
|
Leszek Koltunski
|
}
|
127 |
|
|
|
128 |
eaee1ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
121e4a39
|
Leszek Koltunski
|
// 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.
|
134 |
eaee1ddc
|
Leszek Koltunski
|
|
135 |
|
|
public boolean isSolved()
|
136 |
|
|
{
|
137 |
121e4a39
|
Leszek Koltunski
|
int numCenters = CENTERS.length;
|
138 |
|
|
|
139 |
|
|
for(int c=0; c<numCenters; c++)
|
140 |
6a083c6a
|
Leszek Koltunski
|
{
|
141 |
121e4a39
|
Leszek Koltunski
|
int index = mScramble[CUBITS[c].mQuatIndex][c];
|
142 |
a91fb62f
|
Leszek Koltunski
|
mColors[index] = mFaceMap[c];
|
143 |
6a083c6a
|
Leszek Koltunski
|
}
|
144 |
ece1b58d
|
Leszek Koltunski
|
|
145 |
121e4a39
|
Leszek Koltunski
|
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;
|
154 |
eaee1ddc
|
Leszek Koltunski
|
}
|
155 |
6fd4a72c
|
Leszek Koltunski
|
|
156 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157 |
|
|
|
158 |
|
|
public int getObjectName(int numLayers)
|
159 |
|
|
{
|
160 |
|
|
return R.string.din43;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164 |
|
|
|
165 |
|
|
public int getInventor(int numLayers)
|
166 |
|
|
{
|
167 |
|
|
return R.string.din43_inventor;
|
168 |
|
|
}
|
169 |
eaee1ddc
|
Leszek Koltunski
|
}
|