Project

General

Profile

« Previous | Next » 

Revision 5f54927b

Added by Leszek Koltunski over 2 years ago

Preparation for local creation of puzzles: remove the 'ObjectType' enum from TwistyObject class.

View differences:

src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandaged3x3.java
43 43

  
44 44
///////////////////////////////////////////////////////////////////////////////////////////////////
45 45

  
46
  public ScrambleStateBandaged3x3(long id)
46
  private ScrambleStateBandaged3x3(long id)
47 47
    {
48 48
    mDistance = -1;
49 49
    mID = id;
......
52 52

  
53 53
///////////////////////////////////////////////////////////////////////////////////////////////////
54 54

  
55
  public static void computeGraph(long id)
55
  private long getID()
56
    {
57
    return mID;
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  private void setID(long id)
63
    {
64
    mID = id;
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  private long getMove(int index)
70
    {
71
    return (index>=0 && index<NUM_MOVES) ? mMoves[index] : INVALID_MOVE;
72
    }
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  private int numAxis()
77
    {
78
    int num = 0;
79

  
80
    if( mMoves[ 0]!=INVALID_MOVE || mMoves[ 1]!=INVALID_MOVE || mMoves[ 2]!=INVALID_MOVE ||
81
        mMoves[ 3]!=INVALID_MOVE || mMoves[ 4]!=INVALID_MOVE || mMoves[ 5]!=INVALID_MOVE ||
82
        mMoves[ 6]!=INVALID_MOVE || mMoves[ 7]!=INVALID_MOVE || mMoves[ 8]!=INVALID_MOVE   ) num++;
83

  
84
    if( mMoves[ 9]!=INVALID_MOVE || mMoves[10]!=INVALID_MOVE || mMoves[11]!=INVALID_MOVE ||
85
        mMoves[12]!=INVALID_MOVE || mMoves[13]!=INVALID_MOVE || mMoves[14]!=INVALID_MOVE ||
86
        mMoves[15]!=INVALID_MOVE || mMoves[16]!=INVALID_MOVE || mMoves[17]!=INVALID_MOVE   ) num++;
87

  
88
    if( mMoves[18]!=INVALID_MOVE || mMoves[19]!=INVALID_MOVE || mMoves[20]!=INVALID_MOVE ||
89
        mMoves[21]!=INVALID_MOVE || mMoves[22]!=INVALID_MOVE || mMoves[23]!=INVALID_MOVE ||
90
        mMoves[24]!=INVALID_MOVE || mMoves[25]!=INVALID_MOVE || mMoves[26]!=INVALID_MOVE   ) num++;
91

  
92
    return num;
93
    }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
  private void setMove(int index, long newMove)
98
    {
99
    if( index>=0 && index<NUM_MOVES ) mMoves[index] = newMove;
100
    }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

  
104
  private String formatMoves()
105
    {
106
    String x = getTable( 0);
107
    String y = getTable( 9);
108
    String z = getTable(18);
109

  
110
    return "    new ScrambleState( new int[][] { "+x+", "+y+", "+z+" } ),";
111
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  private String getTable(int index)
116
    {
117
    long m0 = getMove(index  );
118
    long m1 = getMove(index+1);
119
    long m2 = getMove(index+2);
120
    long m3 = getMove(index+3);
121
    long m4 = getMove(index+4);
122
    long m5 = getMove(index+5);
123
    long m6 = getMove(index+6);
124
    long m7 = getMove(index+7);
125
    long m8 = getMove(index+8);
126

  
127
    String ret = "";
128

  
129
    if( m0!=INVALID_MOVE ) ret += formatRet(ret,0,-1,m0);
130
    if( m1!=INVALID_MOVE ) ret += formatRet(ret,0, 2,m1);
131
    if( m2!=INVALID_MOVE ) ret += formatRet(ret,0, 1,m2);
132
    if( m3!=INVALID_MOVE ) ret += formatRet(ret,1,-1,m3);
133
    if( m4!=INVALID_MOVE ) ret += formatRet(ret,1, 2,m4);
134
    if( m5!=INVALID_MOVE ) ret += formatRet(ret,1, 1,m5);
135
    if( m6!=INVALID_MOVE ) ret += formatRet(ret,2,-1,m6);
136
    if( m7!=INVALID_MOVE ) ret += formatRet(ret,2, 2,m7);
137
    if( m8!=INVALID_MOVE ) ret += formatRet(ret,2, 1,m8);
138

  
139
    return formatL("{" + ret + "}");
140
    }
141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

  
144
  private int[] getMoves(int index)
145
    {
146
    int numValid = 0;
147
    for(int i=index; i<index+9; i++) if( mMoves[i]!=INVALID_MOVE ) numValid++;
148

  
149
    int[] ret = new int[3*numValid];
150

  
151
    long m0 = getMove(index  );
152
    long m1 = getMove(index+1);
153
    long m2 = getMove(index+2);
154
    long m3 = getMove(index+3);
155
    long m4 = getMove(index+4);
156
    long m5 = getMove(index+5);
157
    long m6 = getMove(index+6);
158
    long m7 = getMove(index+7);
159
    long m8 = getMove(index+8);
160

  
161
    int pointer=0;
162

  
163
    if( m0!=INVALID_MOVE ) { ret[pointer]=0; ret[pointer+1]=-1; ret[pointer+2]= (int)m0; pointer+=3; }
164
    if( m1!=INVALID_MOVE ) { ret[pointer]=0; ret[pointer+1]= 2; ret[pointer+2]= (int)m1; pointer+=3; }
165
    if( m2!=INVALID_MOVE ) { ret[pointer]=0; ret[pointer+1]= 1; ret[pointer+2]= (int)m2; pointer+=3; }
166
    if( m3!=INVALID_MOVE ) { ret[pointer]=1; ret[pointer+1]=-1; ret[pointer+2]= (int)m3; pointer+=3; }
167
    if( m4!=INVALID_MOVE ) { ret[pointer]=1; ret[pointer+1]= 2; ret[pointer+2]= (int)m4; pointer+=3; }
168
    if( m5!=INVALID_MOVE ) { ret[pointer]=1; ret[pointer+1]= 1; ret[pointer+2]= (int)m5; pointer+=3; }
169
    if( m6!=INVALID_MOVE ) { ret[pointer]=2; ret[pointer+1]=-1; ret[pointer+2]= (int)m6; pointer+=3; }
170
    if( m7!=INVALID_MOVE ) { ret[pointer]=2; ret[pointer+1]= 2; ret[pointer+2]= (int)m7; pointer+=3; }
171
    if( m8!=INVALID_MOVE ) { ret[pointer]=2; ret[pointer+1]= 1; ret[pointer+2]= (int)m8; pointer+=3; }
172

  
173
    return ret;
174
    }
175

  
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

  
178
  private ScrambleState produceScrambleState()
179
    {
180
    int[] xMoves = getMoves(0);
181
    int[] yMoves = getMoves(9);
182
    int[] zMoves = getMoves(18);
183

  
184
    int[][] moves = { xMoves,yMoves,zMoves };
185

  
186
    return new ScrambleState( moves );
187
    }
188

  
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
// STATIC STUFF
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

  
193
  public static ScrambleState[] computeGraph(long id)
56 194
    {
57 195
    ScrambleStateBandaged3x3 bsg = new ScrambleStateBandaged3x3(id);
58 196
    ArrayList<ScrambleStateBandaged3x3> graph = new ArrayList<>();
......
65 203
    remapGraph(graph);
66 204

  
67 205
    int num = graph.size();
68
    android.util.Log.e("D", "\n"+num+" states\n");
206
    ScrambleState[] ret = new ScrambleState[num];
69 207

  
70 208
    for(int i=0; i<num; i++)
71 209
      {
72
      bsg = graph.get(i);
73
      android.util.Log.e("D", formatMoves(bsg));
210
      ScrambleStateBandaged3x3 ssb = graph.get(i);
211
      ret[i] = ssb.produceScrambleState();
74 212
      }
213

  
214
    return ret;
75 215
    }
76 216

  
77 217
///////////////////////////////////////////////////////////////////////////////////////////////////
......
241 381
    return null;
242 382
    }
243 383

  
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

  
246
  private static String formatMoves(ScrambleStateBandaged3x3 bsg)
247
    {
248
    String x = getTable(bsg, 0);
249
    String y = getTable(bsg, 9);
250
    String z = getTable(bsg,18);
251

  
252
    return "    new ScrambleState( new int[][] { "+x+", "+y+", "+z+" } ),";
253
    }
254

  
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

  
257
  private static String getTable(ScrambleStateBandaged3x3 sc, int index)
258
    {
259
    long m0 = sc.getMove(index  );
260
    long m1 = sc.getMove(index+1);
261
    long m2 = sc.getMove(index+2);
262
    long m3 = sc.getMove(index+3);
263
    long m4 = sc.getMove(index+4);
264
    long m5 = sc.getMove(index+5);
265
    long m6 = sc.getMove(index+6);
266
    long m7 = sc.getMove(index+7);
267
    long m8 = sc.getMove(index+8);
268

  
269
    String ret = "";
270

  
271
    if( m0!=INVALID_MOVE ) ret += formatRet(ret,0,-1,m0);
272
    if( m1!=INVALID_MOVE ) ret += formatRet(ret,0, 2,m1);
273
    if( m2!=INVALID_MOVE ) ret += formatRet(ret,0, 1,m2);
274
    if( m3!=INVALID_MOVE ) ret += formatRet(ret,1,-1,m3);
275
    if( m4!=INVALID_MOVE ) ret += formatRet(ret,1, 2,m4);
276
    if( m5!=INVALID_MOVE ) ret += formatRet(ret,1, 1,m5);
277
    if( m6!=INVALID_MOVE ) ret += formatRet(ret,2,-1,m6);
278
    if( m7!=INVALID_MOVE ) ret += formatRet(ret,2, 2,m7);
279
    if( m8!=INVALID_MOVE ) ret += formatRet(ret,2, 1,m8);
280

  
281
    return formatL("{" + ret + "}");
282
    }
283

  
284 384
///////////////////////////////////////////////////////////////////////////////////////////////////
285 385

  
286 386
  private static String formatRet(String str, int row, int angle, long id)
......
310 410
    return ret;
311 411
    }
312 412

  
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

  
315
  private long getID()
316
    {
317
    return mID;
318
    }
319

  
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

  
322
  private void setID(long id)
323
    {
324
    mID = id;
325
    }
326

  
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

  
329
  private long getMove(int index)
330
    {
331
    return (index>=0 && index<NUM_MOVES) ? mMoves[index] : INVALID_MOVE;
332
    }
333

  
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

  
336
  private int numAxis()
337
    {
338
    int num = 0;
339

  
340
    if( mMoves[ 0]!=INVALID_MOVE || mMoves[ 1]!=INVALID_MOVE || mMoves[ 2]!=INVALID_MOVE ||
341
        mMoves[ 3]!=INVALID_MOVE || mMoves[ 4]!=INVALID_MOVE || mMoves[ 5]!=INVALID_MOVE ||
342
        mMoves[ 6]!=INVALID_MOVE || mMoves[ 7]!=INVALID_MOVE || mMoves[ 8]!=INVALID_MOVE   ) num++;
343

  
344
    if( mMoves[ 9]!=INVALID_MOVE || mMoves[10]!=INVALID_MOVE || mMoves[11]!=INVALID_MOVE ||
345
        mMoves[12]!=INVALID_MOVE || mMoves[13]!=INVALID_MOVE || mMoves[14]!=INVALID_MOVE ||
346
        mMoves[15]!=INVALID_MOVE || mMoves[16]!=INVALID_MOVE || mMoves[17]!=INVALID_MOVE   ) num++;
347

  
348
    if( mMoves[18]!=INVALID_MOVE || mMoves[19]!=INVALID_MOVE || mMoves[20]!=INVALID_MOVE ||
349
        mMoves[21]!=INVALID_MOVE || mMoves[22]!=INVALID_MOVE || mMoves[23]!=INVALID_MOVE ||
350
        mMoves[24]!=INVALID_MOVE || mMoves[25]!=INVALID_MOVE || mMoves[26]!=INVALID_MOVE   ) num++;
351

  
352
    return num;
353
    }
354

  
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

  
357
  private void setMove(int index, long newMove)
358
    {
359
    if( index>=0 && index<NUM_MOVES ) mMoves[index] = newMove;
360
    }
361

  
362 413
///////////////////////////////////////////////////////////////////////////////////////////////////
363 414

  
364 415
  private static long[] createMoves(long id)
......
532 583

  
533 584
    return id;
534 585
    }
535

  
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537 586
/*
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588

  
538 589
  private void printMoves()
539 590
    {
540 591
    String moves = "";
......
567 618

  
568 619
    return ret + "]";
569 620
    }
621

  
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623

  
624
  private static void printGraph(ArrayList<ScrambleStateBandaged3x3> graph)
625
    {
626
    int num = graph.size();
627
    android.util.Log.e("D", "\n"+num+" states\n");
628

  
629
    for(int i=0; i<num; i++)
630
      {
631
      bsg = graph.get(i);
632
      android.util.Log.e("D", bsg.formatMoves());
633
      }
634
    }
570 635
*/
571 636
}

Also available in: Unified diff