예제 #1
0
        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);
        }
예제 #2
0
 public bool Test(Func <Rubik, bool> func)
 {
     foreach (LayerMove move in Algorithm.Moves)
     {
         Rubik.RotateLayer(move);
     }
     return(func(Rubik));
 }
예제 #3
0
        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);
        }
예제 #4
0
 /// <summary>
 /// Adds a move to the solution and executes it on the Rubik
 /// </summary>
 /// <param name="move">Defines the move to be rotated</param>
 protected void SolverMove(IMove move)
 {
     Rubik.RotateLayer(move);
     Algorithm.Moves.Add(move);
     _movesOfStep.Add(move);
 }
예제 #5
0
 /// <summary>
 /// Adds n move to the solution and executes it on the Rubik
 /// </summary>
 /// <param name="layer">Defines the layer to be rotated</param>
 /// <param name="direction">Defines the direction of the rotation</param>
 protected void SolverMove(CubeFlag layer, bool direction)
 {
     Rubik.RotateLayer(layer, direction);
     Algorithm.Moves.Add(new LayerMove(layer, direction));
     _movesOfStep.Add(new LayerMove(layer, direction));
 }