Project

General

Profile

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

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

1 eaee1ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6fd4a72c Leszek Koltunski
import org.distorted.main.R;
29 2067efd8 Leszek Koltunski
30
import java.util.Random;
31
32 eaee1ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34 9c2f0c91 Leszek Koltunski
public class TwistyDino4 extends TwistyDino
35 eaee1ddc Leszek Koltunski
{
36
  private static final int[] mFaceMap = {4,4, 2,2, 2,2, 4,4,
37
                                         0,0, 2,2, 1,1, 4,4,
38
                                         0,0, 0,0, 1,1, 1,1 };
39
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42 9c2f0c91 Leszek Koltunski
  TwistyDino4(int size, Static4D quat, DistortedTexture texture,
43
              MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
44 eaee1ddc Leszek Koltunski
    {
45 9c2f0c91 Leszek Koltunski
    super(size, quat, texture, mesh, effects, moves, ObjectList.DIN4, res, scrWidth);
46 eaee1ddc Leszek Koltunski
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50
  int getFaceColor(int cubit, int cubitface, int size)
51
    {
52
    switch(cubitface)
53
      {
54
      case 0 : return mFaceMap[2*cubit];
55
      case 1 : return mFaceMap[2*cubit+1];
56
      default: return NUM_FACES;
57
      }
58
    }
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62
  boolean shouldResetTextureMaps()
63
    {
64
    return true;
65
    }
66
67 2067efd8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69 5043d5d0 Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
70 2067efd8 Leszek Koltunski
    {
71 5043d5d0 Leszek Koltunski
    if( num==0 )
72 bbc6471c Leszek Koltunski
      {
73 5043d5d0 Leszek Koltunski
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
74
      scramble[num][1] = (scramble[num][0]==1 || scramble[num][0]==2) ? 0:2;
75 bbc6471c Leszek Koltunski
      }
76
    else
77
      {
78
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
79 5043d5d0 Leszek Koltunski
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
80
      scramble[num][1] = scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1];
81 bbc6471c Leszek Koltunski
      }
82
83 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
84
      {
85
      case 0: scramble[num][2] = -1; break;
86
      case 1: scramble[num][2] =  1; break;
87
      }
88 2067efd8 Leszek Koltunski
    }
89
90 eaee1ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
91 ece1b58d Leszek Koltunski
// Dino4 is solved if and only if the four groups of three same-colored cubits are each 'together'
92
// (actually we need to check only 3 first groups - if those are correct, the fourth one also needs
93
// to be correct).
94 eaee1ddc Leszek Koltunski
//
95 ece1b58d Leszek Koltunski
// White group : (X,Y,Z) = 10,11,6
96
// Red group   : (X,Y,Z) = 0,3,7
97
// Blue group  : (X,Y,Z) = 2,1,5
98
// Yellow group: (X,Y,Z) = 8,9,4
99
//
100
// A group of 3 cubits is 'together' if and only if they are all rotated with one quat - but we cannot
101
// forget that the whole Dino can be mirrored! (so then qY = qX*Q2 and qZ = qX*Q8 )
102
//
103
// X cubits: 0, 2, 8, 10
104
// Y cubits: 1, 3, 9, 11
105
// Z cubits: 4, 5, 6, 7
106 eaee1ddc Leszek Koltunski
107
  public boolean isSolved()
108
    {
109 ece1b58d Leszek Koltunski
    int redX = CUBITS[0].mQuatIndex;
110
    int bluX = CUBITS[2].mQuatIndex;
111
    int yelX = CUBITS[8].mQuatIndex;
112
113
    if (CUBITS[3].mQuatIndex == redX && CUBITS[7].mQuatIndex == redX &&
114
        CUBITS[1].mQuatIndex == bluX && CUBITS[5].mQuatIndex == bluX &&
115
        CUBITS[9].mQuatIndex == yelX && CUBITS[4].mQuatIndex == yelX  ) return true;
116 eaee1ddc Leszek Koltunski
117 ece1b58d Leszek Koltunski
    if (CUBITS[3].mQuatIndex != mulQuat(redX,2)) return false;
118
    if (CUBITS[7].mQuatIndex != mulQuat(redX,8)) return false;
119
    if (CUBITS[1].mQuatIndex != mulQuat(bluX,2)) return false;
120
    if (CUBITS[5].mQuatIndex != mulQuat(bluX,8)) return false;
121
    if (CUBITS[9].mQuatIndex != mulQuat(yelX,2)) return false;
122
    if (CUBITS[4].mQuatIndex != mulQuat(yelX,8)) return false;
123
124
    return true;
125 eaee1ddc Leszek Koltunski
    }
126 6fd4a72c Leszek Koltunski
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129
  public int getObjectName(int numLayers)
130
    {
131
    return R.string.din43;
132
    }
133
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
136
  public int getInventor(int numLayers)
137
    {
138
    return R.string.din43_inventor;
139
    }
140 eaee1ddc Leszek Koltunski
}