Project

General

Profile

« Previous | Next » 

Revision e50d4668

Added by Leszek Koltunski about 3 years ago

1) in case of several obejct, we need return to the original max num of scrambles - otherwise the records in the DB do not show.
2) implement proper automatic scrambling of the 2Bar and the 3Plate bandaged cubes.

View differences:

src/main/java/org/distorted/objects/TwistyBandaged3Plate.java
33 33

  
34 34
class TwistyBandaged3Plate extends TwistyBandagedAbstract
35 35
{
36
  private int mCurrState;
37
  private boolean mUseX;
38
  private boolean mUseY;
39
  private boolean mUseZ;
40

  
41
  private static class State
42
    {
43
    private final int mNumX, mNumY, mNumZ;
44
    private final int[] mInfo;
45
    private final int[] mTmp;
46
    private final int LEN = 4;
47

  
48
    State(int[] x, int[] y, int[] z)
49
      {
50
      mTmp = new int[LEN];
51

  
52
      mNumX = x==null ? 0 : x.length/(LEN-1);
53
      mNumY = y==null ? 0 : y.length/(LEN-1);
54
      mNumZ = z==null ? 0 : z.length/(LEN-1);
55

  
56
      mInfo = new int[LEN*(mNumX+mNumY+mNumZ)];
57
      int start = 0;
58

  
59
      for(int i=0; i<mNumX; i++)
60
        {
61
        mInfo[LEN*i   + start] = 0;
62
        mInfo[LEN*i+1 + start] = x[(LEN-1)*i  ];
63
        mInfo[LEN*i+2 + start] = x[(LEN-1)*i+1];
64
        mInfo[LEN*i+3 + start] = x[(LEN-1)*i+2];
65
        }
66

  
67
      start = LEN*mNumX;
68

  
69
      for(int i=0; i<mNumY; i++)
70
        {
71
        mInfo[LEN*i   + start] = 1;
72
        mInfo[LEN*i+1 + start] = y[(LEN-1)*i  ];
73
        mInfo[LEN*i+2 + start] = y[(LEN-1)*i+1];
74
        mInfo[LEN*i+3 + start] = y[(LEN-1)*i+2];
75
        }
76

  
77
      start = LEN*(mNumX+mNumY);
78

  
79
      for(int i=0; i<mNumZ; i++)
80
        {
81
        mInfo[LEN*i   + start] = 2;
82
        mInfo[LEN*i+1 + start] = z[(LEN-1)*i  ];
83
        mInfo[LEN*i+2 + start] = z[(LEN-1)*i+1];
84
        mInfo[LEN*i+3 + start] = z[(LEN-1)*i+2];
85
        }
86
      }
87

  
88
    private int getIndex(int num, boolean useX, boolean useY, boolean useZ)
89
      {
90
      int current= -1, total= mNumX + mNumY + mNumZ;
91

  
92
      for(int i=0; i<total; i++)
93
        {
94
        if( (mInfo[LEN*i]==0 && useX) || (mInfo[LEN*i]==1 && useY) || (mInfo[LEN*i]==2 && useZ) )
95
          {
96
          if( ++current==num ) return i;
97
          }
98
        }
99

  
100
      return -1;
101
      }
102

  
103
    int getTotal(boolean useX, boolean useY, boolean useZ)
104
      {
105
      int total = 0;
106

  
107
      if( useX ) total += mNumX;
108
      if( useY ) total += mNumY;
109
      if( useZ ) total += mNumZ;
110

  
111
      return total;
112
      }
113

  
114
    int[] getInfo(int num, boolean useX, boolean useY, boolean useZ)
115
      {
116
      int index = getIndex(num,useX,useY,useZ);
117

  
118
      mTmp[0] = mInfo[LEN*index  ];   // axis
119
      mTmp[1] = mInfo[LEN*index+1];   // row
120
      mTmp[2] = mInfo[LEN*index+2];   // angle
121
      mTmp[3] = mInfo[LEN*index+3];   // next state
122

  
123
      return mTmp;
124
      }
125
    }
126

  
127
  // The 16 'significant' states of the 3Plate bandaged cube.
128
  // One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which
129
  // rotations of the Cube are possible.
130
  // There are 27 such states in total, but 2 of them are unreachable from the initial State, and
131
  // 9 more and 'insignificant' - i.e. States which only permit rotation along a single axis.
132
  // When doing an automatic scramble, we never want to enter such 'insignificant' states because
133
  // that would mean we'd have to do two rotations in a row along the same axis.
134

  
135
  private final State[] mStates = new State[]
136
      {
137
         new State( new int[] { 2,-1, 1, 2, 1, 6                  }, new int[] { 0,-1, 5, 0, 1, 3                  }, new int[] { 2,-1, 2, 2, 1, 4                  } ),
138
         new State( new int[] { 2, 1, 0                           }, null                                           , new int[] { 2, 1,10, 2, 2, 7                  } ),
139
         new State( null                                           , new int[] { 0,-1,11, 0, 2, 8                  }, new int[] { 2, 1, 0                           } ),
140
         new State( new int[] { 2, 1,12, 2, 2, 9                  }, new int[] { 0,-1, 0                           }, null                                            ),
141
         new State( new int[] { 2,-1,10, 2, 2,13                  }, null                                           , new int[] { 2,-1, 0                           } ),
142
         new State( null                                           , new int[] { 0, 1, 0                           }, new int[] { 2,-1,11, 2, 2,14                  } ),
143
         new State( new int[] { 2,-1, 0                           }, new int[] { 0, 1,12, 0, 2,15                  }, null                                            ),
144
         new State( null                                           , new int[] { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, new int[] { 2,-1,10, 2, 2, 1                  } ),
145
         new State( new int[] { 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, new int[] { 0, 1,11, 0, 2, 2                  }, null                                            ),
146
         new State( new int[] { 2,-1,12, 2, 2, 3                  }, null                                           , new int[] { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9} ),
147
         new State( new int[] { 2,-1,13, 2, 1, 4                  }, new int[] { 2,-2,10, 2,-1,10, 2, 1,10, 2, 2,10}, new int[] { 2,-1, 1, 2, 1, 7                  } ),
148
         new State( new int[] { 0,-2,11, 0,-1,11, 0, 1,11, 0, 2,11}, new int[] { 0,-1, 8, 0, 1, 2                  }, new int[] { 2,-1,14, 2, 1, 5                  } ),
149
         new State( new int[] { 2,-1, 3, 2, 1, 9                  }, new int[] { 0,-1, 6, 0, 1,15                  }, new int[] { 0,-2,12, 0,-1,12, 0, 1,12, 0, 2,12} ),
150
         new State( new int[] { 2, 1,10, 2, 2, 4                  }, new int[] { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, null                                            ),
151
         new State( new int[] { 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, null                                           , new int[] { 2, 1,11, 2, 2, 5                  } ),
152
         new State( null                                           , new int[] { 0, 1,12, 0, 2, 6                  }, new int[] { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15} )
153
      };
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

  
36 157
  TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
37 158
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
38 159
    {
......
105 226

  
106 227
///////////////////////////////////////////////////////////////////////////////////////////////////
107 228
// PUBLIC API
108
// TODO
109 229

  
110 230
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
111 231
    {
112 232
    if( num==0 )
113 233
      {
114
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
115
      }
116
    else
117
      {
118
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
119
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
234
      mCurrState = 0;
235
      mUseX = true;
236
      mUseY = true;
237
      mUseZ = true;
120 238
      }
121 239

  
122
    float rowFloat = rnd.nextFloat();
240
    int total = mStates[mCurrState].getTotal(mUseX,mUseY,mUseZ);
241
    int random= rnd.nextInt(total);
242
    int[] info= mStates[mCurrState].getInfo(random,mUseX,mUseY,mUseZ);
123 243

  
124
    for(int row=0; row<mRowChances.length; row++)
125
      {
126
      if( rowFloat<=mRowChances[row] )
127
        {
128
        scramble[num][1] = row;
129
        break;
130
        }
131
      }
244
    scramble[num][0] = info[0];
245
    scramble[num][1] = info[1];
246
    scramble[num][2] = info[2];
247

  
248
    mCurrState = info[3];
132 249

  
133
    switch( rnd.nextInt(4) )
250
    switch(info[0])
134 251
      {
135
      case 0: scramble[num][2] = -2; break;
136
      case 1: scramble[num][2] = -1; break;
137
      case 2: scramble[num][2] =  1; break;
138
      case 3: scramble[num][2] =  2; break;
252
      case 0: mUseX = false; mUseY = true ; mUseZ = true ; break;
253
      case 1: mUseX = true ; mUseY = false; mUseZ = true ; break;
254
      case 2: mUseX = true ; mUseY = true ; mUseZ = false; break;
139 255
      }
140 256
    }
141 257

  

Also available in: Unified diff