Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyBandaged3Plate.java @ 8db55f55

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 8db55f55 Leszek Koltunski
import org.distorted.helpers.ScrambleStateGraph;
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 8db55f55 Leszek Koltunski
  private int mIndexExcluded;
39 e50d4668 Leszek Koltunski
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 eae4b3b2 Leszek Koltunski
  // 9 more are 'insignificant' - i.e. States which only permit rotation along a single axis.
45 e50d4668 Leszek Koltunski
  // 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 69341f31 Leszek Koltunski
  //
48 a4a0b1de Leszek Koltunski
  // 4th State's first 'x' array being '2,-1,10, 2, 2,13' means the following:
49 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]
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 e50d4668 Leszek Koltunski
53 8db55f55 Leszek Koltunski
  private final ScrambleStateGraph[] mStates = new ScrambleStateGraph[]
54 c0254421 Leszek Koltunski
    {
55 8db55f55 Leszek Koltunski
    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 c0254421 Leszek Koltunski
    };
72 e50d4668 Leszek Koltunski
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75 68ce0d53 Leszek Koltunski
  private static final float[][] POSITIONS = new float[][]
76
      {
77
       {-1.0f,  1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
78
       { 1.0f,  0.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f, -1.0f,  1.0f,  1.0f,  0.0f},
79
       {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  0.0f,  0.0f, -1.0f, -1.0f,  0.0f, -1.0f,  0.0f},
80
       { 1.0f,  1.0f,  1.0f},
81
       { 1.0f,  0.0f,  1.0f},
82
       { 1.0f, -1.0f,  1.0f},
83
       {-1.0f, -1.0f,  1.0f},
84
       { 0.0f, -1.0f,  1.0f},
85
       { 1.0f, -1.0f,  0.0f},
86
       { 1.0f, -1.0f, -1.0f},
87
       {-1.0f,  1.0f, -1.0f},
88
       {-1.0f,  1.0f,  0.0f},
89
       { 0.0f,  1.0f, -1.0f},
90
       { 0.0f,  1.0f,  0.0f},
91
       {-1.0f,  0.0f, -1.0f},
92
       {-1.0f,  0.0f,  0.0f},
93
       { 0.0f,  0.0f, -1.0f}
94
      };
95 538ee7a6 Leszek Koltunski
96 68ce0d53 Leszek Koltunski
  private static final int[] QUAT_INDICES = new int[] { 1, 3 };
97 538ee7a6 Leszek Koltunski
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100 68ce0d53 Leszek Koltunski
  TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
101
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
102 538ee7a6 Leszek Koltunski
    {
103 68ce0d53 Leszek Koltunski
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
104 538ee7a6 Leszek Koltunski
    }
105
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108 68ce0d53 Leszek Koltunski
  float[][] getPositions()
109 538ee7a6 Leszek Koltunski
    {
110 68ce0d53 Leszek Koltunski
    return POSITIONS;
111 538ee7a6 Leszek Koltunski
    }
112
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115 68ce0d53 Leszek Koltunski
  int[] getQuatIndices()
116 538ee7a6 Leszek Koltunski
    {
117 68ce0d53 Leszek Koltunski
    return QUAT_INDICES;
118 538ee7a6 Leszek Koltunski
    }
119
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
// PUBLIC API
122 eff371f4 Leszek Koltunski
123 9f171eba Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
124 bbc6471c Leszek Koltunski
    {
125 9f171eba Leszek Koltunski
    if( curr==0 )
126 eff371f4 Leszek Koltunski
      {
127 8db55f55 Leszek Koltunski
      mCurrState     = 0;
128
      mIndexExcluded =-1;
129 eff371f4 Leszek Koltunski
      }
130
131 8db55f55 Leszek Koltunski
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
132 e50d4668 Leszek Koltunski
    int random= rnd.nextInt(total);
133 8db55f55 Leszek Koltunski
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
134 eff371f4 Leszek Koltunski
135 9f171eba Leszek Koltunski
    scramble[curr][0] = info[0];
136
    scramble[curr][1] = info[1];
137
    scramble[curr][2] = info[2];
138 e50d4668 Leszek Koltunski
139 8db55f55 Leszek Koltunski
    mCurrState     = info[3];
140
    mIndexExcluded = info[0];
141 eff371f4 Leszek Koltunski
    }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144 538ee7a6 Leszek Koltunski
145
  public int getObjectName(int numLayers)
146
    {
147
    return R.string.bandaged_3plate;
148
    }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152
  public int getInventor(int numLayers)
153
    {
154
    return R.string.bandaged_3plate_inventor;
155
    }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159
  public int getComplexity(int numLayers)
160
    {
161
    return 8;
162
    }
163
}