public void unpack(int c) { int l = 1; for (int i = 0; i < comb.a.length; i++) // count number of different orientations if ((~active & 1 << i) != 0) l *= 3; if ((active & 0xFF) != 0) { // some orientations are not set comb.combUnpack(c / l); // unpack combination c %= l; // let it be only orientations for (int i = comb.a.length - 1; i >= 0; i--) { if (comb.a[i] != 0) { comb.a[i] = c % 3 + 1; c /= 3; } } } else { // all orientations are set int t = 0; l /= 3; // one corner orientation is given comb.combUnpack(c / l); c %= l; for (int i = comb.a.length - 2; i >= 0; i--) { comb.a[i] = c % 3 + 1; t += c % 3; c /= 3; } comb.a[comb.a.length - 1] = (3 - (t % 3)) % 3 + 1; // set the last orientation } }
/** * By redefining of start() and startLength(), solving to the specified state can be done. * position = 0, 1,..., startLength() - 1 */ public int start(int pos) { int p1 = 0; int o1 = 0; for (int i = 0; i < comb.a.length; i++) { if ((active >> 8 & 1 << i) != 0) { // unspecified position p1++; if ((active & 1 << i) == 0) // specified orientation o1++; } } Comb c = new Comb(p1, o1); c.combUnpack(pos); for (int i = 0, j = 0; i < comb.a.length; i++) { if ((active >> 8 & 1 << i) != 0) // unspecified position comb.a[i] = c.a[j++]; else if ((active & 1 << i) == 0) // specified position and orientation comb.a[i] = 1; else // specified position, unspecified orientation comb.a[i] = 0; } return pack(); }