Revision aa171dee
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.patterns; |
21 | 21 |
|
22 |
import org.distorted.object.RubikObject; |
|
23 |
|
|
22 | 24 |
import java.util.Vector; |
23 | 25 |
|
24 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
111 | 113 |
|
112 | 114 |
///////////////////////////////////////////////////////////// |
113 | 115 |
|
114 |
String retInitializationString(int pattern)
|
|
116 |
void makeMove(RubikObject object, int pattern)
|
|
115 | 117 |
{ |
116 | 118 |
if( pattern>=0 && pattern<numPatterns ) |
117 | 119 |
{ |
118 | 120 |
Pattern p = patterns.elementAt(pattern); |
119 |
if( p!=null ) return p.retInitializationString();
|
|
121 |
if( p!=null ) p.makeMove(object);
|
|
120 | 122 |
} |
121 |
|
|
122 |
return ""; |
|
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
///////////////////////////////////////////////////////////// |
126 | 126 |
|
127 |
String retNextMove(int pattern)
|
|
127 |
void backMove(RubikObject object, int pattern)
|
|
128 | 128 |
{ |
129 | 129 |
if( pattern>=0 && pattern<numPatterns ) |
130 | 130 |
{ |
131 | 131 |
Pattern p = patterns.elementAt(pattern); |
132 |
if( p!=null ) return p.retNextMove();
|
|
132 |
if( p!=null ) p.backMove(object);
|
|
133 | 133 |
} |
134 |
|
|
135 |
return ""; |
|
136 | 134 |
} |
137 | 135 |
|
138 | 136 |
///////////////////////////////////////////////////////////// |
139 | 137 |
|
140 |
String retPrevMove(int pattern)
|
|
138 |
String getMoves(int pattern)
|
|
141 | 139 |
{ |
142 | 140 |
if( pattern>=0 && pattern<numPatterns ) |
143 | 141 |
{ |
144 | 142 |
Pattern p = patterns.elementAt(pattern); |
145 |
if( p!=null ) return p.retPrevMove();
|
|
143 |
if( p!=null ) return p.getMoves();
|
|
146 | 144 |
} |
147 | 145 |
|
148 | 146 |
return ""; |
... | ... | |
191 | 189 |
|
192 | 190 |
///////////////////////////////////////////////////////////// |
193 | 191 |
|
194 |
String retNextMove()
|
|
192 |
void makeMove(RubikObject object)
|
|
195 | 193 |
{ |
196 | 194 |
curMove++; |
197 | 195 |
|
198 | 196 |
if( curMove>numMove) |
199 | 197 |
{ |
200 | 198 |
curMove= 0; |
201 |
return retInitializationString();
|
|
199 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
202 | 200 |
} |
203 | 201 |
else |
204 | 202 |
{ |
205 |
curMove--; |
|
206 |
return moves.substring(4*curMove-4,4*curMove); |
|
203 |
if( !object.makeMove(moves.substring(4*curMove-4,4*curMove)) ) |
|
204 |
{ |
|
205 |
curMove--; |
|
206 |
} |
|
207 | 207 |
} |
208 | 208 |
} |
209 | 209 |
|
210 | 210 |
///////////////////////////////////////////////////////////// |
211 | 211 |
|
212 |
String retPrevMove()
|
|
212 |
void backMove(RubikObject object)
|
|
213 | 213 |
{ |
214 | 214 |
curMove--; |
215 | 215 |
|
216 | 216 |
if( curMove<0) |
217 | 217 |
{ |
218 | 218 |
curMove=numMove; |
219 |
return retInitializationString();
|
|
219 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
220 | 220 |
} |
221 | 221 |
else |
222 | 222 |
{ |
223 |
curMove++; |
|
224 |
return moves.substring(4*curMove,4*curMove+4); |
|
223 |
if( !object.backMove(moves.substring(4*curMove,4*curMove+4)) ) |
|
224 |
{ |
|
225 |
curMove++; |
|
226 |
} |
|
225 | 227 |
} |
226 | 228 |
} |
227 | 229 |
|
228 | 230 |
///////////////////////////////////////////////////////////// |
229 | 231 |
|
230 |
String retInitializationString()
|
|
232 |
String getMoves()
|
|
231 | 233 |
{ |
232 | 234 |
return moves.substring(0,4*curMove); |
233 | 235 |
} |
... | ... | |
382 | 384 |
|
383 | 385 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
384 | 386 |
|
385 |
public String retNextMove(int size, int cat, int pat)
|
|
387 |
public void makeMove(RubikObject object, int size, int cat, int pat)
|
|
386 | 388 |
{ |
387 | 389 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
388 | 390 |
{ |
389 | 391 |
Category c = mCategories[size].elementAt(cat); |
390 |
if( c!=null ) return c.retNextMove(pat);
|
|
392 |
if( c!=null ) c.makeMove(object,pat);
|
|
391 | 393 |
} |
392 |
|
|
393 |
return ""; |
|
394 | 394 |
} |
395 | 395 |
|
396 | 396 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
397 | 397 |
|
398 |
public String retPrevMove(int size, int cat, int pat)
|
|
398 |
public void backMove(RubikObject object, int size, int cat, int pat)
|
|
399 | 399 |
{ |
400 | 400 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
401 | 401 |
{ |
402 | 402 |
Category c = mCategories[size].elementAt(cat); |
403 |
if( c!=null ) return c.retPrevMove(pat);
|
|
403 |
if( c!=null ) c.backMove(object,pat);
|
|
404 | 404 |
} |
405 |
|
|
406 |
return ""; |
|
407 | 405 |
} |
408 | 406 |
|
409 | 407 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
410 | 408 |
|
411 |
public String retInitializationString(int size,int cat, int pat)
|
|
409 |
public String getMoves(int size, int cat, int pat)
|
|
412 | 410 |
{ |
413 | 411 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
414 | 412 |
{ |
415 | 413 |
Category c = mCategories[size].elementAt(cat); |
416 |
if( c!=null ) return c.retInitializationString(pat);
|
|
414 |
if( c!=null ) return c.getMoves(pat);
|
|
417 | 415 |
} |
418 | 416 |
|
419 | 417 |
return ""; |
Also available in: Unified diff
More support for actual patterns!