Project

General

Profile

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

magiccube / src / main / java / org / distorted / helpers / BandagedState.java @ eaf87d1d

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.helpers;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
public class BandagedState
25
{
26
  private final int mNumX, mNumY, mNumZ;
27
  private final int[] mInfo;
28
  private final int[] mTmp;
29
  private final int LEN = 4;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
  public BandagedState(int[] x, int[] y, int[] z)
34
    {
35
    mTmp = new int[LEN];
36

    
37
    mNumX = x==null ? 0 : x.length/(LEN-1);
38
    mNumY = y==null ? 0 : y.length/(LEN-1);
39
    mNumZ = z==null ? 0 : z.length/(LEN-1);
40

    
41
    mInfo = new int[LEN*(mNumX+mNumY+mNumZ)];
42
    int start = 0;
43

    
44
    for(int i=0; i<mNumX; i++)
45
      {
46
      mInfo[LEN*i   + start] = 0;
47
      mInfo[LEN*i+1 + start] = x[(LEN-1)*i  ];
48
      mInfo[LEN*i+2 + start] = x[(LEN-1)*i+1];
49
      mInfo[LEN*i+3 + start] = x[(LEN-1)*i+2];
50
      }
51

    
52
    start = LEN*mNumX;
53

    
54
    for(int i=0; i<mNumY; i++)
55
      {
56
      mInfo[LEN*i   + start] = 1;
57
      mInfo[LEN*i+1 + start] = y[(LEN-1)*i  ];
58
      mInfo[LEN*i+2 + start] = y[(LEN-1)*i+1];
59
      mInfo[LEN*i+3 + start] = y[(LEN-1)*i+2];
60
      }
61

    
62
    start = LEN*(mNumX+mNumY);
63

    
64
    for(int i=0; i<mNumZ; i++)
65
      {
66
      mInfo[LEN*i   + start] = 2;
67
      mInfo[LEN*i+1 + start] = z[(LEN-1)*i  ];
68
      mInfo[LEN*i+2 + start] = z[(LEN-1)*i+1];
69
      mInfo[LEN*i+3 + start] = z[(LEN-1)*i+2];
70
      }
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  private int getIndex(int num, boolean useX, boolean useY, boolean useZ)
76
    {
77
    int current= -1, total= mNumX + mNumY + mNumZ;
78

    
79
    for(int i=0; i<total; i++)
80
      {
81
      if( (mInfo[LEN*i]==0 && useX) || (mInfo[LEN*i]==1 && useY) || (mInfo[LEN*i]==2 && useZ) )
82
        {
83
        if( ++current==num ) return i;
84
        }
85
      }
86

    
87
    return -1;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  public int getTotal(boolean useX, boolean useY, boolean useZ)
93
    {
94
    int total = 0;
95

    
96
    if( useX ) total += mNumX;
97
    if( useY ) total += mNumY;
98
    if( useZ ) total += mNumZ;
99

    
100
    return total;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  public int[] getInfo(int num, boolean useX, boolean useY, boolean useZ)
106
    {
107
    int index = getIndex(num,useX,useY,useZ);
108

    
109
    mTmp[0] = mInfo[LEN*index  ];   // axis
110
    mTmp[1] = mInfo[LEN*index+1];   // row
111
    mTmp[2] = mInfo[LEN*index+2];   // angle
112
    mTmp[3] = mInfo[LEN*index+3];   // next state
113

    
114
    return mTmp;
115
    }
116
}
(1-1/2)