Project

General

Profile

« Previous | Next » 

Revision ecf3f149

Added by Leszek Koltunski over 3 years ago

Move the TwistyObject.retCubePosition() to the solver.

View differences:

src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
583 583

  
584 584
    return true;
585 585
    }
586

  
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
// only needed for solvers - there are no Bandaged solvers ATM)
589

  
590
  public String retObjectString()
591
    {
592
    return "";
593
    }
594 586
}
src/main/java/org/distorted/objects/TwistyCube.java
374 374
    return true;
375 375
    }
376 376

  
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378
// order: Up --> Right --> Front --> Down --> Left --> Back
379
// (because the first implemented Solver - the two-phase Cube3 one - expects such order)
380
//
381
// Solved 3x3x3 Cube maps to "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"
382
//
383
// s : size of the cube; let index = a*s + b    (i.e. a,b = row,column)
384
//
385
// Up    :   index --> b<s-1 ? (s-1)*(s+4b)+a : 6*s*s -13*s +8 +a
386
// Right :   index --> 6*s*s - 12*s + 7 - index
387
// Front :   index --> if b==0  : s*s - 1 - index
388
//                     if b==s-1: 6*s*s -11*s +6 - index
389
//                     else
390
//                         a==0: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-2) + s
391
//                         else: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-1-a)
392
// Down  :   index --> b==0 ? (s-1-a) : s*s + s-1 + 4*(b-1)*(s-1) - a
393
// Left  :   index --> (s-1-a)*s + b
394
// Back  :   index --> if b==s-1: s*(s-1-a)
395
//                     if b==0  : 5*s*s -12*s + 8 + (s-1-a)*s
396
//                     else
397
//                        if a==s-1: s*s + 4*(s-2-b)*(s-1)
398
//                        else     : s*s + 4*(s-2-b)*(s-1) + s + (s-2-a)*2
399

  
400
  public String retObjectString()
401
    {
402
    StringBuilder objectString = new StringBuilder();
403
    int layers = getNumLayers();
404
    int len = layers*layers;
405
    int cubitIndex, row, col, color,face;
406

  
407
    final int RIGHT= 0;
408
    final int LEFT = 1;
409
    final int UP   = 2;
410
    final int DOWN = 3;
411
    final int FRONT= 4;
412
    final int BACK = 5;
413

  
414
    // 'I' - interior, theoretically can happen
415
    final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B', 'I'};
416

  
417
    face = UP;
418

  
419
    for(int i=0; i<len; i++)
420
      {
421
      row = i/layers;
422
      col = i%layers;
423

  
424
      cubitIndex = col<layers-1 ? (layers-1)*(layers+4*col) + row : 6*layers*layers - 13*layers + 8 + row;
425
      color = getCubitFaceColorIndex(cubitIndex,face);
426
      objectString.append(FACE_NAMES[color]);
427
      }
428

  
429
    face = RIGHT;
430

  
431
    for(int i=0; i<len; i++)
432
      {
433
      cubitIndex = 6*layers*layers - 12*layers +7 - i;
434
      color = getCubitFaceColorIndex(cubitIndex,face);
435
      objectString.append(FACE_NAMES[color]);
436
      }
437

  
438
    face = FRONT;
439

  
440
    for(int i=0; i<len; i++)
441
      {
442
      row = i/layers;
443
      col = i%layers;
444

  
445
      if( col==layers-1 ) cubitIndex = 6*layers*layers - 11*layers + 6 -i;
446
      else if(   col==0 ) cubitIndex = layers*layers - 1 - i;
447
      else
448
        {
449
        if( row==0 ) cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-2) + layers;
450
        else         cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-1-row);
451
        }
452

  
453
      color = getCubitFaceColorIndex(cubitIndex,face);
454
      objectString.append(FACE_NAMES[color]);
455
      }
456

  
457
    face = DOWN;
458

  
459
    for(int i=0; i<len; i++)
460
      {
461
      row = i/layers;
462
      col = i%layers;
463

  
464
      cubitIndex = col==0 ? layers-1-row : layers*layers + layers-1 + 4*(col-1)*(layers-1) - row;
465
      color = getCubitFaceColorIndex(cubitIndex,face);
466
      objectString.append(FACE_NAMES[color]);
467
      }
468

  
469
    face = LEFT;
470

  
471
    for(int i=0; i<len; i++)
472
      {
473
      row = i/layers;
474
      col = i%layers;
475

  
476
      cubitIndex = (layers-1-row)*layers + col;
477
      color = getCubitFaceColorIndex(cubitIndex,face);
478
      objectString.append(FACE_NAMES[color]);
479
      }
480

  
481
    face = BACK;
482

  
483
    for(int i=0; i<len; i++)
484
      {
485
      row = i/layers;
486
      col = i%layers;
487

  
488
      if( col==layers-1 ) cubitIndex = layers*(layers-1-row);
489
      else if(   col==0 ) cubitIndex = 5*layers*layers - 12*layers + 8 + (layers-1-row)*layers;
490
      else
491
        {
492
        if( row==layers-1 ) cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1);
493
        else                cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1) + layers + 2*(layers-2-row);
494
        }
495

  
496
      color = getCubitFaceColorIndex(cubitIndex,face);
497
      objectString.append(FACE_NAMES[color]);
498
      }
499

  
500
    return objectString.toString();
501
    }
502

  
503 377
///////////////////////////////////////////////////////////////////////////////////////////////////
504 378

  
505 379
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyDiamond.java
604 604
    return true;
605 605
    }
606 606

  
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608
// only needed for solvers - there are no Diamond solvers ATM
609

  
610
  public String retObjectString()
611
    {
612
    return "";
613
    }
614

  
615 607
///////////////////////////////////////////////////////////////////////////////////////////////////
616 608

  
617 609
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyDino.java
256 256
    return BASIC_ANGLE;
257 257
    }
258 258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
// only needed for solvers - there are no Dino solvers ATM)
261

  
262
  public String retObjectString()
263
    {
264
    return "";
265
    }
266

  
267 259
///////////////////////////////////////////////////////////////////////////////////////////////////
268 260

  
269 261
  public int getComplexity(int numLayers)
src/main/java/org/distorted/objects/TwistyHelicopter.java
513 513
    return false;
514 514
    }
515 515

  
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
// only needed for solvers - there are no Helicopter solvers ATM)
518

  
519
  public String retObjectString()
520
    {
521
    return "";
522
    }
523

  
524 516
///////////////////////////////////////////////////////////////////////////////////////////////////
525 517

  
526 518
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyIvy.java
508 508
    return false;
509 509
    }
510 510

  
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512
// only needed for solvers - there are no Ivy solvers ATM)
513

  
514
  public String retObjectString()
515
    {
516
    return "";
517
    }
518

  
519 511
///////////////////////////////////////////////////////////////////////////////////////////////////
520 512

  
521 513
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyJing.java
480 480
    return true;
481 481
    }
482 482

  
483
////////////////////////////////////////////////////////////////////////
484
// only needed for solvers - there are no JingPyraminx solvers ATM)
485

  
486
  public String retObjectString()
487
    {
488
    return "";
489
    }
490

  
491 483
///////////////////////////////////////////////////////////////////////////////////////////////////
492 484

  
493 485
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyMinx.java
557 557
    {
558 558
    return BASIC_ANGLE;
559 559
    }
560

  
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562
// only needed for solvers - there are no Minx solvers ATM)
563

  
564
  public String retObjectString()
565
    {
566
    return "";
567
    }
568 560
}
src/main/java/org/distorted/objects/TwistyObject.java
399 399
      }
400 400
    }
401 401

  
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

  
404
  int getCubitFaceColorIndex(int cubit, int face)
405
    {
406
    Static4D texMap = mMesh.getTextureMap(NUM_FACES*cubit + face);
407

  
408
    int x = (int)(texMap.get0()/texMap.get2());
409
    int y = (int)(texMap.get1()/texMap.get3());
410

  
411
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
412
    }
413

  
414 402
///////////////////////////////////////////////////////////////////////////////////////////////////
415 403
// normal, not bandaged, object.
416 404

  
......
572 560
    factory.printStickerCoords();
573 561
    }
574 562

  
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564

  
565
  public int getCubitFaceColorIndex(int cubit, int face)
566
    {
567
    Static4D texMap = mMesh.getTextureMap(NUM_FACES*cubit + face);
568

  
569
    int x = (int)(texMap.get0()/texMap.get2());
570
    int y = (int)(texMap.get1()/texMap.get3());
571

  
572
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
573
    }
574

  
575 575
///////////////////////////////////////////////////////////////////////////////////////////////////
576 576
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
577 577

  
......
984 984
  public abstract Static3D[] getRotationAxis();
985 985
  public abstract boolean isSolved();
986 986
  public abstract int[] getBasicAngle();
987
  public abstract String retObjectString();
988 987
  public abstract void randomizeNewScramble(int[][] scramble, Random rnd, int curScramble, int totScrambles);
989 988
  public abstract int getObjectName(int numLayers);
990 989
  public abstract int getInventor(int numLayers);
src/main/java/org/distorted/objects/TwistyPyraminx.java
468 468
    return true;
469 469
    }
470 470

  
471
////////////////////////////////////////////////////////////////////////
472
// only needed for solvers - there are no Pyraminx solvers ATM)
473

  
474
  public String retObjectString()
475
    {
476
    return "";
477
    }
478

  
479 471
///////////////////////////////////////////////////////////////////////////////////////////////////
480 472

  
481 473
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyRedi.java
538 538
             CUBITS[19].mQuatIndex == q  );
539 539
    }
540 540

  
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542
// only needed for solvers - there are no Redi solvers ATM)
543

  
544
  public String retObjectString()
545
    {
546
    return "";
547
    }
548

  
549 541
///////////////////////////////////////////////////////////////////////////////////////////////////
550 542

  
551 543
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistyRex.java
685 685
    return true;
686 686
    }
687 687

  
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689
// only needed for solvers - there are no Rex solvers ATM
690

  
691
  public String retObjectString()
692
    {
693
    return "";
694
    }
695

  
696 688
///////////////////////////////////////////////////////////////////////////////////////////////////
697 689

  
698 690
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistySkewb.java
687 687
    return true;
688 688
    }
689 689

  
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
// only needed for solvers - there are no Skewb solvers ATM)
692

  
693
  public String retObjectString()
694
    {
695
    return "";
696
    }
697

  
698 690
///////////////////////////////////////////////////////////////////////////////////////////////////
699 691

  
700 692
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistySquare.java
295 295
    {
296 296
    return BASIC_ANGLE;
297 297
    }
298

  
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
// only needed for solvers - there are no Square solvers ATM)
301

  
302
  public String retObjectString()
303
    {
304
    return "";
305
    }
306

  
307 298
}
src/main/java/org/distorted/objects/TwistyUltimate.java
485 485
    return true;
486 486
    }
487 487

  
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489
// only needed for solvers - there are no Skewb Ultimate solvers ATM)
490

  
491
  public String retObjectString()
492
    {
493
    return "";
494
    }
495

  
496 488
///////////////////////////////////////////////////////////////////////////////////////////////////
497 489

  
498 490
  public int getObjectName(int numLayers)
src/main/java/org/distorted/screens/RubikScreenSolver.java
212 212
          {
213 213
          mSolving = true;
214 214
          TwistyObject object = act.getObject();
215
          String objectString = object.retObjectString();
216
          SolverMain solver = new SolverMain( act.getResources(), mCurrentObject, mCurrentObjectSize, objectString );
215
          SolverMain solver = new SolverMain( act.getResources(), object );
217 216
          solver.start();
218 217
          }
219 218
        }
src/main/java/org/distorted/solvers/SolverMain.java
23 23

  
24 24
import org.distorted.main.R;
25 25
import org.distorted.objects.ObjectList;
26
import org.distorted.objects.TwistyObject;
26 27
import org.distorted.screens.ScreenList;
27 28
import org.distorted.screens.RubikScreenSolver;
28 29

  
......
30 31

  
31 32
public class SolverMain implements Runnable
32 33
{
33
  private final String mObjectPosition;
34 34
  private final Resources mRes;
35
  private final ObjectList mObject;
36
  private final int mSize;
35
  private final TwistyObject mObject;
37 36

  
38 37
///////////////////////////////////////////////////////////////////////////////////////////////////
39 38

  
40
  public SolverMain(Resources res, ObjectList object, int size, String position )
39
  public SolverMain(Resources res, TwistyObject object)
41 40
    {
42
    mRes            = res;
43
    mObject         = object;
44
    mSize           = size;
45
    mObjectPosition = position;
41
    mRes   = res;
42
    mObject= object;
46 43
    }
47 44

  
48 45
///////////////////////////////////////////////////////////////////////////////////////////////////
......
75 72
    if( !org.distorted.solvers.cube3.Search.prepare(mRes) )
76 73
      result= "Error 9";
77 74
    else
78
      result = org.distorted.solvers.cube3.Search.solution(mObjectPosition, 24, 20);
75
      {
76
      String objectPosition = prepareCube3position();
77
      result = org.distorted.solvers.cube3.Search.solution(objectPosition, 24, 20);
78
      }
79 79

  
80 80
    if (result.contains("Error"))
81 81
      {
......
100 100
      }
101 101
    }
102 102

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
// order: Up --> Right --> Front --> Down --> Left --> Back
105
// (because the first implemented Solver - the two-phase Cube3 one - expects such order)
106
//
107
// Solved 3x3x3 Cube maps to "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"
108
//
109
// s : size of the cube; let index = a*s + b    (i.e. a,b = row,column)
110
//
111
// Up    :   index --> b<s-1 ? (s-1)*(s+4b)+a : 6*s*s -13*s +8 +a
112
// Right :   index --> 6*s*s - 12*s + 7 - index
113
// Front :   index --> if b==0  : s*s - 1 - index
114
//                     if b==s-1: 6*s*s -11*s +6 - index
115
//                     else
116
//                         a==0: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-2) + s
117
//                         else: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-1-a)
118
// Down  :   index --> b==0 ? (s-1-a) : s*s + s-1 + 4*(b-1)*(s-1) - a
119
// Left  :   index --> (s-1-a)*s + b
120
// Back  :   index --> if b==s-1: s*(s-1-a)
121
//                     if b==0  : 5*s*s -12*s + 8 + (s-1-a)*s
122
//                     else
123
//                        if a==s-1: s*s + 4*(s-2-b)*(s-1)
124
//                        else     : s*s + 4*(s-2-b)*(s-1) + s + (s-2-a)*2
125

  
126
  private String prepareCube3position()
127
    {
128
    StringBuilder objectString = new StringBuilder();
129
    int layers = mObject.getNumLayers();
130
    int len = layers*layers;
131
    int cubitIndex, row, col, color,face;
132

  
133
    final int RIGHT= 0;
134
    final int LEFT = 1;
135
    final int UP   = 2;
136
    final int DOWN = 3;
137
    final int FRONT= 4;
138
    final int BACK = 5;
139

  
140
    // 'I' - interior, theoretically can happen
141
    final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B', 'I'};
142

  
143
    face = UP;
144

  
145
    for(int i=0; i<len; i++)
146
      {
147
      row = i/layers;
148
      col = i%layers;
149

  
150
      cubitIndex = col<layers-1 ? (layers-1)*(layers+4*col) + row : 6*layers*layers - 13*layers + 8 + row;
151
      color = mObject.getCubitFaceColorIndex(cubitIndex,face);
152
      objectString.append(FACE_NAMES[color]);
153
      }
154

  
155
    face = RIGHT;
156

  
157
    for(int i=0; i<len; i++)
158
      {
159
      cubitIndex = 6*layers*layers - 12*layers +7 - i;
160
      color = mObject.getCubitFaceColorIndex(cubitIndex,face);
161
      objectString.append(FACE_NAMES[color]);
162
      }
163

  
164
    face = FRONT;
165

  
166
    for(int i=0; i<len; i++)
167
      {
168
      row = i/layers;
169
      col = i%layers;
170

  
171
      if( col==layers-1 ) cubitIndex = 6*layers*layers - 11*layers + 6 -i;
172
      else if(   col==0 ) cubitIndex = layers*layers - 1 - i;
173
      else
174
        {
175
        if( row==0 ) cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-2) + layers;
176
        else         cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-1-row);
177
        }
178

  
179
      color = mObject.getCubitFaceColorIndex(cubitIndex,face);
180
      objectString.append(FACE_NAMES[color]);
181
      }
182

  
183
    face = DOWN;
184

  
185
    for(int i=0; i<len; i++)
186
      {
187
      row = i/layers;
188
      col = i%layers;
189

  
190
      cubitIndex = col==0 ? layers-1-row : layers*layers + layers-1 + 4*(col-1)*(layers-1) - row;
191
      color = mObject.getCubitFaceColorIndex(cubitIndex,face);
192
      objectString.append(FACE_NAMES[color]);
193
      }
194

  
195
    face = LEFT;
196

  
197
    for(int i=0; i<len; i++)
198
      {
199
      row = i/layers;
200
      col = i%layers;
201

  
202
      cubitIndex = (layers-1-row)*layers + col;
203
      color = mObject.getCubitFaceColorIndex(cubitIndex,face);
204
      objectString.append(FACE_NAMES[color]);
205
      }
206

  
207
    face = BACK;
208

  
209
    for(int i=0; i<len; i++)
210
      {
211
      row = i/layers;
212
      col = i%layers;
213

  
214
      if( col==layers-1 ) cubitIndex = layers*(layers-1-row);
215
      else if(   col==0 ) cubitIndex = 5*layers*layers - 12*layers + 8 + (layers-1-row)*layers;
216
      else
217
        {
218
        if( row==layers-1 ) cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1);
219
        else                cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1) + layers + 2*(layers-2-row);
220
        }
221

  
222
      color = mObject.getCubitFaceColorIndex(cubitIndex,face);
223
      objectString.append(FACE_NAMES[color]);
224
      }
225

  
226
    return objectString.toString();
227
    }
228

  
103 229
///////////////////////////////////////////////////////////////////////////////////////////////////
104 230

  
105 231
  private void interruptCube3()
......
121 247
    {
122 248
    RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
123 249

  
124
    if( mObject == ObjectList.CUBE && mSize == 3)
250
    if( mObject.getObjectList()==ObjectList.CUBE && mObject.getNumLayers()==3 )
125 251
      {
126 252
      solveCube3(solver);
127 253
      }

Also available in: Unified diff