Revision c0254421
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/TwistyBandaged3Plate.java | ||
---|---|---|
25 | 25 |
import org.distorted.library.main.DistortedTexture; |
26 | 26 |
import org.distorted.library.mesh.MeshSquare; |
27 | 27 |
import org.distorted.library.type.Static4D; |
28 |
import org.distorted.bandaged.BandagedState; |
|
28 | 29 |
import org.distorted.main.R; |
29 | 30 |
|
30 | 31 |
import java.util.Random; |
... | ... | |
38 | 39 |
private boolean mUseY; |
39 | 40 |
private boolean mUseZ; |
40 | 41 |
|
41 |
private static class State |
|
42 |
{ |
|
43 |
private final int mNumX, mNumY, mNumZ; |
|
44 |
private final int[] mInfo; |
|
45 |
private final int[] mTmp; |
|
46 |
private final int LEN = 4; |
|
47 |
|
|
48 |
State(int[] x, int[] y, int[] z) |
|
49 |
{ |
|
50 |
mTmp = new int[LEN]; |
|
51 |
|
|
52 |
mNumX = x==null ? 0 : x.length/(LEN-1); |
|
53 |
mNumY = y==null ? 0 : y.length/(LEN-1); |
|
54 |
mNumZ = z==null ? 0 : z.length/(LEN-1); |
|
55 |
|
|
56 |
mInfo = new int[LEN*(mNumX+mNumY+mNumZ)]; |
|
57 |
int start = 0; |
|
58 |
|
|
59 |
for(int i=0; i<mNumX; i++) |
|
60 |
{ |
|
61 |
mInfo[LEN*i + start] = 0; |
|
62 |
mInfo[LEN*i+1 + start] = x[(LEN-1)*i ]; |
|
63 |
mInfo[LEN*i+2 + start] = x[(LEN-1)*i+1]; |
|
64 |
mInfo[LEN*i+3 + start] = x[(LEN-1)*i+2]; |
|
65 |
} |
|
66 |
|
|
67 |
start = LEN*mNumX; |
|
68 |
|
|
69 |
for(int i=0; i<mNumY; i++) |
|
70 |
{ |
|
71 |
mInfo[LEN*i + start] = 1; |
|
72 |
mInfo[LEN*i+1 + start] = y[(LEN-1)*i ]; |
|
73 |
mInfo[LEN*i+2 + start] = y[(LEN-1)*i+1]; |
|
74 |
mInfo[LEN*i+3 + start] = y[(LEN-1)*i+2]; |
|
75 |
} |
|
76 |
|
|
77 |
start = LEN*(mNumX+mNumY); |
|
78 |
|
|
79 |
for(int i=0; i<mNumZ; i++) |
|
80 |
{ |
|
81 |
mInfo[LEN*i + start] = 2; |
|
82 |
mInfo[LEN*i+1 + start] = z[(LEN-1)*i ]; |
|
83 |
mInfo[LEN*i+2 + start] = z[(LEN-1)*i+1]; |
|
84 |
mInfo[LEN*i+3 + start] = z[(LEN-1)*i+2]; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
private int getIndex(int num, boolean useX, boolean useY, boolean useZ) |
|
89 |
{ |
|
90 |
int current= -1, total= mNumX + mNumY + mNumZ; |
|
91 |
|
|
92 |
for(int i=0; i<total; i++) |
|
93 |
{ |
|
94 |
if( (mInfo[LEN*i]==0 && useX) || (mInfo[LEN*i]==1 && useY) || (mInfo[LEN*i]==2 && useZ) ) |
|
95 |
{ |
|
96 |
if( ++current==num ) return i; |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
return -1; |
|
101 |
} |
|
102 |
|
|
103 |
int getTotal(boolean useX, boolean useY, boolean useZ) |
|
104 |
{ |
|
105 |
int total = 0; |
|
106 |
|
|
107 |
if( useX ) total += mNumX; |
|
108 |
if( useY ) total += mNumY; |
|
109 |
if( useZ ) total += mNumZ; |
|
110 |
|
|
111 |
return total; |
|
112 |
} |
|
113 |
|
|
114 |
int[] getInfo(int num, boolean useX, boolean useY, boolean useZ) |
|
115 |
{ |
|
116 |
int index = getIndex(num,useX,useY,useZ); |
|
117 |
|
|
118 |
mTmp[0] = mInfo[LEN*index ]; // axis |
|
119 |
mTmp[1] = mInfo[LEN*index+1]; // row |
|
120 |
mTmp[2] = mInfo[LEN*index+2]; // angle |
|
121 |
mTmp[3] = mInfo[LEN*index+3]; // next state |
|
122 |
|
|
123 |
return mTmp; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 | 42 |
// The 16 'significant' states of the 3Plate bandaged cube. |
128 | 43 |
// One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which |
129 | 44 |
// rotations of the Cube are possible. |
... | ... | |
137 | 52 |
// then we will land in state 10. If we make move (2,2), we will land in state 13. There are no other |
138 | 53 |
// 'x' moves that lead to a 'significant' state. |
139 | 54 |
|
140 |
private final State[] mStates = new State[]
|
|
141 |
{
|
|
142 |
new State( new int[] { 2,-1, 1, 2, 1, 6 }, new int[] { 0,-1, 5, 0, 1, 3 }, new int[] { 2,-1, 2, 2, 1, 4 } ),
|
|
143 |
new State( new int[] { 2, 1, 0 }, null , new int[] { 2, 1,10, 2, 2, 7 } ),
|
|
144 |
new State( null , new int[] { 0,-1,11, 0, 2, 8 }, new int[] { 2, 1, 0 } ),
|
|
145 |
new State( new int[] { 2, 1,12, 2, 2, 9 }, new int[] { 0,-1, 0 }, null ),
|
|
146 |
new State( new int[] { 2,-1,10, 2, 2,13 }, null , new int[] { 2,-1, 0 } ),
|
|
147 |
new State( null , new int[] { 0, 1, 0 }, new int[] { 2,-1,11, 2, 2,14 } ),
|
|
148 |
new State( new int[] { 2,-1, 0 }, new int[] { 0, 1,12, 0, 2,15 }, null ),
|
|
149 |
new State( null , new int[] { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, new int[] { 2,-1,10, 2, 2, 1 } ),
|
|
150 |
new State( new int[] { 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, new int[] { 0, 1,11, 0, 2, 2 }, null ),
|
|
151 |
new State( new int[] { 2,-1,12, 2, 2, 3 }, null , new int[] { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9} ),
|
|
152 |
new State( 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 } ),
|
|
153 |
new State( 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 } ),
|
|
154 |
new State( 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} ),
|
|
155 |
new State( new int[] { 2, 1,10, 2, 2, 4 }, new int[] { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, null ),
|
|
156 |
new State( new int[] { 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, null , new int[] { 2, 1,11, 2, 2, 5 } ),
|
|
157 |
new State( null , new int[] { 0,-1,12, 0, 2, 6 }, new int[] { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15} )
|
|
158 |
};
|
|
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 |
}; |
|
159 | 74 |
|
160 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
161 | 76 |
|
Also available in: Unified diff
Automatic scrambling of the Evil Cube works!