20 |
20 |
import org.distorted.library.type.Static2D;
|
21 |
21 |
import org.distorted.library.type.Static4D;
|
22 |
22 |
import org.distorted.objectlib.helpers.MovesFinished;
|
|
23 |
import org.distorted.objectlib.helpers.ObjectMove;
|
23 |
24 |
import org.distorted.objectlib.main.ObjectControl;
|
24 |
25 |
import org.distorted.objectlib.main.TwistyObject;
|
25 |
26 |
|
... | ... | |
37 |
38 |
private final TextView mText, mPhase;
|
38 |
39 |
private String[] mPhaseNames;
|
39 |
40 |
private int mNumPhases;
|
40 |
|
private int[][][] mMoves;
|
|
41 |
private ObjectMove[][] mMoves;
|
41 |
42 |
private int[][] mCubitsNotInvolved;
|
42 |
43 |
private int mNumMoves,mCurrMove,mCurrPhase;
|
43 |
44 |
private boolean mCanMove;
|
... | ... | |
74 |
75 |
|
75 |
76 |
mPhaseNames = names;
|
76 |
77 |
mNumPhases = names.length;
|
77 |
|
mMoves = new int[mNumPhases][][];
|
|
78 |
mMoves = new ObjectMove[mNumPhases][];
|
78 |
79 |
mCubitsNotInvolved = new int[mNumPhases][];
|
79 |
80 |
mCanMove = true;
|
80 |
81 |
setSolution(null,0,null);
|
... | ... | |
86 |
87 |
{
|
87 |
88 |
mPhaseNames = names;
|
88 |
89 |
mNumPhases = names.length;
|
89 |
|
mMoves = new int[mNumPhases][][];
|
|
90 |
mMoves = new ObjectMove[mNumPhases][];
|
90 |
91 |
mCubitsNotInvolved = new int[mNumPhases][];
|
91 |
92 |
mCanMove = true;
|
92 |
93 |
setSolution(null,0,null);
|
... | ... | |
101 |
102 |
|
102 |
103 |
if( mCurrMove>0 )
|
103 |
104 |
{
|
104 |
|
int[][] moves = transformMoves(mMoves[mCurrPhase],0,mCurrMove, false);
|
|
105 |
ObjectMove[] moves = transformMoves(mMoves[mCurrPhase],0,mCurrMove, false);
|
105 |
106 |
control.applyScrambles(moves);
|
106 |
107 |
mCurrMove = 0;
|
107 |
108 |
}
|
... | ... | |
110 |
111 |
mCurrPhase--;
|
111 |
112 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
112 |
113 |
mCurrMove = 0;
|
113 |
|
int[][] moves = transformMoves(mMoves[mCurrPhase],0,mNumMoves, false);
|
|
114 |
ObjectMove[] moves = transformMoves(mMoves[mCurrPhase],0,mNumMoves, false);
|
114 |
115 |
control.applyScrambles(moves);
|
115 |
116 |
}
|
116 |
117 |
else
|
... | ... | |
118 |
119 |
mCurrPhase = mNumPhases-1;
|
119 |
120 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
120 |
121 |
mCurrMove = mNumMoves;
|
121 |
|
int[][] moves = transformMoves(mMoves, true);
|
|
122 |
ObjectMove[] moves = transformMoves(mMoves, true);
|
122 |
123 |
control.applyScrambles(moves);
|
123 |
124 |
}
|
124 |
125 |
|
... | ... | |
135 |
136 |
if( mCurrPhase<mNumPhases-1 )
|
136 |
137 |
{
|
137 |
138 |
glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
138 |
|
int[][] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
|
|
139 |
ObjectMove[] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
|
139 |
140 |
control.applyScrambles(moves);
|
140 |
141 |
mCurrPhase++;
|
141 |
142 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
... | ... | |
144 |
145 |
else if( mCurrMove<mNumMoves )
|
145 |
146 |
{
|
146 |
147 |
glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
147 |
|
int[][] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
|
|
148 |
ObjectMove[] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
|
148 |
149 |
control.applyScrambles(moves);
|
149 |
150 |
mCurrMove = mNumMoves;
|
150 |
151 |
}
|
... | ... | |
153 |
154 |
mCurrPhase = 0;
|
154 |
155 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
155 |
156 |
mCurrMove = 0;
|
156 |
|
int[][] moves = transformMoves(mMoves, false);
|
|
157 |
ObjectMove[] moves = transformMoves(mMoves, false);
|
157 |
158 |
control.applyScrambles(moves);
|
158 |
159 |
}
|
159 |
160 |
|
... | ... | |
190 |
191 |
|
191 |
192 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192 |
193 |
|
193 |
|
private int[][] transformMoves(int[][] moves, int start, int end, boolean front)
|
|
194 |
private ObjectMove[] transformMoves(ObjectMove[] moves, int start, int end, boolean front)
|
194 |
195 |
{
|
195 |
|
int mult = front ? 1:-1;
|
196 |
196 |
int len = end-start;
|
197 |
|
int[][] ret = new int[len][];
|
|
197 |
ObjectMove[] ret = new ObjectMove[len];
|
198 |
198 |
|
199 |
199 |
for(int m=0; m<len; m++)
|
200 |
200 |
{
|
201 |
|
int[] mv = moves[front ? start+m : end-1-m];
|
202 |
|
int[] rt = new int[3];
|
203 |
|
rt[0] = mv[0];
|
204 |
|
rt[1] = (1<<mv[1]);
|
205 |
|
rt[2] = mult*mv[2];
|
206 |
|
ret[m] = rt;
|
|
201 |
ObjectMove mv = moves[front ? start+m : end-1-m];
|
|
202 |
ret[m] = new ObjectMove( mv.getAxis(), mv.getRowBitmap(), front ? mv.getAngle() : -mv.getAngle());
|
207 |
203 |
}
|
208 |
204 |
|
209 |
205 |
return ret;
|
... | ... | |
211 |
207 |
|
212 |
208 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213 |
209 |
|
214 |
|
private int[][] transformMoves(int[][][] moves, boolean front)
|
|
210 |
private ObjectMove[] transformMoves(ObjectMove[][] moves, boolean front)
|
215 |
211 |
{
|
216 |
212 |
int len = moves.length;
|
217 |
213 |
int totalLen = 0;
|
218 |
|
for (int[][] move : moves) totalLen += (move==null ? 0 : move.length);
|
|
214 |
for (ObjectMove[] move : moves) totalLen += (move==null ? 0 : move.length);
|
219 |
215 |
|
220 |
|
int[][] ret = new int[totalLen][];
|
221 |
|
int mult = front ? 1:-1;
|
|
216 |
ObjectMove[] ret = new ObjectMove[totalLen];
|
222 |
217 |
int index = 0;
|
223 |
218 |
|
224 |
219 |
for(int m=0; m<len; m++)
|
225 |
220 |
{
|
226 |
|
int[][] mv = moves[front ? m : len-1-m];
|
|
221 |
ObjectMove[] mv = moves[front ? m : len-1-m];
|
227 |
222 |
int l = (mv==null ? 0 : mv.length);
|
228 |
223 |
|
229 |
224 |
for(int p=0; p<l; p++)
|
230 |
225 |
{
|
231 |
|
int[] mve = mv[front ? p : l-1-p];
|
232 |
|
int[] rt = new int[3];
|
233 |
|
rt[0] = mve[0];
|
234 |
|
rt[1] = (1<<mve[1]);
|
235 |
|
rt[2] = mult*mve[2];
|
236 |
|
ret[index++] = rt;
|
|
226 |
ObjectMove mve = mv[front ? p : l-1-p];
|
|
227 |
ret[index++] = new ObjectMove( mve.getAxis(), mve.getRowBitmap(), front ? mve.getAngle() : -mve.getAngle());
|
237 |
228 |
}
|
238 |
229 |
}
|
239 |
230 |
|
... | ... | |
301 |
292 |
|
302 |
293 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
303 |
294 |
|
304 |
|
void setSolution(int[][] moves, int phase, int[][] subphases)
|
|
295 |
void setSolution(ObjectMove[] moves, int phase, int[][] subphases)
|
305 |
296 |
{
|
306 |
297 |
SolverActivity act=mAct.get();
|
307 |
298 |
|
... | ... | |
344 |
335 |
if( mCurrMove>0 )
|
345 |
336 |
{
|
346 |
337 |
mCanMove = false;
|
347 |
|
int[] move = mMoves[mCurrPhase][--mCurrMove];
|
|
338 |
ObjectMove move = mMoves[mCurrPhase][--mCurrMove];
|
348 |
339 |
ObjectControl control = act.getControl();
|
349 |
340 |
control.blockTouch(MOVES_PLACE_0);
|
350 |
|
control.addRotation(this, move[0], (1<<move[1]), -move[2], MILLIS_PER_DEGREE);
|
|
341 |
control.addRotation(this, move.getAxis(), move.getRowBitmap(), -move.getAngle(), MILLIS_PER_DEGREE);
|
351 |
342 |
}
|
352 |
343 |
else if( mCurrPhase>0 )
|
353 |
344 |
{
|
... | ... | |
361 |
352 |
mCurrPhase = mNumPhases-1;
|
362 |
353 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
363 |
354 |
mCurrMove = mNumMoves;
|
364 |
|
int[][] moves = transformMoves(mMoves, true);
|
|
355 |
ObjectMove[] moves = transformMoves(mMoves, true);
|
365 |
356 |
ObjectControl control = act.getControl();
|
366 |
357 |
control.applyScrambles(moves);
|
367 |
358 |
glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
... | ... | |
382 |
373 |
if( mCurrMove<mNumMoves )
|
383 |
374 |
{
|
384 |
375 |
mCanMove = false;
|
385 |
|
int[] move = mMoves[mCurrPhase][mCurrMove++];
|
|
376 |
ObjectMove move = mMoves[mCurrPhase][mCurrMove++];
|
386 |
377 |
ObjectControl control = act.getControl();
|
387 |
378 |
control.blockTouch(MOVES_PLACE_1);
|
388 |
|
control.addRotation(this, move[0], (1<<move[1]), move[2], MILLIS_PER_DEGREE);
|
|
379 |
control.addRotation(this, move.getAxis(), move.getRowBitmap(), move.getAngle(), MILLIS_PER_DEGREE);
|
389 |
380 |
if( mCurrMove==mNumMoves && mCurrPhase==mNumPhases-1 ) glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
390 |
381 |
}
|
391 |
382 |
else if( mCurrPhase<mNumPhases-1 )
|
... | ... | |
400 |
391 |
mCurrPhase = 0;
|
401 |
392 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
402 |
393 |
mCurrMove = 0;
|
403 |
|
int[][] moves = transformMoves(mMoves, false);
|
|
394 |
ObjectMove[] moves = transformMoves(mMoves, false);
|
404 |
395 |
ObjectControl control = act.getControl();
|
405 |
396 |
control.applyScrambles(moves);
|
406 |
397 |
}
|
compiles now