| 3 | import java.util.Random; |
| 4 | |
| 5 | public class Pyraminx { |
| 6 | private static int[] colmap = new int[91]; |
| 7 | private static byte[] perm = new byte[360]; // pruning table for edge permutation |
| 8 | private static byte[] twst = new byte[2592]; // pruning table for edge orientation+twist |
| 9 | private static short[][] permmv = new short[360][4]; // transition table for edge permutation |
| 10 | private static short[][] twstmv = new short[81][4]; // transition table for corner orientation |
| 11 | private static short[][] flipmv = new short[32][4]; // transition table for edge orientation |
| 12 | private static String[] turn = {"L", "R", "B", "U"}; |
| 13 | private static String[] suff = {"'", ""}; |
| 14 | private static String[] tips = {"l", "r", "b", "u"}; |
| 15 | //private static int[] seq = new int[12]; |
| 16 | private static int[] img = new int[91]; |
| 17 | private static Random r = new Random(); |
| 18 | |
| 19 | static { |
| 20 | calcperm(); |
| 21 | } |
| 22 | |
| 23 | public static String scramble() { |
| 24 | String scramble; |
| 25 | do { |
| 26 | int t = r.nextInt(2592), q = r.nextInt(360); |
| 27 | scramble = scramble(q, t); |
| 28 | } while (scramble.equals("error")); |
| 29 | return scramble; |
| 30 | } |
| 31 | |
| 32 | public static String scrambleL4E() { |
| 33 | String scramble; |
| 34 | do { |
| 35 | int[] ps = {0, 1, 2, 3, 4, 5}; |
| 36 | Utils.idxToPerm(ps, r.nextInt(12), 4, true); |
| 37 | int[] ts = new int[6]; |
| 38 | Utils.idxToFlip(ts, r.nextInt(8), 4, true); |
| 39 | int p = Utils.permToIdx(ps, 6, true); |
| 40 | int t = r.nextInt(3) * 864 + Utils.flipToIdx(ts, 6, true); |
| 41 | scramble = scramble(p, t); |
| 42 | } while (scramble.equals("error")); |
| 43 | return scramble; |
| 44 | } |
| 45 | |
| 46 | private static String scramble(int p, int t) { |
| 47 | int[] seq = new int[12]; |
| 48 | for (int l = 0; l < 12; l++) |
| 49 | if (search(p, t, l, -1, seq)) { |
| 50 | if (l < 2) return "error"; |
| 51 | if (l < 5) { |
| 52 | continue; |
| 53 | } |
| 54 | StringBuilder sol = new StringBuilder(); |
| 55 | for (int i = 1; i <= l; i++) |
| 56 | sol.append(turn[seq[i] >> 1]).append(suff[seq[i] & 1]).append(" "); |
| 57 | for (int i = 0; i < 4; i++) { |
| 58 | int j = r.nextInt(3); |
| 59 | if (j < 2) |
| 60 | sol.append(tips[i]).append(suff[j]).append(" "); |
| 61 | } |
| 62 | return sol.toString(); |