Project

General

Profile

« Previous | Next » 

Revision 38589947

Added by Leszek Koltunski about 3 years ago

Unify scrambling across all 4 bandaged objects.

View differences:

src/main/java/org/distorted/objects/TwistyBandaged2Bar.java
21 21

  
22 22
import android.content.res.Resources;
23 23

  
24
import org.distorted.helpers.ScrambleStateGraph;
24 25
import org.distorted.library.main.DistortedEffects;
25 26
import org.distorted.library.main.DistortedTexture;
26 27
import org.distorted.library.mesh.MeshSquare;
......
67 68
                     DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
68 69
    {
69 70
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN2, res, scrWidth);
71

  
72
    mStates = new ScrambleStateGraph[]
73
      {
74
      new ScrambleStateGraph( new int[][] { {}                                          , {0,1,1, 0,-1,1, 2,1,2, 2,-1,2}, {} }),
75
      new ScrambleStateGraph( new int[][] { {0,-1,1, 0,1,1, 0,2,1, 2,-1,1, 2,1,1, 2,2,1}, {0,2,1, 2,2,1}                , {} }),
76
      new ScrambleStateGraph( new int[][] { {}, {0,2,2, 2,2,2}                , {0,-1,2, 0,1,2, 0,2,2, 2,-1,2, 2,1,2, 2,2,2} })
77
      };
70 78
    }
71 79

  
72 80
///////////////////////////////////////////////////////////////////////////////////////////////////
......
86 94
///////////////////////////////////////////////////////////////////////////////////////////////////
87 95
// PUBLIC API
88 96

  
89
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
90
    {
91
    if( curr==0 )
92
      {
93
      int random = rnd.nextInt(4);
94

  
95
      scramble[curr][0] = 1;
96
      scramble[curr][1] = random>1      ?  2:0;
97
      scramble[curr][2] = random%2 == 0 ? -1:1;
98
      }
99
    else
100
      {
101
      boolean even = ((curr%2) == 0);
102
      int angle = rnd.nextInt(4);
103

  
104
      scramble[curr][0] = even ? 1 : scramble[0][1];
105
      scramble[curr][1] = rnd.nextInt(3);
106

  
107
      if( even == (scramble[curr][1]==1) )
108
        {
109
        switch(angle)
110
          {
111
          case 0: scramble[curr][2] = -2; break;
112
          case 1: scramble[curr][2] = -1; break;
113
          case 2: scramble[curr][2] =  1; break;
114
          case 3: scramble[curr][2] =  2; break;
115
          }
116
        }
117
      else
118
        {
119
        scramble[curr][2] = angle>1 ? 2:-2;
120
        }
121
      }
122
    }
123

  
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

  
126 97
  public int getObjectName(int numLayers)
127 98
    {
128 99
    return R.string.bandaged_2bar;
src/main/java/org/distorted/objects/TwistyBandaged3Plate.java
34 34

  
35 35
class TwistyBandaged3Plate extends TwistyBandagedAbstract
36 36
{
37
  private int mCurrState;
38
  private int mIndexExcluded;
39

  
40
  // The 16 'significant' states of the 3Plate bandaged cube.
41
  // One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which
42
  // rotations of the Cube are possible.
43
  // There are 27 such states in total, but 2 of them are unreachable from the initial State, and
44
  // 9 more are 'insignificant' - i.e. States which only permit rotation along a single axis.
45
  // When doing an automatic scramble, we never want to enter such 'insignificant' states because
46
  // that would mean we'd have to do two rotations in a row along the same axis.
47
  //
48
  // 4th State's first 'x' array being '2,-1,10, 2, 2,13' means the following:
49
  // if we are in the 4th state, and make move (2,-1) [i.e. rotation along the X axis, 2nd row, -1 angle]
50
  // then we will land in state 10. If we make move (2,2), we will land in state 13. There are no other
51
  // 'x' moves that lead to a 'significant' state.
52

  
53
  private final ScrambleStateGraph[] mStates = new ScrambleStateGraph[]
54
    {
55
    new ScrambleStateGraph( new int[][] {{ 2,-1, 1, 2, 1, 6                  }, { 0,-1, 5, 0, 1, 3                  }, { 2,-1, 2, 2, 1, 4                  }} ),
56
    new ScrambleStateGraph( new int[][] {{ 2, 1, 0                           }, {                                   }, { 2, 1,10, 2, 2, 7                  }} ),
57
    new ScrambleStateGraph( new int[][] {{                                   }, { 0,-1,11, 0, 2, 8                  }, { 2, 1, 0                           }} ),
58
    new ScrambleStateGraph( new int[][] {{ 2, 1,12, 2, 2, 9                  }, { 0,-1, 0                           }, {                                   }} ),
59
    new ScrambleStateGraph( new int[][] {{ 2,-1,10, 2, 2,13                  }, {                                   }, { 2,-1, 0                           }} ),
60
    new ScrambleStateGraph( new int[][] {{                                   }, { 0, 1, 0                           }, { 2,-1,11, 2, 2,14                  }} ),
61
    new ScrambleStateGraph( new int[][] {{ 2,-1, 0                           }, { 0, 1,12, 0, 2,15                  }, {                                   }} ),
62
    new ScrambleStateGraph( new int[][] {{                                   }, { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, { 2,-1,10, 2, 2, 1                  }} ),
63
    new ScrambleStateGraph( new int[][] {{ 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, { 0, 1,11, 0, 2, 2                  }, {                                   }} ),
64
    new ScrambleStateGraph( new int[][] {{ 2,-1,12, 2, 2, 3                  }, {                                   }, { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9}} ),
65
    new ScrambleStateGraph( new int[][] {{ 2,-1,13, 2, 1, 4                  }, { 2,-2,10, 2,-1,10, 2, 1,10, 2, 2,10}, { 2,-1, 1, 2, 1, 7                  }} ),
66
    new ScrambleStateGraph( new int[][] {{ 0,-2,11, 0,-1,11, 0, 1,11, 0, 2,11}, { 0,-1, 8, 0, 1, 2                  }, { 2,-1,14, 2, 1, 5                  }} ),
67
    new ScrambleStateGraph( new int[][] {{ 2,-1, 3, 2, 1, 9                  }, { 0,-1, 6, 0, 1,15                  }, { 0,-2,12, 0,-1,12, 0, 1,12, 0, 2,12}} ),
68
    new ScrambleStateGraph( new int[][] {{ 2, 1,10, 2, 2, 4                  }, { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, {                                   }} ),
69
    new ScrambleStateGraph( new int[][] {{ 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, {                                   }, { 2, 1,11, 2, 2, 5                  }} ),
70
    new ScrambleStateGraph( new int[][] {{                                   }, { 0,-1,12, 0, 2, 6                  }, { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15}} )
71
    };
72

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

  
75 37
  private static final float[][] POSITIONS = new float[][]
76 38
      {
77 39
       {-1.0f,  1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
......
101 63
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
102 64
    {
103 65
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
66

  
67
    mStates = new ScrambleStateGraph[]
68
    {
69
    new ScrambleStateGraph( new int[][] {{ 2,-1, 1, 2, 1, 6                  }, { 0,-1, 5, 0, 1, 3                  }, { 2,-1, 2, 2, 1, 4                  }} ),
70
    new ScrambleStateGraph( new int[][] {{ 2, 1, 0                           }, {                                   }, { 2, 1,10, 2, 2, 7                  }} ),
71
    new ScrambleStateGraph( new int[][] {{                                   }, { 0,-1,11, 0, 2, 8                  }, { 2, 1, 0                           }} ),
72
    new ScrambleStateGraph( new int[][] {{ 2, 1,12, 2, 2, 9                  }, { 0,-1, 0                           }, {                                   }} ),
73
    new ScrambleStateGraph( new int[][] {{ 2,-1,10, 2, 2,13                  }, {                                   }, { 2,-1, 0                           }} ),
74
    new ScrambleStateGraph( new int[][] {{                                   }, { 0, 1, 0                           }, { 2,-1,11, 2, 2,14                  }} ),
75
    new ScrambleStateGraph( new int[][] {{ 2,-1, 0                           }, { 0, 1,12, 0, 2,15                  }, {                                   }} ),
76
    new ScrambleStateGraph( new int[][] {{                                   }, { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, { 2,-1,10, 2, 2, 1                  }} ),
77
    new ScrambleStateGraph( new int[][] {{ 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, { 0, 1,11, 0, 2, 2                  }, {                                   }} ),
78
    new ScrambleStateGraph( new int[][] {{ 2,-1,12, 2, 2, 3                  }, {                                   }, { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9}} ),
79
    new ScrambleStateGraph( new int[][] {{ 2,-1,13, 2, 1, 4                  }, { 2,-2,10, 2,-1,10, 2, 1,10, 2, 2,10}, { 2,-1, 1, 2, 1, 7                  }} ),
80
    new ScrambleStateGraph( new int[][] {{ 0,-2,11, 0,-1,11, 0, 1,11, 0, 2,11}, { 0,-1, 8, 0, 1, 2                  }, { 2,-1,14, 2, 1, 5                  }} ),
81
    new ScrambleStateGraph( new int[][] {{ 2,-1, 3, 2, 1, 9                  }, { 0,-1, 6, 0, 1,15                  }, { 0,-2,12, 0,-1,12, 0, 1,12, 0, 2,12}} ),
82
    new ScrambleStateGraph( new int[][] {{ 2, 1,10, 2, 2, 4                  }, { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, {                                   }} ),
83
    new ScrambleStateGraph( new int[][] {{ 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, {                                   }, { 2, 1,11, 2, 2, 5                  }} ),
84
    new ScrambleStateGraph( new int[][] {{                                   }, { 0,-1,12, 0, 2, 6                  }, { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15}} )
85
    };
104 86
    }
105 87

  
106 88
///////////////////////////////////////////////////////////////////////////////////////////////////
......
120 102
///////////////////////////////////////////////////////////////////////////////////////////////////
121 103
// PUBLIC API
122 104

  
123
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
124
    {
125
    if( curr==0 )
126
      {
127
      mCurrState     = 0;
128
      mIndexExcluded =-1;
129
      }
130

  
131
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
132
    int random= rnd.nextInt(total);
133
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
134

  
135
    scramble[curr][0] = info[0];
136
    scramble[curr][1] = info[1];
137
    scramble[curr][2] = info[2];
138

  
139
    mCurrState     = info[3];
140
    mIndexExcluded = info[0];
141
    }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145 105
  public int getObjectName(int numLayers)
146 106
    {
147 107
    return R.string.bandaged_3plate;
src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
23 23

  
24 24
import org.distorted.helpers.ObjectShape;
25 25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleStateGraph;
26 27
import org.distorted.library.main.DistortedEffects;
27 28
import org.distorted.library.main.DistortedTexture;
28 29
import org.distorted.library.mesh.MeshSquare;
29 30
import org.distorted.library.type.Static3D;
30 31
import org.distorted.library.type.Static4D;
31 32

  
33
import java.util.Random;
34

  
32 35
///////////////////////////////////////////////////////////////////////////////////////////////////
33 36

  
34 37
abstract class TwistyBandagedAbstract extends TwistyObject
......
148 151
      }
149 152
    }
150 153

  
154
  private int mCurrState;
155
  private int mIndexExcluded;
156
  ScrambleStateGraph[] mStates;
157

  
151 158
///////////////////////////////////////////////////////////////////////////////////////////////////
152 159

  
153 160
  TwistyBandagedAbstract(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
......
443 450
///////////////////////////////////////////////////////////////////////////////////////////////////
444 451
// PUBLIC API
445 452

  
453
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
454
    {
455
    if( curr==0 )
456
      {
457
      mCurrState     = 0;
458
      mIndexExcluded =-1;
459
      }
460

  
461
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
462
    int random= rnd.nextInt(total);
463
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
464

  
465
    scramble[curr][0] = info[0];
466
    scramble[curr][1] = info[1];
467
    scramble[curr][2] = info[2];
468

  
469
    mCurrState     = info[3];
470
    mIndexExcluded = info[0];
471
    }
472

  
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

  
446 475
  public Static3D[] getRotationAxis()
447 476
    {
448 477
    return ROT_AXIS;
src/main/java/org/distorted/objects/TwistyBandagedEvil.java
34 34

  
35 35
class TwistyBandagedEvil extends TwistyBandagedAbstract
36 36
{
37
   private int mCurrState;
38
   private int mIndexExcluded;
37
  private static final float[][] POSITIONS = new float[][]
38
      {
39
        { 1.0f,  1.0f, -1.0f},
40
        {-1.0f, -1.0f,  0.0f, -1.0f,  0.0f,  0.0f, 0.0f, -1.0f,  0.0f,  0.0f,  0.0f,  0.0f},
41
        {-1.0f,  1.0f, -1.0f,  0.0f,  1.0f, -1.0f},
42
        {-1.0f,  0.0f, -1.0f,  0.0f,  0.0f, -1.0f},
43
        {-1.0f, -1.0f, -1.0f,  0.0f, -1.0f, -1.0f},
44
        {-1.0f,  1.0f,  0.0f, -1.0f,  1.0f,  1.0f},
45
        { 0.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f},
46
        { 1.0f,  1.0f,  0.0f,  1.0f,  1.0f,  1.0f},
47
        {-1.0f, -1.0f,  1.0f, -1.0f,  0.0f,  1.0f},
48
        { 0.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
49
        { 1.0f, -1.0f,  1.0f,  1.0f,  0.0f,  1.0f},
50
        { 1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  0.0f},
51
        { 1.0f, -1.0f, -1.0f,  1.0f,  0.0f, -1.0f}
52
      };
39 53

  
40
   // The list of all 'significant' states of the Evil Cube, just like in the 3Plate Cube class.
41
   // This time the list got computed automatically - by the ScrambleStateGraphProducer.computeGraph().
54
  private static final int[] QUAT_INDICES = new int[]
55
      { 0, 1, 0, 0, 0, 2, 2, 2, 3, 3, 3, 3, 3 };
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
  TwistyBandagedEvil(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
60
                     DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
61
    {
62
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN4, res, scrWidth);
42 63

  
43
   private final ScrambleStateGraph[] mStates = new ScrambleStateGraph[]
64
    mStates = new ScrambleStateGraph[]
44 65
     {
45 66
     new ScrambleStateGraph( new int[][] {{2, 1,  1,2,-1,  2}         , {2, 2,142,2,-1, 28}         , {0, 1,114}          }),   //0
46 67
     new ScrambleStateGraph( new int[][] {{2, 2,  2}                  , {2,-1,143}                  , {}                  }),
......
187 208
     new ScrambleStateGraph( new int[][] {{}                          , {2, 1, 28}                  , {2,-1, 18}          }),
188 209
     new ScrambleStateGraph( new int[][] {{}                          , {2, 1,  1}                  , {2, 2, 12,2,-1, 13} })
189 210
     };
190

  
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

  
193
  private static final float[][] POSITIONS = new float[][]
194
      {
195
        { 1.0f,  1.0f, -1.0f},
196
        {-1.0f, -1.0f,  0.0f, -1.0f,  0.0f,  0.0f, 0.0f, -1.0f,  0.0f,  0.0f,  0.0f,  0.0f},
197
        {-1.0f,  1.0f, -1.0f,  0.0f,  1.0f, -1.0f},
198
        {-1.0f,  0.0f, -1.0f,  0.0f,  0.0f, -1.0f},
199
        {-1.0f, -1.0f, -1.0f,  0.0f, -1.0f, -1.0f},
200
        {-1.0f,  1.0f,  0.0f, -1.0f,  1.0f,  1.0f},
201
        { 0.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f},
202
        { 1.0f,  1.0f,  0.0f,  1.0f,  1.0f,  1.0f},
203
        {-1.0f, -1.0f,  1.0f, -1.0f,  0.0f,  1.0f},
204
        { 0.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
205
        { 1.0f, -1.0f,  1.0f,  1.0f,  0.0f,  1.0f},
206
        { 1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  0.0f},
207
        { 1.0f, -1.0f, -1.0f,  1.0f,  0.0f, -1.0f}
208
      };
209

  
210
  private static final int[] QUAT_INDICES = new int[]
211
      { 0, 1, 0, 0, 0, 2, 2, 2, 3, 3, 3, 3, 3 };
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  TwistyBandagedEvil(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
216
                     DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
217
    {
218
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN4, res, scrWidth);
219 211
    }
220 212

  
221 213
///////////////////////////////////////////////////////////////////////////////////////////////////
......
235 227
///////////////////////////////////////////////////////////////////////////////////////////////////
236 228
// PUBLIC API
237 229

  
238
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
239
    {
240
    if( curr==0 )
241
      {
242
      mCurrState     = 0;
243
      mIndexExcluded =-1;
244
      }
245

  
246
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
247
    int random= rnd.nextInt(total);
248
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
249

  
250
    scramble[curr][0] = info[0];
251
    scramble[curr][1] = info[1];
252
    scramble[curr][2] = info[2];
253

  
254
    mCurrState     = info[3];
255
    mIndexExcluded = info[0];
256
    }
257

  
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

  
260 230
  public int getObjectName(int numLayers)
261 231
    {
262 232
    return R.string.bandaged_evil;
src/main/java/org/distorted/objects/TwistyBandagedFused.java
21 21

  
22 22
import android.content.res.Resources;
23 23

  
24
import org.distorted.helpers.ScrambleStateGraph;
24 25
import org.distorted.library.main.DistortedEffects;
25 26
import org.distorted.library.main.DistortedTexture;
26 27
import org.distorted.library.mesh.MeshSquare;
......
72 73
                      DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
73 74
    {
74 75
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN1, res, scrWidth);
76

  
77
    mStates = new ScrambleStateGraph[]
78
      {
79
      new ScrambleStateGraph( new int[][] {
80
                                           {0,-1,0, 0,1,0, 0,2,0, 2,-1,0, 2,1,0, 2,2,0},
81
                                           {0,-1,0, 0,1,0, 0,2,0, 2,-1,0, 2,1,0, 2,2,0},
82
                                           {0,-1,0, 0,1,0, 0,2,0, 2,-1,0, 2,1,0, 2,2,0},
83
                                          }
84
                            )
85
      };
75 86
    }
76 87

  
77 88
///////////////////////////////////////////////////////////////////////////////////////////////////
......
89 100
    }
90 101

  
91 102
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
94
    {
95
    if( curr==0 )
96
      {
97
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
98
      }
99
    else
100
      {
101
      int newVector = rnd.nextInt(NUM_AXIS -1);
102
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
103
      }
104

  
105
    float rowFloat = rnd.nextFloat();
106
    int numLayers = getNumLayers();
107

  
108
    for(int row=0; row<numLayers; row++)
109
      {
110
      if( rowFloat*numLayers <= row+1 )
111
        {
112
        scramble[curr][1] = row;
113
        break;
114
        }
115
      }
116

  
117
    switch( rnd.nextInt(4) )
118
      {
119
      case 0: scramble[curr][2] = -2; break;
120
      case 1: scramble[curr][2] = -1; break;
121
      case 2: scramble[curr][2] =  1; break;
122
      case 3: scramble[curr][2] =  2; break;
123
      }
124
    }
125

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
103
// PUBLIC APi
127 104

  
128 105
  public int getObjectName(int numLayers)
129 106
    {

Also available in: Unified diff