public static int GetSolvedSym(CenterCube cube) { Center1 c = new Center1(cube.Ct); for (int j = 0; j < 48; j++) { bool check = true; for (int i = 0; i < 24; i++) { if (c.Ct[i] != i / 4) { check = false; break; } } if (check) { return(j); } c.Rot(0); if (j % 2 == 1) { c.Rot(1); } if (j % 8 == 7) { c.Rot(2); } if (j % 16 == 15) { c.Rot(3); } } return(-1); }
private static void Init() { if (inited) { return; } cs.min2phase.Tools.Init(); Center1.InitSym(); Center1.Raw2sym = new int[735471]; Center1.InitSym2Raw(); Center1.CreateMoveTable(); Center1.Raw2sym = null; Center1.CreatePrun(); Center2.Init(); Center3.Init(); Edge3.InitMvrot(); Edge3.InitRaw2Sym(); Edge3.CreatePrun(); inited = true; }
private void Set(Center1 c) { for (int i = 0; i < 24; i++) { Ct[i] = c.Ct[i]; } }
public override bool Equals(object obj) { if (obj is Center1) { Center1 c = (Center1)obj; for (int i = 0; i < 24; i++) { if (Ct[i] != c.Ct[i]) { return(false); } } return(true); } return(false); }
public static void CreateMoveTable() { Center1 c = new Center1(); Center1 d = new Center1(); for (int i = 0; i < 15582; i++) { d.Set(sym2raw[i]); for (int m = 0; m < 36; m++) { c.Set(d); c.Move(m); Ctsmv[i][m] = c.Getsym(); } } }
public static void InitSym2Raw() { Center1 c = new Center1(); int[] occ = new int[735471 / 32 + 1]; int count = 0; for (int i = 0; i < 735471; i++) { if ((occ[(uint)i >> 5] & (1 << (i & 0x1f))) == 0) { c.Set(i); for (int j = 0; j < 48; j++) { int idx = c.Get(); occ[(uint)idx >> 5] |= (1 << (idx & 0x1f)); if (Raw2sym != null) { Raw2sym[idx] = count << 6 | Syminv[j]; } c.Rot(0); if (j % 2 == 1) { c.Rot(1); } if (j % 8 == 7) { c.Rot(2); } if (j % 16 == 15) { c.Rot(3); } } sym2raw[count++] = i; } } }
private void DoSearch() { Init(); solution = ""; int ud = new Center1(cubeToSolve.GetCenter(), 0).Getsym(); int fb = new Center1(cubeToSolve.GetCenter(), 1).Getsym(); int rl = new Center1(cubeToSolve.GetCenter(), 2).Getsym(); int udprun = Center1.Csprun[ud >> 6]; int fbprun = Center1.Csprun[fb >> 6]; int rlprun = Center1.Csprun[rl >> 6]; p1SolsCnt = 0; arr2idx = 0; p1sols.Clear(); for (length1 = Math.Min(Math.Min(udprun, fbprun), rlprun); length1 < 100; length1++) { if (rlprun <= length1 && Search1((int)((uint)rl >> 6), rl & 0x3f, length1, -1, 0) || udprun <= length1 && Search1((int)((uint)ud >> 6), ud & 0x3f, length1, -1, 0) || fbprun <= length1 && Search1((int)((uint)fb >> 6), fb & 0x3f, length1, -1, 0)) { break; } } //FullCube[] p1SolsArr = p1sols.ToArray(new FullCube[0]); FullCube[] p1SolsArr = new FullCube[p1sols.Count]; p1sols.CopyTo(p1SolsArr, 0); Array.Sort(p1SolsArr, 0, p1SolsArr.Length); int MAX_LENGTH2 = 9; int length12; do { for (length12 = p1SolsArr[0].Value; length12 < 100; length12++) { for (int i = 0; i < p1SolsArr.Length; i++) { if (p1SolsArr[i].Value > length12) { break; } if (length12 - p1SolsArr[i].Length1 > MAX_LENGTH2) { continue; } c1.Copy(p1SolsArr[i]); ct2.Set(c1.GetCenter(), c1.GetEdge().GetParity()); int s2ct = ct2.Getct(); int s2rl = ct2.Getrl(); length1 = p1SolsArr[i].Length1; length2 = length12 - p1SolsArr[i].Length1; if (Search2(s2ct, s2rl, length2, 28, 0)) { goto OUT; } } } OUT: MAX_LENGTH2++; } while (length12 == 100); Array.Sort(arr2, 0, arr2idx); int length123, index = 0; int solcnt = 0; int MAX_LENGTH3 = 13; do { for (length123 = arr2[0].Value; length123 < 100; length123++) { for (int i = 0; i < Math.Min(arr2idx, PHASE3_ATTEMPTS); i++) { if (arr2[i].Value > length123) { break; } if (length123 - arr2[i].Length1 - arr2[i].Length2 > MAX_LENGTH3) { continue; } int eparity = e12.Set(arr2[i].GetEdge()); ct3.Set(arr2[i].GetCenter(), eparity ^ arr2[i].GetCorner().GetParity()); int ct = ct3.Getct(); int edge = e12.Get(10); int prun = Edge3.Getprun(e12.Getsym()); int lm = 20; if (prun <= length123 - arr2[i].Length1 - arr2[i].Length2 && Search3(edge, ct, prun, length123 - arr2[i].Length1 - arr2[i].Length2, lm, 0)) { solcnt++; index = i; goto OUT2; } } } OUT2: MAX_LENGTH3++; } while (length123 == 100); FullCube solcube = new FullCube(arr2[index]); length1 = solcube.Length1; length2 = solcube.Length2; int length = length123 - length1 - length2; for (int i = 0; i < length; i++) { solcube.Move(Move3std[move3[i]]); } string facelet = solcube.To333Facelet(); string sol = search333.Solution(facelet, 20, 100, 50, 0); if (sol.StartsWith("Error 8")) { sol = search333.Solution(facelet, 21, 1000000, 30, 0); } int len333 = sol.Length / 3; if (sol.StartsWith("Error")) { throw new Exception(); } int[] sol333 = Util.Tomove(sol); for (int i = 0; i < sol333.Length; i++) { solcube.Move(sol333[i]); } StringBuilder str = new StringBuilder(); str.Append(solcube.GetMoveString(InverseSolution, WithRotation)); solution = str.ToString(); totlen = length1 + length2 + length + len333; }
public string GetMoveString(bool inverse, bool rotation) { int[] fixedMoves = new int[moveLength - (Add1 ? 2 : 0)]; int idx = 0; for (int i = 0; i < Length1; i++) { fixedMoves[idx++] = moveBuffer[i]; } int sym = this.Sym; for (int i = Length1 + (Add1 ? 2 : 0); i < moveLength; i++) { if (Center1.Symmove[sym][moveBuffer[i]] >= dx1) { fixedMoves[idx++] = Center1.Symmove[sym][moveBuffer[i]] - 9; int rot = move2rot[Center1.Symmove[sym][moveBuffer[i]] - dx1]; sym = Center1.Symmult[sym][rot]; } else { fixedMoves[idx++] = Center1.Symmove[sym][moveBuffer[i]]; } } int finishSym = Center1.Symmult[Center1.Syminv[sym]][Center1.GetSolvedSym(GetCenter())]; StringBuilder sb = new StringBuilder(); sym = finishSym; if (inverse) { for (int i = idx - 1; i >= 0; i--) { int move = fixedMoves[i]; move = move / 3 * 3 + (2 - move % 3); if (Center1.Symmove[sym][move] >= dx1) { sb.Append(Move2str[Center1.Symmove[sym][move] - 9]).Append(' '); int rot = move2rot[Center1.Symmove[sym][move] - dx1]; sym = Center1.Symmult[sym][rot]; } else { sb.Append(Move2str[Center1.Symmove[sym][move]]).Append(' '); } } if (rotation) { sb.Append(Center1.Rot2str[Center1.Syminv[sym]] + " ");//cube rotation after solution. for wca scramble, it should be omitted. } } else { for (int i = 0; i < idx; i++) { sb.Append(Move2str[fixedMoves[i]]).Append(' '); } if (rotation) { sb.Append(Center1.Rot2str[finishSym]);//cube rotation after solution. } } return(sb.ToString()); }
public static void InitSym() { Center1 c = new Center1(); for (sbyte i = 0; i < 24; i++) { c.Ct[i] = i; } Center1 d = new Center1(c.Ct); Center1 e = new Center1(c.Ct); Center1 f = new Center1(c.Ct); for (int i = 0; i < 48; i++) { for (int j = 0; j < 48; j++) { for (int k = 0; k < 48; k++) { if (c.Equals(d)) { Symmult[i][j] = k; if (k == 0) { Syminv[i] = j; } } d.Rot(0); if (k % 2 == 1) { d.Rot(1); } if (k % 8 == 7) { d.Rot(2); } if (k % 16 == 15) { d.Rot(3); } } c.Rot(0); if (j % 2 == 1) { c.Rot(1); } if (j % 8 == 7) { c.Rot(2); } if (j % 16 == 15) { c.Rot(3); } } c.Rot(0); if (i % 2 == 1) { c.Rot(1); } if (i % 8 == 7) { c.Rot(2); } if (i % 16 == 15) { c.Rot(3); } } for (int i = 0; i < 48; i++) { c.Set(e); c.Rotate(Syminv[i]); for (int j = 0; j < 36; j++) { d.Set(c); d.Move(j); d.Rotate(i); for (int k = 0; k < 36; k++) { f.Set(e); f.Move(k); if (f.Equals(d)) { Symmove[i][j] = k; break; } } } } c.Set(0); for (int i = 0; i < 48; i++) { Finish[Syminv[i]] = c.Get(); c.Rot(0); if (i % 2 == 1) { c.Rot(1); } if (i % 8 == 7) { c.Rot(2); } if (i % 16 == 15) { c.Rot(3); } } }