public static int GetOrientation(Rubik rubik, Cube c) { int orientation = 0; if (c.IsEdge) { CubeFlag targetFlags = rubik.GetTargetFlags(c); Rubik clone = rubik.DeepClone(); if (!targetFlags.HasFlag(CubeFlag.MiddleLayer)) { while (RefreshCube(clone, c).Position.HasFlag(CubeFlag.MiddleLayer)) { clone.RotateLayer(c.Position.X, true); } Cube clonedCube = RefreshCube(clone, c); Face yFace = clonedCube.Faces.First(f => f.Color == rubik.TopColor || f.Color == rubik.BottomColor); if (!FacePosition.YPos.HasFlag(yFace.Position)) { orientation = 1; } } else { Face zFace = c.Faces.First(f => f.Color == rubik.FrontColor || f.Color == rubik.BackColor); if (c.Position.HasFlag(CubeFlag.MiddleLayer)) { if (!FacePosition.ZPos.HasFlag(zFace.Position)) { orientation = 1; } } else { if (!FacePosition.YPos.HasFlag(zFace.Position)) { orientation = 1; } } } } else if (c.IsCorner) { Face face = c.Faces.First(f => f.Color == rubik.TopColor || f.Color == rubik.BottomColor); if (!FacePosition.YPos.HasFlag(face.Position)) { if (FacePosition.XPos.HasFlag(face.Position) ^ !((c.Position.HasFlag(CubeFlag.BottomLayer) ^ (c.Position.HasFlag(CubeFlag.FrontSlice) ^ c.Position.HasFlag(CubeFlag.RightSlice))))) { orientation = 1; } else { orientation = 2; } } } return(orientation); }
/// <summary> /// Returns the first flag in the first parameter which the second parameter does not contain /// </summary> /// <param name="flags">Defines the posiible flags to be returned</param> /// <param name="invalid">Defines the invalid flags</param> /// <returns></returns> public static CubeFlag FirstNotInvalidFlag(CubeFlag flags, CubeFlag invalid) { foreach (CubeFlag f in GetFlags(flags)) { if (!invalid.HasFlag(f)) return f; } return CubeFlag.None; }
/// <summary> /// Yields each single flag within the parameter /// </summary> /// <param name="flags">Defines the flag to be 'splitted'</param> /// <returns></returns> public static IEnumerable <Enum> GetFlags(CubeFlag flags) { foreach (Enum value in Enum.GetValues(flags.GetType())) { if (flags.HasFlag(value)) { yield return(value); } } }
/// <summary> /// Returns a ClubFlag which contains all single flags in the first parameter which don't exist in the second parameter /// </summary> /// <param name="flags">Defines all possible flags</param> /// <param name="invalid">Defines the flags to be filtered out of the first parameter</param> /// <returns></returns> public static CubeFlag ExceptFlag(CubeFlag flags, CubeFlag invalid) { CubeFlag pos = CubeFlag.None; foreach (CubeFlag p in GetFlags(flags)) { if (!invalid.HasFlag(p)) pos |= p; } return pos; }
/// <summary> /// Returns a CubeFlag which contains all flags which exist in both the first and the second parameter /// </summary> /// <param name="first">Defines the first CubeFlag</param> /// <param name="second">Defines the second CubeFlag</param> /// <returns></returns> public static CubeFlag CommonFlags(CubeFlag first, CubeFlag second) { CubeFlag commonFlags = CubeFlag.None; foreach (CubeFlag flag in GetFlags(first)) { if (second.HasFlag(flag)) commonFlags |= flag; } return commonFlags; }
/// <summary> /// Returns the first flag in the first parameter which the second parameter does not contain /// </summary> /// <param name="flags">Defines the posiible flags to be returned</param> /// <param name="invalid">Defines the invalid flags</param> /// <returns></returns> public static CubeFlag FirstNotInvalidFlag(CubeFlag flags, CubeFlag invalid) { foreach (CubeFlag f in GetFlags(flags)) { if (!invalid.HasFlag(f)) { return(f); } } return(CubeFlag.None); }
/// <summary> /// Returns a CubeFlag which contains all flags which exist in both the first and the second parameter /// </summary> /// <param name="first">Defines the first CubeFlag</param> /// <param name="second">Defines the second CubeFlag</param> /// <returns></returns> public static CubeFlag CommonFlags(CubeFlag first, CubeFlag second) { CubeFlag commonFlags = CubeFlag.None; foreach (CubeFlag flag in GetFlags(first)) { if (second.HasFlag(flag)) { commonFlags |= flag; } } return(commonFlags); }
/// <summary> /// Returns a ClubFlag which contains all single flags in the first parameter which don't exist in the second parameter /// </summary> /// <param name="flags">Defines all possible flags</param> /// <param name="invalid">Defines the flags to be filtered out of the first parameter</param> /// <returns></returns> public static CubeFlag ExceptFlag(CubeFlag flags, CubeFlag invalid) { CubeFlag pos = CubeFlag.None; foreach (CubeFlag p in GetFlags(flags)) { if (!invalid.HasFlag(p)) { pos |= p; } } return(pos); }
/// <summary> /// Converts the given CubeFlag into a notation string /// </summary> public static string ToNotationString(CubeFlag flag) { string notation = string.Empty; if (flag.HasFlag(CubeFlag.TopLayer)) { notation += "U"; } if (flag.HasFlag(CubeFlag.BottomLayer)) { notation += "D"; } if (flag.HasFlag(CubeFlag.FrontSlice)) { notation += "F"; } if (flag.HasFlag(CubeFlag.RightSlice)) { notation += "R"; } if (flag.HasFlag(CubeFlag.BackSlice)) { notation += "B"; } if (flag.HasFlag(CubeFlag.LeftSlice)) { notation += "L"; } if (flag.HasFlag(CubeFlag.MiddleSlice)) { notation += "S"; } if (flag.HasFlag(CubeFlag.MiddleSliceSides)) { notation += "M"; } if (flag.HasFlag(CubeFlag.MiddleLayer)) { notation += "E"; } return(notation); }
/// <summary> /// Converts the given CubeFlag into a notation string /// </summary> public static string ToNotationString(CubeFlag flag) { var notation = string.Empty; if (flag.HasFlag(CubeFlag.TopLayer)) notation += "U"; if (flag.HasFlag(CubeFlag.BottomLayer)) notation += "D"; if (flag.HasFlag(CubeFlag.FrontSlice)) notation += "F"; if (flag.HasFlag(CubeFlag.RightSlice)) notation += "R"; if (flag.HasFlag(CubeFlag.BackSlice)) notation += "B"; if (flag.HasFlag(CubeFlag.LeftSlice)) notation += "L"; if (flag.HasFlag(CubeFlag.MiddleSlice)) notation += "S"; if (flag.HasFlag(CubeFlag.MiddleSliceSides)) notation += "M"; if (flag.HasFlag(CubeFlag.MiddleLayer)) notation += "E"; return notation; }
/// <summary> /// Returns a CubeFlag which contains all flags which exist in both the first and the second parameter /// </summary> /// <param name="first">Defines the first CubeFlag</param> /// <param name="second">Defines the second CubeFlag</param> /// <returns></returns> public static CubeFlag CommonFlags(CubeFlag first, CubeFlag second) => GetFlags(first).Cast<CubeFlag>().Where(flag => second.HasFlag(flag)).Aggregate(CubeFlag.None, (current, flag) => current | flag);
/// <summary> /// Returns a ClubFlag which contains all single flags in the first parameter which don't exist in the second parameter /// </summary> /// <param name="flags">Defines all possible flags</param> /// <param name="invalid">Defines the flags to be filtered out of the first parameter</param> /// <returns></returns> public static CubeFlag ExceptFlag(CubeFlag flags, CubeFlag invalid) => (from CubeFlag p in GetFlags(flags) where !invalid.HasFlag(p) select p).Aggregate(CubeFlag.None, (current, p) => current | p);
/// <summary> /// Returns the first flag in the first parameter which the second parameter does not contain /// </summary> /// <param name="flags">Defines the posiible flags to be returned</param> /// <param name="invalid">Defines the invalid flags</param> /// <returns></returns> public static CubeFlag FirstNotInvalidFlag(CubeFlag flags, CubeFlag invalid) => GetFlags(flags).Cast<CubeFlag>().FirstOrDefault(f => !invalid.HasFlag(f));
/// <summary> /// Yields each single flag within the parameter /// </summary> /// <param name="flags">Defines the flag to be 'splitted'</param> /// <returns></returns> public static IEnumerable<Enum> GetFlags(CubeFlag flags) { foreach (Enum value in Enum.GetValues(flags.GetType())) { if (flags.HasFlag(value)) yield return value; } }