Project

General

Profile

« Previous | Next » 

Revision e50d4668

Added by Leszek Koltunski over 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/ObjectList.java
61 61

  
62 62
  DIAM (
63 63
         new int[][] {
64
                       {2 , 12, R.raw.diamond, R.drawable.ui_small_diam, R.drawable.ui_medium_diam, R.drawable.ui_big_diam, R.drawable.ui_huge_diam} ,
64
                       {2 , 10, R.raw.diamond, R.drawable.ui_small_diam, R.drawable.ui_medium_diam, R.drawable.ui_big_diam, R.drawable.ui_huge_diam} ,
65 65
                     },
66 66
         TwistyDiamond.class,
67 67
         new MovementDiamond(),
......
71 71

  
72 72
  DINO (
73 73
         new int[][] {
74
                       {3 , 12, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
74
                       {3 , 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
75 75
                     },
76 76
         TwistyDino6.class,
77 77
         new MovementDino(),
......
91 91

  
92 92
  REDI (
93 93
         new int[][] {
94
                       {3 , 18, R.raw.redi, R.drawable.ui_small_redi, R.drawable.ui_medium_redi, R.drawable.ui_big_redi, R.drawable.ui_huge_redi} ,
94
                       {3 , 14, R.raw.redi, R.drawable.ui_small_redi, R.drawable.ui_medium_redi, R.drawable.ui_big_redi, R.drawable.ui_huge_redi} ,
95 95
                     },
96 96
         TwistyRedi.class,
97 97
         new MovementRedi(),
......
101 101

  
102 102
  HELI (
103 103
         new int[][] {
104
                       {3 , 20, R.raw.heli, R.drawable.ui_small_heli, R.drawable.ui_medium_heli, R.drawable.ui_big_heli, R.drawable.ui_huge_heli} ,
104
                       {3 , 18, R.raw.heli, R.drawable.ui_small_heli, R.drawable.ui_medium_heli, R.drawable.ui_big_heli, R.drawable.ui_huge_heli} ,
105 105
                     },
106 106
         TwistyHelicopter.class,
107 107
         new MovementHelicopter(),
......
111 111

  
112 112
  SKEW (
113 113
         new int[][] {
114
                       {2 , 12, R.raw.skewb, R.drawable.ui_small_skewb, R.drawable.ui_medium_skewb, R.drawable.ui_big_skewb, R.drawable.ui_huge_skewb} ,
115
                       {3 , 21, R.raw.skewm, R.drawable.ui_small_skewm, R.drawable.ui_medium_skewm, R.drawable.ui_big_skewm, R.drawable.ui_huge_skewm} ,
114
                       {2 , 11, R.raw.skewb, R.drawable.ui_small_skewb, R.drawable.ui_medium_skewb, R.drawable.ui_big_skewb, R.drawable.ui_huge_skewb} ,
115
                       {3 , 17, R.raw.skewm, R.drawable.ui_small_skewm, R.drawable.ui_medium_skewm, R.drawable.ui_big_skewm, R.drawable.ui_huge_skewm} ,
116 116
                     },
117 117
         TwistySkewb.class,
118 118
         new MovementSkewb(),
......
132 132

  
133 133
  REX  (
134 134
         new int[][] {
135
                       {3 , 18, R.raw.rex, R.drawable.ui_small_rex, R.drawable.ui_medium_rex, R.drawable.ui_big_rex, R.drawable.ui_huge_rex} ,
135
                       {3 , 16, R.raw.rex, R.drawable.ui_small_rex, R.drawable.ui_medium_rex, R.drawable.ui_big_rex, R.drawable.ui_huge_rex} ,
136 136
                     },
137 137
         TwistyRex.class,
138 138
         new MovementRex(),
......
152 152

  
153 153
  MEGA (
154 154
         new int[][] {
155
                       {3 , 24, R.raw.mega3, R.drawable.ui_small_mega3, R.drawable.ui_medium_mega3, R.drawable.ui_big_mega3, R.drawable.ui_huge_mega3} ,
155
                       {3 , 21, R.raw.mega3, R.drawable.ui_small_mega3, R.drawable.ui_medium_mega3, R.drawable.ui_big_mega3, R.drawable.ui_huge_mega3} ,
156 156
                       {5 , 35, R.raw.mega5, R.drawable.ui_small_mega5, R.drawable.ui_medium_mega5, R.drawable.ui_big_mega5, R.drawable.ui_huge_mega5} ,
157 157
                     },
158 158
         TwistyMegaminx.class,
src/main/java/org/distorted/objects/TwistyBandaged2Bar.java
99 99

  
100 100
///////////////////////////////////////////////////////////////////////////////////////////////////
101 101
// PUBLIC API
102
// TODO
103 102

  
104 103
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
105 104
    {
106 105
    if( num==0 )
107 106
      {
108
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
107
      int random = rnd.nextInt(4);
108

  
109
      scramble[num][0] = 1;
110
      scramble[num][1] = random>1      ?  2:0;
111
      scramble[num][2] = random%2 == 0 ? -1:1;
109 112
      }
110 113
    else
111 114
      {
112
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
113
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
114
      }
115
      boolean even = ((num%2) == 0);
116
      int angle = rnd.nextInt(4);
115 117

  
116
    float rowFloat = rnd.nextFloat();
118
      scramble[num][0] = even ? 1 : scramble[0][1];
119
      scramble[num][1] = rnd.nextInt(3);
117 120

  
118
    for(int row=0; row<mRowChances.length; row++)
119
      {
120
      if( rowFloat<=mRowChances[row] )
121
      if( even == (scramble[num][1]==1) )
121 122
        {
122
        scramble[num][1] = row;
123
        break;
123
        switch(angle)
124
          {
125
          case 0: scramble[num][2] = -2; break;
126
          case 1: scramble[num][2] = -1; break;
127
          case 2: scramble[num][2] =  1; break;
128
          case 3: scramble[num][2] =  2; break;
129
          }
130
        }
131
      else
132
        {
133
        scramble[num][2] = angle>1 ? 2:-2;
124 134
        }
125
      }
126

  
127
    switch( rnd.nextInt(4) )
128
      {
129
      case 0: scramble[num][2] = -2; break;
130
      case 1: scramble[num][2] = -1; break;
131
      case 2: scramble[num][2] =  1; break;
132
      case 3: scramble[num][2] =  2; break;
133 135
      }
134 136
    }
135 137

  
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