Project

General

Profile

Download (9.13 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyBandaged3Plate.java @ eaf87d1d

1 538ee7a6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.objects;
21
22
import android.content.res.Resources;
23
24
import org.distorted.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static4D;
28 eaf87d1d Leszek Koltunski
import org.distorted.helpers.BandagedState;
29 538ee7a6 Leszek Koltunski
import org.distorted.main.R;
30
31 eff371f4 Leszek Koltunski
import java.util.Random;
32
33 538ee7a6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
class TwistyBandaged3Plate extends TwistyBandagedAbstract
36
{
37 e50d4668 Leszek Koltunski
  private int mCurrState;
38
  private boolean mUseX;
39
  private boolean mUseY;
40
  private boolean mUseZ;
41
42
  // The 16 'significant' states of the 3Plate bandaged cube.
43
  // One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which
44
  // rotations of the Cube are possible.
45
  // There are 27 such states in total, but 2 of them are unreachable from the initial State, and
46
  // 9 more and 'insignificant' - i.e. States which only permit rotation along a single axis.
47
  // When doing an automatic scramble, we never want to enter such 'insignificant' states because
48
  // that would mean we'd have to do two rotations in a row along the same axis.
49 69341f31 Leszek Koltunski
  //
50 a4a0b1de Leszek Koltunski
  // 4th State's first 'x' array being '2,-1,10, 2, 2,13' means the following:
51 69341f31 Leszek Koltunski
  // if we are in the 4th state, and make move (2,-1) [i.e. rotation along the X axis, 2nd row, -1 angle]
52
  // then we will land in state 10. If we make move (2,2), we will land in state 13. There are no other
53
  // 'x' moves that lead to a 'significant' state.
54 e50d4668 Leszek Koltunski
55 c0254421 Leszek Koltunski
  private final BandagedState[] mStates = new BandagedState[]
56
    {
57
    new BandagedState( new int[] { 2,-1, 1, 2, 1, 6                  }, new int[] { 0,-1, 5, 0, 1, 3                  }, new int[] { 2,-1, 2, 2, 1, 4                  } ),
58
    new BandagedState( new int[] { 2, 1, 0                           }, null                                           , new int[] { 2, 1,10, 2, 2, 7                  } ),
59
    new BandagedState( null                                           , new int[] { 0,-1,11, 0, 2, 8                  }, new int[] { 2, 1, 0                           } ),
60
    new BandagedState( new int[] { 2, 1,12, 2, 2, 9                  }, new int[] { 0,-1, 0                           }, null                                            ),
61
    new BandagedState( new int[] { 2,-1,10, 2, 2,13                  }, null                                           , new int[] { 2,-1, 0                           } ),
62
    new BandagedState( null                                           , new int[] { 0, 1, 0                           }, new int[] { 2,-1,11, 2, 2,14                  } ),
63
    new BandagedState( new int[] { 2,-1, 0                           }, new int[] { 0, 1,12, 0, 2,15                  }, null                                            ),
64
    new BandagedState( null                                           , new int[] { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, new int[] { 2,-1,10, 2, 2, 1                  } ),
65
    new BandagedState( new int[] { 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, new int[] { 0, 1,11, 0, 2, 2                  }, null                                            ),
66
    new BandagedState( new int[] { 2,-1,12, 2, 2, 3                  }, null                                           , new int[] { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9} ),
67
    new BandagedState( 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                  } ),
68
    new BandagedState( 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                  } ),
69
    new BandagedState( 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} ),
70
    new BandagedState( new int[] { 2, 1,10, 2, 2, 4                  }, new int[] { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, null                                            ),
71
    new BandagedState( new int[] { 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, null                                           , new int[] { 2, 1,11, 2, 2, 5                  } ),
72
    new BandagedState( null                                           , new int[] { 0,-1,12, 0, 2, 6                  }, new int[] { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15} )
73
    };
74 e50d4668 Leszek Koltunski
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
77 68ce0d53 Leszek Koltunski
  private static final float[][] POSITIONS = new float[][]
78
      {
79
       {-1.0f,  1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
80
       { 1.0f,  0.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f, -1.0f,  1.0f,  1.0f,  0.0f},
81
       {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  0.0f,  0.0f, -1.0f, -1.0f,  0.0f, -1.0f,  0.0f},
82
       { 1.0f,  1.0f,  1.0f},
83
       { 1.0f,  0.0f,  1.0f},
84
       { 1.0f, -1.0f,  1.0f},
85
       {-1.0f, -1.0f,  1.0f},
86
       { 0.0f, -1.0f,  1.0f},
87
       { 1.0f, -1.0f,  0.0f},
88
       { 1.0f, -1.0f, -1.0f},
89
       {-1.0f,  1.0f, -1.0f},
90
       {-1.0f,  1.0f,  0.0f},
91
       { 0.0f,  1.0f, -1.0f},
92
       { 0.0f,  1.0f,  0.0f},
93
       {-1.0f,  0.0f, -1.0f},
94
       {-1.0f,  0.0f,  0.0f},
95
       { 0.0f,  0.0f, -1.0f}
96
      };
97 538ee7a6 Leszek Koltunski
98 68ce0d53 Leszek Koltunski
  private static final int[] QUAT_INDICES = new int[] { 1, 3 };
99 538ee7a6 Leszek Koltunski
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 68ce0d53 Leszek Koltunski
  TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
103
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
104 538ee7a6 Leszek Koltunski
    {
105 68ce0d53 Leszek Koltunski
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
106 538ee7a6 Leszek Koltunski
    }
107
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110 68ce0d53 Leszek Koltunski
  float[][] getPositions()
111 538ee7a6 Leszek Koltunski
    {
112 68ce0d53 Leszek Koltunski
    return POSITIONS;
113 538ee7a6 Leszek Koltunski
    }
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117 68ce0d53 Leszek Koltunski
  int[] getQuatIndices()
118 538ee7a6 Leszek Koltunski
    {
119 68ce0d53 Leszek Koltunski
    return QUAT_INDICES;
120 538ee7a6 Leszek Koltunski
    }
121
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
// PUBLIC API
124 eff371f4 Leszek Koltunski
125 5043d5d0 Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
126 bbc6471c Leszek Koltunski
    {
127 5043d5d0 Leszek Koltunski
    if( num==0 )
128 eff371f4 Leszek Koltunski
      {
129 e50d4668 Leszek Koltunski
      mCurrState = 0;
130
      mUseX = true;
131
      mUseY = true;
132
      mUseZ = true;
133 eff371f4 Leszek Koltunski
      }
134
135 e50d4668 Leszek Koltunski
    int total = mStates[mCurrState].getTotal(mUseX,mUseY,mUseZ);
136
    int random= rnd.nextInt(total);
137
    int[] info= mStates[mCurrState].getInfo(random,mUseX,mUseY,mUseZ);
138 eff371f4 Leszek Koltunski
139 e50d4668 Leszek Koltunski
    scramble[num][0] = info[0];
140
    scramble[num][1] = info[1];
141
    scramble[num][2] = info[2];
142
143
    mCurrState = info[3];
144 eff371f4 Leszek Koltunski
145 e50d4668 Leszek Koltunski
    switch(info[0])
146 5043d5d0 Leszek Koltunski
      {
147 e50d4668 Leszek Koltunski
      case 0: mUseX = false; mUseY = true ; mUseZ = true ; break;
148
      case 1: mUseX = true ; mUseY = false; mUseZ = true ; break;
149
      case 2: mUseX = true ; mUseY = true ; mUseZ = false; break;
150 5043d5d0 Leszek Koltunski
      }
151 34440c77 Leszek Koltunski
152
    //android.util.Log.e("D", (info[0]==0 ? "X" : (info[0]==1 ? "Y" : "Z")) + info[2] +" --> "+info[3]);
153 eff371f4 Leszek Koltunski
    }
154
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156 538ee7a6 Leszek Koltunski
157
  public int getObjectName(int numLayers)
158
    {
159
    return R.string.bandaged_3plate;
160
    }
161
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163
164
  public int getInventor(int numLayers)
165
    {
166
    return R.string.bandaged_3plate_inventor;
167
    }
168
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
171
  public int getComplexity(int numLayers)
172
    {
173
    return 8;
174
    }
175
}