/// <summary> /// private mid layer constructor /// </summary> /// <param name="FaceArray">Face array</param> /// <param name="FaceNo">Face number</param> private MidLayer ( int[] FaceArray, int FaceNo ) { // save face number and position // 11=Blue, 19=Red, 27=Green, 35=Orange this.FaceNo = FaceNo; FacePos = Cube.FindEdge(FaceArray, FaceNo); // mid layer edge is in the mid layer but in wrong position or orientation if (Cube.FaceNoToBlockNo[FacePos] < 18) { MoveToYellow = true; return; } // color of face no int FaceNoColor = FaceNo / Cube.FaceNoToColor; // use left algorithm if (FacePos / Cube.FaceNoToColor == Cube.YellowFace) { // the front face is one face to the right FrontFace = (FaceNoColor % 4) + 1; // steps control StepCtrl = Cube.MidLayerLeft; // get steps Steps = StepCtrl.Steps(FrontFace - 1); // face pos is on yellow face // it is translated to face position on a front face // and converted to color code Rotation = (33 - 4 * (FacePos - 41)) / 8 - FrontFace + 4; } // use right algorithm else { // front face FrontFace = FaceNoColor; // steps control StepCtrl = Cube.MidLayerRight; // get steps Steps = StepCtrl.Steps(FaceNoColor - 1); // required rotation Rotation = FacePos / 8 - FaceNoColor + 4; } // the first step in mid layer algorithm is yellow rotation // if additional yellow rotation is required we will combine it with first step YellowRotation = (Steps[0] - Cube.YellowCW + 1 + Rotation) % 4; return; }
/// <summary> /// Create solution state case 4 /// </summary> /// <param name="Message">Message</param> /// <returns>Solution step</returns> public SolutionStep CreateSolutionStep4 ( string Message ) { // current face position is in middle layer but not at right place. // we need to take it out to yellow layer // we will do right algoritm switch (FacePos) { case 11: case 23: FrontFace = 1; break; case 19: case 31: FrontFace = 2; break; case 27: case 39: FrontFace = 3; break; case 35: case 15: FrontFace = 4; break; default: throw new ApplicationException("Mid layer FacePos"); } // get mid layer right step control StepCtrl = Cube.MidLayerRight; // get steps Steps = StepCtrl.Steps(FrontFace - 1); // remove initial step int Len = Steps.Length - 1; int[] TempSteps = new int[Len]; Array.Copy(Steps, 1, TempSteps, 0, Len); // there was no yellow rotation required return(new SolutionStep(StepCode.MidLayer, Message, FacePos, Cube.YellowFace, FrontFace, TempSteps)); }
/// <summary> /// Create solution step /// </summary> /// <param name="Message">Text message</param> /// <returns>Solution step</returns> public SolutionStep CreateSolutionStep ( string Message ) { // if block number is 0 to 8 it is in white face but not in correct position // we need an extra move to get it out of white face into yellow face if (MoveToYellow) { // calculate face position on the yellow face that will be moved // into the bad corner block to force it to get out FacePos = 0; switch (FaceNo) { case 0: FacePos = 16; break; case 2: FacePos = 24; break; case 4: FacePos = 32; break; case 6: FacePos = 8; break; } } // if rotation is not zero change face position else if (YellowRotation != 0) { FacePos = Cube.RotMatrix[Cube.YellowCW + YellowRotation - 1][FacePos]; } // get steps int CtrlIndex = Cube.WhiteCornerIndex[FacePos / 2]; int Case = CtrlIndex / 4; int StepsIndex = CtrlIndex % 4; int FrontFace = StepsIndex + 1; StepCtrl StepCtrl = Cube.WhiteCornerCases[Case]; int[] Steps = StepCtrl.Steps(StepsIndex); // corner is in yellow face if (!MoveToYellow) { // no rotation if (YellowRotation == 0) { return(new SolutionStep(StepCode.WhiteCorners, Message, FaceNo, Cube.WhiteFace, FrontFace, Steps)); } // create new color steps array to include yellow rotation int Len = Steps.Length; int[] TempSteps = new int[Len + 1]; Array.Copy(Steps, 0, TempSteps, 1, Len); TempSteps[0] = Cube.YellowCW + YellowRotation - 1; // return solve step return(new SolutionStep(StepCode.WhiteCorners, Message, FaceNo, Cube.WhiteFace, FrontFace, TempSteps)); } // move corner to yellow face // return with solve step return(new SolutionStep(StepCode.WhiteCorners, Message, FaceNo, Cube.WhiteFace, FrontFace, Steps)); }