1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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
|
import org.distorted.helpers.BandagedState;
|
29
|
import org.distorted.main.R;
|
30
|
|
31
|
import java.util.Random;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
class TwistyBandaged3Plate extends TwistyBandagedAbstract
|
36
|
{
|
37
|
private int mCurrState;
|
38
|
private boolean mUseX;
|
39
|
private boolean mUseY;
|
40
|
private boolean mUseZ;
|
41
|
|
42
|
// The 16 'significant' states of the 3Plate bandaged cube.
|
43
|
// One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which
|
44
|
// rotations of the Cube are possible.
|
45
|
// There are 27 such states in total, but 2 of them are unreachable from the initial State, and
|
46
|
// 9 more and 'insignificant' - i.e. States which only permit rotation along a single axis.
|
47
|
// When doing an automatic scramble, we never want to enter such 'insignificant' states because
|
48
|
// that would mean we'd have to do two rotations in a row along the same axis.
|
49
|
//
|
50
|
// 4th State's first 'x' array being '2,-1,10, 2, 2,13' means the following:
|
51
|
// if we are in the 4th state, and make move (2,-1) [i.e. rotation along the X axis, 2nd row, -1 angle]
|
52
|
// then we will land in state 10. If we make move (2,2), we will land in state 13. There are no other
|
53
|
// 'x' moves that lead to a 'significant' state.
|
54
|
|
55
|
private final BandagedState[] mStates = new BandagedState[]
|
56
|
{
|
57
|
new BandagedState( new int[] { 2,-1, 1, 2, 1, 6 }, new int[] { 0,-1, 5, 0, 1, 3 }, new int[] { 2,-1, 2, 2, 1, 4 } ),
|
58
|
new BandagedState( new int[] { 2, 1, 0 }, null , new int[] { 2, 1,10, 2, 2, 7 } ),
|
59
|
new BandagedState( null , new int[] { 0,-1,11, 0, 2, 8 }, new int[] { 2, 1, 0 } ),
|
60
|
new BandagedState( new int[] { 2, 1,12, 2, 2, 9 }, new int[] { 0,-1, 0 }, null ),
|
61
|
new BandagedState( new int[] { 2,-1,10, 2, 2,13 }, null , new int[] { 2,-1, 0 } ),
|
62
|
new BandagedState( null , new int[] { 0, 1, 0 }, new int[] { 2,-1,11, 2, 2,14 } ),
|
63
|
new BandagedState( new int[] { 2,-1, 0 }, new int[] { 0, 1,12, 0, 2,15 }, null ),
|
64
|
new BandagedState( null , new int[] { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, new int[] { 2,-1,10, 2, 2, 1 } ),
|
65
|
new BandagedState( new int[] { 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, new int[] { 0, 1,11, 0, 2, 2 }, null ),
|
66
|
new BandagedState( new int[] { 2,-1,12, 2, 2, 3 }, null , new int[] { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9} ),
|
67
|
new BandagedState( new int[] { 2,-1,13, 2, 1, 4 }, new int[] { 2,-2,10, 2,-1,10, 2, 1,10, 2, 2,10}, new int[] { 2,-1, 1, 2, 1, 7 } ),
|
68
|
new BandagedState( new int[] { 0,-2,11, 0,-1,11, 0, 1,11, 0, 2,11}, new int[] { 0,-1, 8, 0, 1, 2 }, new int[] { 2,-1,14, 2, 1, 5 } ),
|
69
|
new BandagedState( new int[] { 2,-1, 3, 2, 1, 9 }, new int[] { 0,-1, 6, 0, 1,15 }, new int[] { 0,-2,12, 0,-1,12, 0, 1,12, 0, 2,12} ),
|
70
|
new BandagedState( new int[] { 2, 1,10, 2, 2, 4 }, new int[] { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, null ),
|
71
|
new BandagedState( new int[] { 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, null , new int[] { 2, 1,11, 2, 2, 5 } ),
|
72
|
new BandagedState( null , new int[] { 0,-1,12, 0, 2, 6 }, new int[] { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15} )
|
73
|
};
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
private static final float[][] POSITIONS = new float[][]
|
78
|
{
|
79
|
{-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f},
|
80
|
{ 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f},
|
81
|
{-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f},
|
82
|
{ 1.0f, 1.0f, 1.0f},
|
83
|
{ 1.0f, 0.0f, 1.0f},
|
84
|
{ 1.0f, -1.0f, 1.0f},
|
85
|
{-1.0f, -1.0f, 1.0f},
|
86
|
{ 0.0f, -1.0f, 1.0f},
|
87
|
{ 1.0f, -1.0f, 0.0f},
|
88
|
{ 1.0f, -1.0f, -1.0f},
|
89
|
{-1.0f, 1.0f, -1.0f},
|
90
|
{-1.0f, 1.0f, 0.0f},
|
91
|
{ 0.0f, 1.0f, -1.0f},
|
92
|
{ 0.0f, 1.0f, 0.0f},
|
93
|
{-1.0f, 0.0f, -1.0f},
|
94
|
{-1.0f, 0.0f, 0.0f},
|
95
|
{ 0.0f, 0.0f, -1.0f}
|
96
|
};
|
97
|
|
98
|
private static final int[] QUAT_INDICES = new int[] { 1, 3 };
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
103
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
104
|
{
|
105
|
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
float[][] getPositions()
|
111
|
{
|
112
|
return POSITIONS;
|
113
|
}
|
114
|
|
115
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116
|
|
117
|
int[] getQuatIndices()
|
118
|
{
|
119
|
return QUAT_INDICES;
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
// PUBLIC API
|
124
|
|
125
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
|
126
|
{
|
127
|
if( num==0 )
|
128
|
{
|
129
|
mCurrState = 0;
|
130
|
mUseX = true;
|
131
|
mUseY = true;
|
132
|
mUseZ = true;
|
133
|
}
|
134
|
|
135
|
int total = mStates[mCurrState].getTotal(mUseX,mUseY,mUseZ);
|
136
|
int random= rnd.nextInt(total);
|
137
|
int[] info= mStates[mCurrState].getInfo(random,mUseX,mUseY,mUseZ);
|
138
|
|
139
|
scramble[num][0] = info[0];
|
140
|
scramble[num][1] = info[1];
|
141
|
scramble[num][2] = info[2];
|
142
|
|
143
|
mCurrState = info[3];
|
144
|
|
145
|
switch(info[0])
|
146
|
{
|
147
|
case 0: mUseX = false; mUseY = true ; mUseZ = true ; break;
|
148
|
case 1: mUseX = true ; mUseY = false; mUseZ = true ; break;
|
149
|
case 2: mUseX = true ; mUseY = true ; mUseZ = false; break;
|
150
|
}
|
151
|
|
152
|
//android.util.Log.e("D", (info[0]==0 ? "X" : (info[0]==1 ? "Y" : "Z")) + info[2] +" --> "+info[3]);
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
public int getObjectName(int numLayers)
|
158
|
{
|
159
|
return R.string.bandaged_3plate;
|
160
|
}
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
|
164
|
public int getInventor(int numLayers)
|
165
|
{
|
166
|
return R.string.bandaged_3plate_inventor;
|
167
|
}
|
168
|
|
169
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170
|
|
171
|
public int getComplexity(int numLayers)
|
172
|
{
|
173
|
return 8;
|
174
|
}
|
175
|
}
|