Project

General

Profile

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

magiccube / src / main / java / org / distorted / helpers / ScrambleStateGraph.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.helpers;
21

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

    
24
public class ScrambleStateGraph
25
{
26
  private final int mTotal, mNumAxis;
27
  private final int[] mNum;
28
  private final int[] mInfo;
29
  private final int[] mTmp;
30
  private final int LEN = 4;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
  public ScrambleStateGraph(int[][] axis)
35
    {
36
    mTmp = new int[LEN];
37

    
38
    mNumAxis = axis.length;
39
    mNum = new int[mNumAxis];
40
    int total =0;
41

    
42
    for(int i=0; i<mNumAxis; i++)
43
      {
44
      mNum[i] = axis[i]==null ? 0 : axis[i].length/(LEN-1);
45
      total += mNum[i];
46
      }
47

    
48
    mTotal = total;
49

    
50
    mInfo = new int[LEN*total];
51
    int start = 0;
52

    
53
    for(int i=0; i<mNumAxis; i++)
54
      {
55
      for(int j=0; j<mNum[i]; j++)
56
        {
57
        mInfo[LEN*j   + start] = i;
58
        mInfo[LEN*j+1 + start] = axis[i][(LEN-1)*j  ];
59
        mInfo[LEN*j+2 + start] = axis[i][(LEN-1)*j+1];
60
        mInfo[LEN*j+3 + start] = axis[i][(LEN-1)*j+2];
61
        }
62

    
63
      start += LEN*mNum[i];
64
      }
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  private int getIndex(int num, int indexExcluded)
70
    {
71
    int current= -1;
72

    
73
    for(int i=0; i<mTotal; i++)
74
      if( mInfo[LEN*i]!=indexExcluded && ++current==num ) return i;
75

    
76
    return -1;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  public int getTotal(int indexExcluded)
82
    {
83
    return ( indexExcluded>=0 && indexExcluded<mNumAxis ) ? mTotal-mNum[indexExcluded] : mTotal;
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  public int[] getInfo(int num, int indexExcluded)
89
    {
90
    int index = getIndex(num,indexExcluded);
91

    
92
    mTmp[0] = mInfo[LEN*index  ];   // axis
93
    mTmp[1] = mInfo[LEN*index+1];   // row
94
    mTmp[2] = mInfo[LEN*index+2];   // angle
95
    mTmp[3] = mInfo[LEN*index+3];   // next state
96

    
97
    return mTmp;
98
    }
99
}
(9-9/14)