Beispiel #1
0
        public void simpleSolver()
        {
            Rubik myRubik = new Rubik();

            myRubik.rotateFace(new Rotation(Face.U, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.D, Direction.CW));
            RotationTree       myTree = new RotationTree();
            RotationLinkedList myRotationLinkedList = new RotationLinkedList();

            myRotationLinkedList.addRotation(new Rotation(Face.U, Direction.CCW));
            myTree.addRotationLinkedList(myRotationLinkedList);

            myRotationLinkedList = new RotationLinkedList();
            myRotationLinkedList.addRotation(new Rotation(Face.R, Direction.CCW));
            myTree.addRotationLinkedList(myRotationLinkedList);

            myRotationLinkedList = new RotationLinkedList();
            myRotationLinkedList.addRotation(new Rotation(Face.L, Direction.CCW));
            myTree.addRotationLinkedList(myRotationLinkedList);

            myRotationLinkedList = new RotationLinkedList();
            myRotationLinkedList.addRotation(new Rotation(Face.D, Direction.CCW));
            myTree.addRotationLinkedList(myRotationLinkedList);

            Solver   mySolver   = new Solver();
            Solution mySolution = mySolver.solve(myRubik, myTree, myTree, myTree);

            mySolution.applyToRubik(myRubik);
            mySolution.print();
            myRubik.getPermutation().print();
            AssistAssertRubik.checkEntireCube(myRubik);
        }
Beispiel #2
0
        public void positionTest()
        {
            Rubik myRubik = new Rubik();

            myRubik.rotateFace(new Rotation(Face.U, Direction.CW));
            Assert.AreEqual(true, myRubik
                            .getPositionOfCubicleOfCubiclePlace(new Location(Face.D, Face.F))
                            .equals(new Position(Face.U, Face.F)), "1");

            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            Assert.AreEqual(true, myRubik
                            .getPositionOfCubicleOfCubiclePlace(new Location(Face.D, Face.F))
                            .equals(new Position(Face.U, Face.F)), "2");

            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            Assert.AreEqual(true, myRubik
                            .getPositionOfCubicleOfCubiclePlace(new Location(Face.D, Face.F))
                            .equals(new Position(Face.U, Face.F)), "3");

            Position yaki = myRubik.getPositionOfCubicleOfCubiclePlace(new Location(Face.D, Face.L));

            myRubik.rotateFace(new Rotation(Face.D, Direction.CW));
            yaki = myRubik.getPositionOfCubicleOfCubiclePlace(new Location(Face.D, Face.F));
            Assert.AreEqual(true, myRubik
                            .getPositionOfCubicleOfCubiclePlace(new Location(Face.D, Face.F))
                            .equals(new Position(Face.B, Face.L)), "4");
        }
Beispiel #3
0
 static void myAssertEdge(Face p_firstFace, Face p_secondFace, Rubik p_rubik)
 {
     Assert.AreEqual(true, (new Location(p_firstFace, p_secondFace))
                     .equals(p_rubik.getOriginalLocationOfCurrentCubicleInLocation(new Location(p_firstFace, p_secondFace)))
                     , "Problem with edge " + Char.ToString(p_firstFace.getChar())
                     + " / " + Char.ToString(p_secondFace.getChar()));
 }
Beispiel #4
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);
        }
Beispiel #5
0
        public static void checkEntireCube(Rubik p_rubik)
        {
            myAssertEdge(Face.U, Face.L, p_rubik);
            myAssertEdge(Face.U, Face.R, p_rubik);
            myAssertEdge(Face.U, Face.F, p_rubik);
            myAssertEdge(Face.U, Face.B, p_rubik);

            myAssertEdge(Face.D, Face.L, p_rubik);
            myAssertEdge(Face.D, Face.R, p_rubik);
            myAssertEdge(Face.D, Face.F, p_rubik);
            myAssertEdge(Face.D, Face.B, p_rubik);

            myAssertEdge(Face.F, Face.L, p_rubik);
            myAssertEdge(Face.F, Face.R, p_rubik);
            myAssertEdge(Face.B, Face.L, p_rubik);
            myAssertEdge(Face.B, Face.R, p_rubik);

            myAssertCorner(Face.D, Face.L, Face.B, p_rubik);
            myAssertCorner(Face.D, Face.L, Face.F, p_rubik);
            myAssertCorner(Face.D, Face.R, Face.B, p_rubik);
            myAssertCorner(Face.D, Face.R, Face.F, p_rubik);

            myAssertCorner(Face.U, Face.L, Face.B, p_rubik);
            myAssertCorner(Face.U, Face.L, Face.F, p_rubik);
            myAssertCorner(Face.U, Face.R, Face.B, p_rubik);
            myAssertCorner(Face.U, Face.R, Face.F, p_rubik);
        }
Beispiel #6
0
        public void simpleRotations()
        {
            Rubik myRubik = new Rubik();

            for (int i = 0; i < 20; i++)
            {
                myRubik.rotateFace(new Rotation(Face.U, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.D, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.U, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
                myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            }
            for (int i = 0; i < 20; i++)
            {
                myRubik.rotateFace(new Rotation(Face.F, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.L, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.B, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.R, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.U, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.R, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.D, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.L, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.R, Direction.CCW));
                myRubik.rotateFace(new Rotation(Face.U, Direction.CCW));
            }
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CCW));
            AssistAssertRubik.checkEntireCube(myRubik);
        }
Beispiel #7
0
 public bool Test(Func <Rubik, bool> func)
 {
     foreach (LayerMove move in Algorithm.Moves)
     {
         Rubik.RotateLayer(move);
     }
     return(func(Rubik));
 }
Beispiel #8
0
        public void rotateTest3()
        {
            Rubik myRubik = new Rubik();

            myRubik.rotateFace(new Rotation(Face.D, Direction.CCW));
            Assert.AreEqual(true, (new Location(Face.D, Face.R, Face.B))
                            .equals(myRubik.getOriginalLocationOfCurrentCubicleInLocation(new Location(Face.D, Face.R, Face.F))));
        }
        // *** METHODS ***

        /// <summary>
        /// Returns the solution for the transferred Rubik
        /// </summary>
        /// <param name="cube">Defines the Rubik to be solved</param>
        protected virtual void Solve(Rubik cube)
        {
            Rubik     = cube.DeepClone();
            Algorithm = new Algorithm();
            InitStandardCube();

            GetSolution();
            RemoveUnnecessaryMoves();
        }
Beispiel #10
0
        /// <summary>
        /// Returns the solution for the transferred Rubik
        /// </summary>
        /// <param name="cube">Defines the Rubik to be solved</param>
        public virtual void Solve(Rubik cube)
        {
            Rubik     = cube.DeepClone();
            Algorithm = new Algorithm(null);
            InitStandardCube();

            GetSolution();
            Algorithm = Algorithm.RemoveUnnecessaryMoves(Algorithm);
        }
Beispiel #11
0
 public void setData(float scale, Vector3 position, Vector3 movemment, Quaternion rotation, Transform transform, int[] showFaces, Rubik parent)
 {
     _showFaces = showFaces;
     _parent    = parent;
     setColor();
     setScale(scale);
     setPosition((scale * position) + movemment, rotation);
     gameObject.transform.parent = transform;
 }
Beispiel #12
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);
        }
 private IEnumerable <Tuple <Cube, Cube> > GetPairs(Rubik rubik)
 {
     foreach (Cube edge in rubik.Cubes.Where(c => c.IsEdge && Rubik.GetTargetFlags(c).HasFlag(CubeFlag.MiddleLayer)))
     {
         Cube corner = rubik.Cubes.First(c => c.IsCorner && (rubik.GetTargetFlags(c) & ~CubeFlag.BottomLayer) == (rubik.GetTargetFlags(edge) & ~CubeFlag.MiddleLayer));
         if (!rubik.IsCorrect(corner) || !rubik.IsCorrect(edge))
         {
             yield return(new Tuple <Cube, Cube>(edge, corner));
         }
     }
 }
Beispiel #14
0
        public void getValue()
        {
            Rubik myRubik = new Rubik();

            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            Permutation myPermutation = myRubik.getPermutation();

            Assert.AreEqual(10, myPermutation.getValue(1), "first floor");
            Assert.AreEqual(14, myPermutation.getValue(2), "second floor");
            Assert.AreEqual(24, myPermutation.getValue(3), "third floor");
        }
        protected override void Solve(Rubik cube)
        {
            Rubik         = cube.DeepClone();
            _coordCube    = ToCoordCube(cube);
            this.MaxDepth = 30;
            this.TimeOut  = 10000;
            Algorithm     = new Algorithm();
            InitStandardCube();

            GetSolution();
            RemoveUnnecessaryMoves();
        }
        public override void Solve(Rubik cube)
        {
            this.Rubik    = cube.DeepClone();
            _coordCube    = TwoPhaseHelpers.ToCoordCube(cube);
            this.MaxDepth = 30;
            this.TimeOut  = 10000;
            Algorithm     = new Algorithm(null);
            InitStandardCube();

            GetSolution();
            Algorithm = Algorithm.RemoveUnnecessaryMoves(Algorithm);
        }
Beispiel #17
0
        public void testChangesOnlyInThirdFloor_partI()
        {
            Permutation myPermutation = new Permutation();
            Rubik       myCube        = new Rubik();

            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.U)
                                                         , new Location(Face.F, Face.R), new Position(Face.U, Face.B)));
            Assert.AreEqual(true, myCube.changesOnlyInThirdFloor(myPermutation), "one");

            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.L)
                                                         , new Location(Face.F, Face.L), new Position(Face.U, Face.B)));
            Assert.AreEqual(false, myCube.changesOnlyInThirdFloor(myPermutation), "two");
        }
Beispiel #18
0
        /// <summary>
        /// Converts a rubik to a pattern
        /// </summary>
        /// <param name="r">Rubik </param>
        /// <returns>The pattern of the given rubik</returns>
        public static Pattern FromRubik(Rubik r)
        {
            Pattern            p        = new Pattern();
            List <PatternItem> newItems = new List <PatternItem>();

            foreach (CubePosition pos in Positions)
            {
                Cube cube = r.Cubes.First(c => r.GetTargetFlags(c) == pos.Flags);
                newItems.Add(new PatternItem(cube.Position, Solvability.GetOrientation(r, cube), pos.Flags));
            }
            p.Items = newItems;
            return(p);
        }
Beispiel #19
0
        private CoordCube ToCoordCube(Rubik rubik)
        {
            // get corner perm and orientation
            string[] corners = new string[N_CORNER] {
                "UFR", "UFL", "UBL", "URB", "DFR", "DFL", "DBL", "DRB"
            };
            byte[] cornerPermutation = new byte[N_CORNER];
            byte[] cornerOrientation = new byte[N_CORNER];
            for (int i = 0; i < N_CORNER; i++)
            {
                CubeFlag pos          = CubeFlagService.Parse(corners[i]);
                Cube     matchingCube = rubik.Cubes.First(c => c.Position.Flags == pos);
                CubeFlag targetPos    = rubik.GetTargetFlags(matchingCube);
                cornerOrientation[i] = (byte)Solvability.GetOrientation(rubik, matchingCube);

                for (int j = 0; j < N_CORNER; j++)
                {
                    if (corners[j] == CubeFlagService.ToNotationString(targetPos))
                    {
                        cornerPermutation[i] = (byte)(j + 1);
                    }
                }
            }

            // get edge perm and orientation
            string[] edges = new string[N_EDGE] {
                "UR", "UF", "UL", "UB", "DR", "DF", "DL", "DB", "FR", "FL", "BL", "RB"
            };
            byte[] edgePermutation = new byte[N_EDGE];
            byte[] edgeOrientation = new byte[N_EDGE];
            for (int i = 0; i < N_EDGE; i++)
            {
                CubeFlag pos          = CubeFlagService.Parse(edges[i]);
                Cube     matchingCube = rubik.Cubes.Where(c => c.IsEdge).First(c => c.Position.Flags.HasFlag(pos));
                CubeFlag targetPos    = rubik.GetTargetFlags(matchingCube);
                edgeOrientation[i] = (byte)Solvability.GetOrientation(rubik, matchingCube);

                for (int j = 0; j < N_EDGE; j++)
                {
                    if (CubeFlagService.ToNotationString(targetPos).Contains(edges[j]))
                    {
                        edgePermutation[i] = (byte)(j + 1);
                    }
                }
            }

            byte[] cornerInv = CoordCube.ToInversions(cornerPermutation);
            byte[] edgeInv   = CoordCube.ToInversions(edgePermutation);

            return(new CoordCube(cornerPermutation, edgePermutation, cornerOrientation, edgeOrientation));
        }
        public DialogParityCheckResult(Rubik rubik, Form parent = null)
        {
            InitializeComponent();
            this.ShowInTaskbar = false;
            if (parent != null)
            {
                this.Owner         = parent;
                this.StartPosition = FormStartPosition.CenterParent;
            }

            // Color test
            bool colors = Solvability.CorrectColors(rubik);

            lblColorTest.Text = colors ? "Passed" : "Failed";
            pbColorTest.Image = colors ? Properties.Resources.ok : Properties.Resources.cross_icon;

            if (!colors)
            {
                lblPermutationTest.Text = "Not tested";
                lblCornerTest.Text      = "Not tested";
                lblEdgeTest.Text        = "Not tested";

                pbCornerTest.Image      = Properties.Resources.questionmark;
                pbEdgeTest.Image        = Properties.Resources.questionmark;
                pbPermutationTest.Image = Properties.Resources.questionmark;
                lblHeader.Text          = "This cube is unsolvable.";
            }
            else
            {
                // Permutation parity test
                bool permutation = Solvability.PermutationParityTest(rubik);
                lblPermutationTest.Text = permutation ? "Passed" : "Failed";
                pbPermutationTest.Image = permutation ? Properties.Resources.ok : Properties.Resources.cross_icon;

                // Corner parity test
                bool corner = Solvability.CornerParityTest(rubik);
                lblCornerTest.Text = corner ? "Passed" : "Failed";
                pbCornerTest.Image = corner ? Properties.Resources.ok : Properties.Resources.cross_icon;

                // Edge parity test
                bool edge = Solvability.EdgeParityTest(rubik);
                lblEdgeTest.Text = edge ? "Passed" : "Failed";
                pbEdgeTest.Image = edge ? Properties.Resources.ok : Properties.Resources.cross_icon;

                lblHeader.Text = permutation && corner && edge && colors ? "This cube is solvable." : "This cube is unsolvable.";
            }
        }
Beispiel #21
0
        public void testIsDifferentItemsOnlyInSecondFloorLessThanThree_partI()
        {
            Permutation myPermutation = new Permutation();
            Rubik       myCube        = new Rubik();

            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.R)
                                                         , new Location(Face.F, Face.R), new Position(Face.U, Face.B)));
            Assert.AreEqual(true, myCube.isDifferentItemsOnlyInSecondFloorLessThanThree(myPermutation), "one");

            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.L)
                                                         , new Location(Face.F, Face.L), new Position(Face.U, Face.B)));
            Assert.AreEqual(true, myCube.isDifferentItemsOnlyInSecondFloorLessThanThree(myPermutation), "two");

            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.L)
                                                         , new Location(Face.B, Face.R), new Position(Face.U, Face.F)));
            Assert.AreEqual(false, myCube.isDifferentItemsOnlyInSecondFloorLessThanThree(myPermutation), "three");
        }
Beispiel #22
0
        public void setPermutationTest()
        {
            Permutation myPermutation = new Permutation();

            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.U), new Location(Face.F, Face.U), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.R), new Location(Face.F, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.L), new Location(Face.F, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.D), new Location(Face.F, Face.D), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.U), new Location(Face.B, Face.U), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.R), new Location(Face.B, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.L), new Location(Face.B, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.D), new Location(Face.B, Face.D), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.U, Face.R), new Location(Face.U, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.U, Face.L), new Location(Face.U, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.D, Face.R), new Location(Face.D, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.D, Face.L), new Location(Face.D, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.U, Face.R), new Location(Face.F, Face.U, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.U, Face.L), new Location(Face.F, Face.U, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.D, Face.R), new Location(Face.F, Face.D, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.F, Face.D, Face.L), new Location(Face.F, Face.D, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.U, Face.R), new Location(Face.B, Face.U, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.U, Face.L), new Location(Face.B, Face.U, Face.L), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.D, Face.R), new Location(Face.B, Face.D, Face.R), new Position(Face.U, Face.F)));
            myPermutation.addCubicleData(new CubeCubicle(new Location(Face.B, Face.D, Face.L), new Location(Face.B, Face.D, Face.L), new Position(Face.U, Face.F)));

            Rubik myRubik = new Rubik();



            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));

            myRubik.setPermutation(myPermutation);
            AssistAssertRubik.checkEntireCube(myRubik);
        }
        public DialogSolutionFinder(CubeSolver solver, Rubik rubik, Form parent = null)
        {
            this.solver = solver;
            InitializeComponent();
            if (parent != null)
            {
                this.Owner         = parent;
                this.StartPosition = FormStartPosition.CenterParent;
            }
            this.ShowInTaskbar = false;

            AddStepLabels(solver);

            solver.TrySolveAsync(rubik);
            solver.OnSolutionStepCompleted += solver_OnSolutionStepCompleted;
            solver.OnSolutionError         += solver_OnSolutionError;

            stepLabels[currentIndex].Text = "In progress ...";
            stepImgs[currentIndex].Image  = Properties.Resources.refresh;
        }
        private void SolveAsync(Rubik rubik)
        {
            bool solvable = Solvability.FullTest(rubik);

            if (solvable)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Solve(rubik);
                sw.Stop();
                if (OnSolutionStepCompleted != null)
                {
                    OnSolutionStepCompleted(this, new SolutionStepCompletedEventArgs(this.Name, true, this.Algorithm, (int)sw.ElapsedMilliseconds));
                }
                solvingThread.Abort();
            }
            else
            {
                this.BroadcastOnSolutionError(this.Name, "Unsolvable cube");
            }
        }
Beispiel #25
0
        /// <summary>
        /// Initializes a new instance of the CubeModel class
        /// </summary>
        /// <param name="rubik">Rubik's Cube that has to be drawn</param>
        public CubeModel(Rubik rubik)
        {
            this.Rubik         = rubik;
            this.Rotation      = new double[] { 0, 0, 0 };
            this.Moves         = new Queue <RotationInfo>();
            this.MouseHandling = true;
            this.DrawingMode   = RubiksCubeLib.CubeModel.DrawingMode.ThreeDimensional;
            this.State         = "Ready";
            this.RotationSpeed = 250;

            InitColorPicker();
            ResetLayerRotation();
            InitSelection();
            InitRenderer();

            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);
        }
Beispiel #26
0
        private void SolveAsync(Rubik rubik)
        {
            bool solvable = Solvability.FullTest(rubik);

            if (solvable)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Solve(rubik);
                sw.Stop();

                Algorithm = Algorithm.RemoveUnnecessaryMoves(Algorithm);
                var args = new SolutionStepCompletedEventArgs(Name, true, Algorithm, (int)sw.ElapsedMilliseconds);
                OnSolutionStepCompleted?.Invoke(this, args);

                solvingThread.Abort();
            }
            else
            {
                this.BroadcastOnSolutionError(this.Name, "Unsolvable cube");
            }
        }
Beispiel #27
0
        public void constuctorTest()
        {
            Rubik myRubik            = new Rubik();
            int   numberOfAssertions = 0;

            foreach (Face firstFaceDimension in Enum.GetValues(typeof(Face)))
            {
                foreach (Face secondFaceDimension in Enum.GetValues(typeof(Face)))
                {
                    if (firstFaceDimension != secondFaceDimension &&
                        firstFaceDimension.getOpposite() != secondFaceDimension
                        //                        && firstFaceDimension != Face.NOTDEFINED
                        //                        && secondFaceDimension != Face.NOTDEFINED
                        )
                    {
                        Assert.AreEqual(true,
                                        (new Location(firstFaceDimension, secondFaceDimension))
                                        .equals(myRubik.getOriginalLocationOfCurrentCubicleInLocation(new Location(firstFaceDimension, secondFaceDimension))));
                        numberOfAssertions++;
                    }
                }
            }
            Assert.AreEqual(24, numberOfAssertions);
        }
 /// <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);
 }
 /// <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));
 }
 /// <summary>
 /// Initializes the StandardCube
 /// </summary>
 protected void InitStandardCube()
 {
     StandardCube = Rubik.GenStandardCube();
 }