public bool TestCubePosition(Cube c, CubeFlag endPos)
 {
     foreach (var move in this.Algorithm.Moves.Cast<LayerMove>())
     {
         this.Rubik.RotateLayer(move);
     }
     var result = this.RefreshCube(c).Position.HasFlag(endPos);
     return result;
 }
 public bool TestCubePosition(Cube c, CubeFlag endPos)
 {
   foreach(LayerMove move in Algorithm.Moves)
   {
     Rubik.RotateLayer(move);
   }
   bool result = RefreshCube(c).Position.HasFlag(endPos);
   return result;
 }
        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 Orientation
        /// </summary>
        /// <param name="rubik"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public static Orientation GetOrientation(Rubik rubik, Cube c)
        {
            var orientation = Orientation.Correct;
            if (c.IsEdge)
            {
                var targetFlags = rubik.GetTargetFlags(c);
                var clone = rubik.DeepClone();

                if (!targetFlags.HasFlag(CubeFlag.MiddleLayer))
                {
                    while (RefreshCube(clone, c).Position.HasFlag(CubeFlag.MiddleLayer)) clone.RotateLayer(c.Position.X, true);

                    var clonedCube = RefreshCube(clone, c);
                    var yFace = clonedCube.Faces.First(f => f.Color == rubik.TopColor || f.Color == rubik.BottomColor);
                    if (!YPos.HasFlag(yFace.Position)) orientation = Orientation.Clockwise;
                }
                else
                {
                    var zFace = c.Faces.First(f => f.Color == rubik.FrontColor || f.Color == rubik.BackColor);
                    if (c.Position.HasFlag(CubeFlag.MiddleLayer))
                    {
                        if (!ZPos.HasFlag(zFace.Position)) orientation = Orientation.Clockwise;
                    }
                    else
                    {
                        if (!YPos.HasFlag(zFace.Position)) orientation = Orientation.Clockwise;
                    }
                }
            }
            else if (c.IsCorner)
            {
                var face = c.Faces.First(f => f.Color == rubik.TopColor || f.Color == rubik.BottomColor);
                if (YPos.HasFlag(face.Position))
                {
                    return orientation;
                }
                orientation = XPos.HasFlag(face.Position) ^ !(c.Position.HasFlag(CubeFlag.BottomLayer) ^ (c.Position.HasFlag(CubeFlag.FrontSlice) ^ c.Position.HasFlag(CubeFlag.RightSlice))) ? Orientation.CounterClockwise : Orientation.Clockwise;
            }

            return orientation;
        }
 public bool IsCorrect(Cube cube)
 {
     return cube.Position.Flags == GetTargetFlags(cube) && Solvability.GetOrientation(this, cube) == 0;
 }
 /// <summary>
 /// Returns the position of given cube where it has to be when the Rubik is solved
 /// </summary>
 /// <param name="cube">Defines the cube to be analyzed</param>
 /// <returns></returns>
 public CubeFlag GetTargetFlags(Cube cube)
 {
     return GenStandardCube().Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, cube.Colors)).Position.Flags;
 }
 /// <summary>
 /// Refreshes the position of a cube
 /// </summary>
 /// <param name="r">Parent rubik of the cube</param>
 private static Cube RefreshCube(Rubik r, Cube c)
 {
     return r.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, c.Colors));
 }
 private Cube RefreshCube(Cube c)
 {
   return Rubik.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, c.Colors));
 }
 /// <summary>
 /// Returns the position of given cube where it has to be when the Rubik is solved
 /// </summary>
 /// <param name="cube">Defines the cube to be analyzed</param>
 /// <returns></returns>
 protected CubeFlag GetTargetFlags(Cube cube) => this.StandardCube.Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, cube.Colors)).Position.Flags;
Beispiel #10
0
 public bool IsCorrect(Cube cube)
 {
     return(cube.Position.Flags == GetTargetFlags(cube) && Solvability.GetOrientation(this, cube) == 0);
 }
Beispiel #11
0
 /// <summary>
 /// Returns the position of given cube where it has to be when the Rubik is solved
 /// </summary>
 /// <param name="cube">Defines the cube to be analyzed</param>
 /// <returns></returns>
 public CubeFlag GetTargetFlags(Cube cube)
 {
     return(GenStandardCube().Cubes.First(cu => CollectionMethods.ScrambledEquals(cu.Colors, cube.Colors)).Position.Flags);
 }