public void Solve()
        {
            while (!RubixCubeStatusEvaluator.SecondLayerIsSolved(_cube))
            {
                var backEdges = _cube.GetBackEdges();
                if (backEdges.All(b => b.HasColour(Colour.Yellow)))
                {
                    RotateIncorrectSideEdgeToBack();
                }

                while (GetSolvableEdge() == null)
                {
                    _cube.RotateClockwise(Side.Back);
                }

                SolveBackEdge(GetSolvableEdge());
            }
        }
Beispiel #2
0
        public void RotateClockwise_CorrectlyRotatesTheFrontFace()
        {
            cube.RotateClockwise(Side.Front);
            var face = cube.GetFace(Side.Front);

            Assert.AreEqual(Colour.Blue, face[0, 0].Left);
            Assert.AreEqual(Colour.White, face[0, 0].Front);
            Assert.AreEqual(Colour.Red, face[0, 0].Top);
            Assert.AreEqual(Colour.Green, face[2, 2].Right);
            Assert.AreEqual(Colour.White, face[2, 2].Front);
            Assert.AreEqual(Colour.Orange, face[2, 2].Bottom);
        }
        private void ReorganiseMiddleEdges()
        {
            while (!RubixCubeStatusEvaluator.CrossIsFormed(_cube, Side.Back))
            {
                var middleEdges       = GetMiddleEdges();
                var numIncorrectEdges = middleEdges.Count(b => b.isCorrect);

                if (numIncorrectEdges == 2)
                {
                    var firstIncorrectEdge = middleEdges.First(b => !b.isCorrect);
                    var startNode          = middleEdges.Find(firstIncorrectEdge);
                    if (startNode == null)
                    {
                        throw new Exception("There should be an incorrect edge");
                    }

                    if (startNode.Next != null && !startNode.Next.Value.isCorrect) // TODO: managed to get a NullReferenceException here...
                    {
                        var sideToRotate = firstIncorrectEdge.index switch
                        {
                            (0, 1) => Side.Right,
                            (1, 2) => Side.Top,
                            (2, 1) => Side.Left,
                            (1, 0) => Side.Bottom,
                            _ => throw new Exception("The selected block is not a middle edge")
                        };

                        PerformRuRuRuuRuRotation(sideToRotate);
                    }
                    else if (startNode.Previous != null && !startNode.Previous.Value.isCorrect)
                    {
                        var sideToRotate = firstIncorrectEdge.index switch
                        {
                            (0, 1) => Side.Bottom,
                            (1, 2) => Side.Right,
                            (2, 1) => Side.Top,
                            (1, 0) => Side.Left,
                            _ => throw new Exception("The selected block is not a middle edge")
                        };

                        PerformRuRuRuuRuRotation(sideToRotate);
                    }
                    else
                    {
                        switch (firstIncorrectEdge.index)
                        {
                        case (0, 1):
                        case (2, 1):
                            PerformRuRuRuuRuRotation(Side.Bottom);
                            PerformRuRuRuuRuRotation(Side.Left);
                            PerformRuRuRuuRuRotation(Side.Bottom);
                            break;

                        case (1, 2):
                        case (1, 0):
                            PerformRuRuRuuRuRotation(Side.Right);
                            PerformRuRuRuuRuRotation(Side.Bottom);
                            PerformRuRuRuuRuRotation(Side.Right);
                            break;
                        }
                    }
                }
                else if (numIncorrectEdges == 3)
                {
                    var correctEdge  = middleEdges.First(b => b.isCorrect);
                    var sideToRotate = correctEdge.index switch
                    {
                        (0, 1) => Side.Left,
                        (1, 2) => Side.Bottom,
                        (2, 1) => Side.Right,
                        (1, 0) => Side.Top,
                        _ => throw new Exception("The selected block is not a middle edge")
                    };

                    PerformRuRuRuuRuRotation(sideToRotate);
                }
                else
                {
                    _cube.RotateClockwise(Side.Back);
                }
            }
        }
Beispiel #4
0
        private void RotateFrontEdgeToBack(Block block)
        {
            var sideToRotate = GetSideToRotate(block, Side.Front);

            _cube.RotateClockwise(sideToRotate);
            _cube.RotateClockwise(sideToRotate);
        }