public MoveCollection TransformMoves(CubeOrientation orientation) { MoveCollection newMoves = new MoveCollection(); for (IEnumerator <Move> e = GetEnumerator(); e.MoveNext();) { Move m = e.Current; newMoves.Add(orientation.TransformFace(m.Face), m.Count); } return(newMoves); }
public MoveCollection Parse(string moveString) { MoveCollection moves = new MoveCollection(); for (int i = 0; i < moveString.Length; i++) { char moveChar = moveString[i]; string postfix = new string(moveString.Skip(i + 1).TakeWhile(c => !faceMappings.Contains(c) && !orientationMoveChars.Contains(c)).ToArray()); i += postfix.Length; // get rotations count ('i' = -1, '2' = 2, '' = 1) int count = postfix.EndsWith("i") ? -1 : (postfix.EndsWith("2") ? 2 : 1); // normal face move if (faceMappings.Contains(moveChar)) { CubeFace face = cubeOrientation[Array.IndexOf(faceMappings, moveChar)]; // W move if (postfix.StartsWith("w")) { switch (face) { // Lw case CubeFace.LEFT: ChangeOrientation(OrientationMove.X, -count); break; // Uw case CubeFace.UP: ChangeOrientation(OrientationMove.Y, count); break; // Fw case CubeFace.FRONT: ChangeOrientation(OrientationMove.Z, count); break; // Dw case CubeFace.DOWN: ChangeOrientation(OrientationMove.Y, -count); break; // Rw case CubeFace.RIGHT: ChangeOrientation(OrientationMove.X, count); break; // Bw case CubeFace.BACK: ChangeOrientation(OrientationMove.Z, -count); break; default: throw new InvalidProgramException(); } face = GetOpponentFace(face); } moves.Add(face, count); } // orientation move else if (orientationMoveChars.Contains(moveChar)) { switch (char.ToLower(moveChar)) { case 'x': ChangeOrientation(OrientationMove.X, count); break; case 'y': ChangeOrientation(OrientationMove.Y, count); break; case 'z': ChangeOrientation(OrientationMove.Z, count); break; default: throw new InvalidProgramException(); } } else { throw new FormatException($"Cannot parse orientation move \'{moveChar + postfix}\'"); } } return(moves); }