Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino4.java @ 121e4a39

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.main.R;
29
import org.distorted.main.RubikSurfaceView;
30

    
31
import java.util.Random;
32

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

    
35
public class TwistyDino4 extends TwistyDino
36
{
37
  private static final int[] mFaceMap = { 4, 2, 2, 4, 0, 2, 1, 4, 0, 0, 1, 1 };
38
  private static final int[][] mScramble;
39

    
40
  static
41
    {
42
    int numQuats = QUATS.length;
43
    int numCenters = CENTERS.length;
44

    
45
    mScramble = new int[numQuats][numCenters];
46

    
47
    for(int q=0; q<numQuats; q++)
48
      for(int c=0; c<numCenters; c++) mScramble[q][c] = computeScramble(q,c);
49
    }
50

    
51
  private final int[] mColors = new int[CENTERS.length];
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  private static int computeScramble(int quatNum, int centerNum)
56
    {
57
    float MAXDIFF = 0.01f;
58
    float[] center= CENTERS[centerNum];
59
    Static4D sc = new Static4D(center[0], center[1], center[2], 1.0f);
60
    Static4D result = RubikSurfaceView.rotateVectorByQuat(sc,QUATS[quatNum]);
61
    int numCenters = CENTERS.length;
62

    
63
    float x = result.get0();
64
    float y = result.get1();
65
    float z = result.get2();
66

    
67
    for(int c=0; c<numCenters; c++)
68
      {
69
      float[] cent = CENTERS[c];
70

    
71
      float qx = cent[0] - x;
72
      float qy = cent[1] - y;
73
      float qz = cent[2] - z;
74

    
75
      if( qx>-MAXDIFF && qx<MAXDIFF &&
76
          qy>-MAXDIFF && qy<MAXDIFF &&
77
          qz>-MAXDIFF && qz<MAXDIFF  ) return c;
78
      }
79

    
80
    return -1;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  TwistyDino4(int size, Static4D quat, DistortedTexture texture,
86
              MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
87
    {
88
    super(size, quat, texture, mesh, effects, moves, ObjectList.DIN4, res, scrWidth);
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  int getFaceColor(int cubit, int cubitface, int size)
94
    {
95
    return (cubitface==0 || cubitface==1) ? mFaceMap[cubit] : NUM_TEXTURES;
96
    }
97

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

    
100
  boolean shouldResetTextureMaps()
101
    {
102
    return true;
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
108
    {
109
    if( num==0 )
110
      {
111
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
112
      scramble[num][1] = (scramble[num][0]==1 || scramble[num][0]==2) ? 0:2;
113
      }
114
    else
115
      {
116
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
117
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
118
      scramble[num][1] = scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1];
119
      }
120

    
121
    switch( rnd.nextInt(2) )
122
      {
123
      case 0: scramble[num][2] = -1; break;
124
      case 1: scramble[num][2] =  1; break;
125
      }
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// Dino4 is solved if and only if groups of cubits
130
// (0,3,7), (1,2,5), (4,8,9), (6,10,11)
131
// or
132
// (0,1,4), (2,3,6), (5,9,10), (7,8,11)
133
// are all the same color.
134

    
135
  public boolean isSolved()
136
    {
137
    int numCenters = CENTERS.length;
138

    
139
    for(int c=0; c<numCenters; c++)
140
      {
141
      int index = mScramble[CUBITS[c].mQuatIndex][c];
142
      mColors[c] = mFaceMap[index];
143
      }
144

    
145
    if( mColors[0]==mColors[3] && mColors[0]==mColors[7] &&
146
        mColors[1]==mColors[2] && mColors[1]==mColors[5] &&
147
        mColors[4]==mColors[8] && mColors[4]==mColors[9]  ) return true;
148

    
149
    if( mColors[0]==mColors[1] && mColors[0]==mColors[4] &&
150
        mColors[2]==mColors[3] && mColors[2]==mColors[6] &&
151
        mColors[5]==mColors[9] && mColors[5]==mColors[10] ) return true;
152

    
153
    return false;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  public int getObjectName(int numLayers)
159
    {
160
    return R.string.din43;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public int getInventor(int numLayers)
166
    {
167
    return R.string.din43_inventor;
168
    }
169
}
(22-22/33)