public RubikRenderer(Rectangle screen, double scale)
        {
            RubikManager = new RubikManager();
            this.scale   = scale;
            this.screen  = screen;
            frameTimes   = new List <double>();
            IsRunning    = false;

            updateHandle = new AutoResetEvent[2];
            for (int i = 0; i < updateHandle.Length; i++)
            {
                updateHandle[i] = new AutoResetEvent(false);
            }

            renderHandle = new AutoResetEvent[2];
            for (int i = 0; i < renderHandle.Length; i++)
            {
                renderHandle[i] = new AutoResetEvent(true);
            }

            buffer = new RenderInfo[2];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = new RenderInfo();
            }
        }
Ejemplo n.º 2
0
        public RubikManager Clone()
        {
            RubikManager newRubikManager = new RubikManager();

            newRubikManager.Rotating       = Rotating;
            newRubikManager.rotationLayer  = rotationLayer;
            newRubikManager.rotationStep   = rotationStep;
            newRubikManager.rotationTarget = rotationTarget;
            newRubikManager.RubikCube      = RubikCube.Clone();
            newRubikManager.Moves          = new List <LayerMove>(Moves.Select(m => m.Clone()));
            return(newRubikManager);
        }
Ejemplo n.º 3
0
        public CubeSolver(RubikManager rubik)
        {
            Manager = rubik.Clone();

            //Change colors of the faces
            standardCube.setFaceColor(Cube3D.RubikPosition.TopLayer, Face3D.FacePosition.Top,
                                      Manager.getFaceColor(Cube3D.RubikPosition.TopLayer | Cube3D.RubikPosition.MiddleSlice_Sides | Cube3D.RubikPosition.MiddleSlice, Face3D.FacePosition.Top));

            standardCube.setFaceColor(Cube3D.RubikPosition.BottomLayer, Face3D.FacePosition.Bottom,
                                      Manager.getFaceColor(Cube3D.RubikPosition.BottomLayer | Cube3D.RubikPosition.MiddleSlice_Sides | Cube3D.RubikPosition.MiddleSlice, Face3D.FacePosition.Bottom));

            standardCube.setFaceColor(Cube3D.RubikPosition.RightSlice, Face3D.FacePosition.Right,
                                      Manager.getFaceColor(Cube3D.RubikPosition.RightSlice | Cube3D.RubikPosition.MiddleSlice | Cube3D.RubikPosition.MiddleLayer, Face3D.FacePosition.Right));

            standardCube.setFaceColor(Cube3D.RubikPosition.LeftSlice, Face3D.FacePosition.Left,
                                      Manager.getFaceColor(Cube3D.RubikPosition.LeftSlice | Cube3D.RubikPosition.MiddleSlice | Cube3D.RubikPosition.MiddleLayer, Face3D.FacePosition.Left));

            standardCube.setFaceColor(Cube3D.RubikPosition.FrontSlice, Face3D.FacePosition.Front,
                                      Manager.getFaceColor(Cube3D.RubikPosition.MiddleLayer | Cube3D.RubikPosition.MiddleSlice_Sides | Cube3D.RubikPosition.FrontSlice, Face3D.FacePosition.Front));

            standardCube.setFaceColor(Cube3D.RubikPosition.BackSlice, Face3D.FacePosition.Back,
                                      Manager.getFaceColor(Cube3D.RubikPosition.MiddleLayer | Cube3D.RubikPosition.MiddleSlice_Sides | Cube3D.RubikPosition.BackSlice, Face3D.FacePosition.Back));
        }
Ejemplo n.º 4
0
        public bool CanSolve()
        {
            RubikManager oldManager = Manager.Clone();
            //check colors
            bool correctColors = standardCube.RubikCube.cubes.Count(sc => Manager.RubikCube.cubes
                                                                    .Where(c => ScrambledEquals(c.Colors, sc.Colors)).Count() == 1) == Manager.RubikCube.cubes.Count();

            //return false, if there are invalid cube colors
            if (!correctColors)
            {
                return(false);
            }

            Solve(false);

            //check if all the cube faces are solved
            Cube3D.RubikPosition layers = Cube3D.RubikPosition.TopLayer | Cube3D.RubikPosition.BottomLayer | Cube3D.RubikPosition.RightSlice
                                          | Cube3D.RubikPosition.LeftSlice | Cube3D.RubikPosition.FrontSlice | Cube3D.RubikPosition.BackSlice;
            foreach (Cube3D.RubikPosition l in GetFlags(layers))
            {
                Face3D.FacePosition facePos = CubePosToFacePos(l);
                if (facePos != Face3D.FacePosition.None)
                {
                    Cube3D.RubikPosition centerPos = Manager.RubikCube.cubes.First(c => Cube3D.isCenter(c.Position) && c.Position.HasFlag(l)).Position;
                    Color faceColor = Manager.getFaceColor(centerPos, facePos);

                    bool faceNotSolved = Manager.RubikCube.cubes.Count(c => c.Position.HasFlag(l) && c.Faces.First(f => f.Position == facePos).Color == faceColor) != 9;
                    if (faceNotSolved)
                    {
                        return(false);
                    }
                }
            }

            Manager = oldManager;
            return(true);
        }
Ejemplo n.º 5
0
 private Cube3D RefreshCube(Cube3D cube, RubikManager manager)
 {
     return(manager.RubikCube.cubes.First(cu => ScrambledEquals(cu.Colors, cube.Colors)));
 }
Ejemplo n.º 6
0
 private int CountTopEdgesAtTargetPosition(RubikManager manager)
 {
     return(manager.RubikCube.cubes.Count(c => Cube3D.isEdge(c.Position) && c.Position.HasFlag(Cube3D.RubikPosition.TopLayer) && c.Position == GetTargetPosition(c)));
 }
Ejemplo n.º 7
0
        private int CountEdgesWithCorrectOrientation(RubikManager manager)
        {
            Color topColor = manager.getFaceColor(Cube3D.RubikPosition.TopLayer | Cube3D.RubikPosition.MiddleSlice_Sides | Cube3D.RubikPosition.MiddleSlice, Face3D.FacePosition.Top);

            return(manager.RubikCube.cubes.Count(c => Cube3D.isEdge(c.Position) && c.Faces.First(f => f.Position == Face3D.FacePosition.Top).Color == topColor));
        }