Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import org.distorted.helpers.ScrambleStateGraph;
29
import org.distorted.main.R;
30

    
31
import java.util.Random;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
class TwistyBandaged3Plate extends TwistyBandagedAbstract
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
  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

    
96
  private static final int[] QUAT_INDICES = new int[] { 1, 3 };
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
101
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
102
    {
103
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  float[][] getPositions()
109
    {
110
    return POSITIONS;
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  int[] getQuatIndices()
116
    {
117
    return QUAT_INDICES;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
// PUBLIC API
122

    
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
  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
}
(18-18/41)