Revision 9ba7f3f6
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java | ||
---|---|---|
22 | 22 |
private final int mType; |
23 | 23 |
private final int mNumAxis; |
24 | 24 |
private final int[] mNumLayers; |
25 |
private final int[][] mAlgorithms; |
|
25 | 26 |
|
26 | 27 |
// type=0, i.e. main |
27 | 28 |
private int mCurrState; |
28 |
private int mIndexExcluded;
|
|
29 |
private int mAxisExcluded;
|
|
29 | 30 |
private int[][] mScrambleTable; |
30 | 31 |
private int[] mNumOccurences; |
31 | 32 |
|
... | ... | |
49 | 50 |
|
50 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 52 |
|
52 |
public ObjectScrambler(int type, int numAxis, int[] numLayers, ScrambleState[] states)
|
|
53 |
public ObjectScrambler(int type, int numAxis, int[] numLayers, int[][] algorithms, int[][] edges)
|
|
53 | 54 |
{ |
54 |
mType = type; |
|
55 |
mNumAxis = numAxis; |
|
56 |
mNumLayers = numLayers; |
|
57 |
mStates = states; |
|
55 |
mType = type; |
|
56 |
mNumAxis = numAxis; |
|
57 |
mNumLayers = numLayers; |
|
58 |
mAlgorithms = algorithms; |
|
59 |
|
|
60 |
if( edges!=null ) |
|
61 |
{ |
|
62 |
int numEdges = edges.length; |
|
63 |
mStates = new ScrambleState[numEdges]; |
|
64 |
for(int i=0; i<numEdges; i++) mStates[i] = new ScrambleState(edges[i],algorithms); |
|
65 |
} |
|
66 |
else mStates = null; |
|
58 | 67 |
|
59 | 68 |
if( mType==1 ) |
60 | 69 |
{ |
... | ... | |
68 | 77 |
|
69 | 78 |
private void initializeScrambling() |
70 | 79 |
{ |
71 |
if( mScrambleTable ==null )
|
|
80 |
if( mScrambleTable==null ) |
|
72 | 81 |
{ |
73 | 82 |
mScrambleTable = new int[mNumAxis][]; |
74 | 83 |
} |
75 |
if( mNumOccurences ==null )
|
|
84 |
if( mNumOccurences==null ) |
|
76 | 85 |
{ |
77 | 86 |
int max=0; |
78 | 87 |
|
79 | 88 |
for (ScrambleState mState : mStates) |
80 | 89 |
{ |
81 |
int tmp = mState.getTotal(-1);
|
|
90 |
int tmp = mState.getTotal(); |
|
82 | 91 |
if (max < tmp) max = tmp; |
83 | 92 |
} |
84 | 93 |
|
... | ... | |
100 | 109 |
{ |
101 | 110 |
if( curr==0 ) |
102 | 111 |
{ |
103 |
mCurrState = 0;
|
|
104 |
mIndexExcluded =-1;
|
|
112 |
mCurrState = 0; |
|
113 |
mAxisExcluded =-1;
|
|
105 | 114 |
initializeScrambling(); |
106 | 115 |
} |
107 | 116 |
|
108 |
int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences); |
|
117 |
int index = mStates[mCurrState].getRandom(rnd, mAlgorithms, mAxisExcluded, mScrambleTable, mNumOccurences); |
|
118 |
int[] algorithm = mAlgorithms[index]; |
|
109 | 119 |
|
110 |
scramble[curr][0] = info[0];
|
|
111 |
scramble[curr][1] = info[1];
|
|
112 |
scramble[curr][2] = info[2];
|
|
120 |
scramble[curr][0] = algorithm[0];
|
|
121 |
scramble[curr][1] = algorithm[1];
|
|
122 |
scramble[curr][2] = algorithm[2];
|
|
113 | 123 |
|
114 |
mCurrState = info[3];
|
|
115 |
mIndexExcluded = info[0];
|
|
124 |
mCurrState = algorithm[3];
|
|
125 |
mAxisExcluded = algorithm[0];
|
|
116 | 126 |
} |
117 | 127 |
|
118 | 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Move scrambling to a new model where there are spearete scrambling 'algorithms' and 'edges' of the scrambling graph.
Now each edge can contain a whole algorithm, i.e. a sequence of moves leading from state to state, which permits construction of scrambling for more complicated bandaged objects such as the AI cube.
Unchecked as of yet, probably still a lot of bugs.