Beispiel #1
0
        private RSide Step4GetOppositeForSide(RSide side)
        {
            switch (side)
            {
            case RSide.Front:
                return(RSide.Back);

            case RSide.Left:
                return(RSide.Right);

            case RSide.Right:
                return(RSide.Left);

            case RSide.Back:
                return(RSide.Front);

            case RSide.Down:
                return(RSide.Up);

            case RSide.Up:
                return(RSide.Down);

            default:
                throw new ArgumentOutOfRangeException(nameof(side), side, "Wrong side passed");
            }
        }
Beispiel #2
0
        public void RotateSide(RSide targetSide, bool clockwise = true)
        {
            var side = Sides[(sbyte)targetSide];

            RotateSelectedSideFaces(side, clockwise);
            RotateSelectedNeighbours(targetSide, side, clockwise);
        }
Beispiel #3
0
        private void Step3BuildCross()
        {
            //there could be only 4 possible configurations: empty, L, line and full cross
            const RSide rMimic            = RSide.Left;
            const RSide uMimic            = RSide.Down;
            var         correctFacesCount = 0;
            var         clrs = new[] { _dFaces[0, 1].Color, _dFaces[1, 0].Color, _dFaces[2, 1].Color, _dFaces[1, 2].Color };

            void CrossBuildingCommandsSequence()
            {
                PerformRotation(RSide.Front, RotationType.Clockwise);
                PerformRotation(rMimic, RotationType.Clockwise);
                PerformRotation(uMimic, RotationType.Clockwise);
                PerformRotation(rMimic, RotationType.CounterClockwise);
                PerformRotation(uMimic, RotationType.CounterClockwise);
                PerformRotation(RSide.Front, RotationType.CounterClockwise);
            }

            foreach (var color in clrs)
            {
                correctFacesCount = color == _dCenterColor ? correctFacesCount + 1 : correctFacesCount;
            }
            if (correctFacesCount == 0)
            {
                CrossBuildingCommandsSequence();
            }
            while (_dFaces[1, 0].Color == _dCenterColor || _dFaces[2, 1].Color != _dCenterColor)
            {
                PerformRotation(uMimic, RotationType.Clockwise);
            }
            while (!Step3CrossConditionsMet())
            {
                CrossBuildingCommandsSequence();
            }
        }
Beispiel #4
0
        //for step4 points of interests are

        /*
         *       [ ][ ][ ]
         *       [ ][ ][ ]
         *       [ ][ ][ ]
         * [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
         * [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
         * [3][ ][0][0][ ][1][1][ ][2][2][ ][3]
         *       [0][ ][1]
         *       [ ][ ][ ]
         *       [3][ ][2]
         */

        public void SolveStep4()
        {
            const RSide rMimic             = RSide.Left;
            const RSide dMimic             = RSide.Up;
            const RSide uMimic             = RSide.Down;
            var         triplets           = GetCurrentLowerTriplets();
            var         lastRotationsCount = _rotationsMade.Count;

            if (!Step4TripletsAtCorrectCorners(triplets) && _rotationsMade.Count < 250)
            {
                var correctRightSide = Step4GetCorrectRightSide(ref triplets);
                var correctLeftSide  = Step4GetOppositeForSide(correctRightSide);

                while (!Step4TripletsAtCorrectCorners(triplets))
                {
                    Step4PerformCornersSwapAlgorithm(correctLeftSide, correctRightSide);
                }
            }

            while (!Step4IsRubikComplete())
            {
                if (_dFaces[0, 0].Color == _dCenterColor)
                {
                    PerformRotation(uMimic, RotationType.Clockwise);
                }
                else
                {
                    PerformRotation(rMimic, RotationType.CounterClockwise);
                    PerformRotation(dMimic, RotationType.CounterClockwise);
                    PerformRotation(rMimic, RotationType.Clockwise);
                    PerformRotation(dMimic, RotationType.Clockwise);
                }
            }

            if (_lFaces[0, 2].Color == _fCenterColor)
            {
                PerformRotation(uMimic, RotationType.Clockwise);
            }
            else if (_lFaces[0, 2].Color == _bCenterColor)
            {
                PerformRotation(uMimic, RotationType.CounterClockwise);
            }
            else if (_lFaces[0, 2].Color == _rCenterColor)
            {
                PerformRotation(uMimic, RotationType.Halfturn);
            }

            if (_lFaces[1, 2].Color != _lCenterColor)
            {
                return;
            }

            RotationsCountStep4 = _rotationsMade.Count - lastRotationsCount;
        }
Beispiel #5
0
 private void Step2PerformRightAlgorithm(RSide frontMimic, RSide rightMimic)
 {
     // U R U' R' U' F' U F
     //instead of up we use down because we do not turn rubik upside down programmatically
     PerformRotation(RSide.Down, RotationType.Clockwise);
     PerformRotation(rightMimic, RotationType.Clockwise);
     PerformRotation(RSide.Down, RotationType.CounterClockwise);
     PerformRotation(rightMimic, RotationType.CounterClockwise);
     PerformRotation(RSide.Down, RotationType.CounterClockwise);
     PerformRotation(frontMimic, RotationType.CounterClockwise);
     PerformRotation(RSide.Down, RotationType.Clockwise);
     PerformRotation(frontMimic, RotationType.Clockwise);
 }
Beispiel #6
0
 private void Step2PerformLeftAlgorithm(RSide frontMimic, RSide leftMimic)
 {
     // U' L' U L U F U' F'
     //instead of up we use down because we do not turn rubik upside down programmatically
     PerformRotation(RSide.Down, RotationType.CounterClockwise);
     PerformRotation(leftMimic, RotationType.CounterClockwise);
     PerformRotation(RSide.Down, RotationType.Clockwise);
     PerformRotation(leftMimic, RotationType.Clockwise);
     PerformRotation(RSide.Down, RotationType.Clockwise);
     PerformRotation(frontMimic, RotationType.Clockwise);
     PerformRotation(RSide.Down, RotationType.CounterClockwise);
     PerformRotation(frontMimic, RotationType.CounterClockwise);
 }
Beispiel #7
0
        private void Step3PerformPairsSwap(RSide rMimic)
        {
            // R U R' U R U2 R' U
            // instead of up we are using down, because we won't turn rubik upside down programmatically
            const RSide uMimic = RSide.Down;

            PerformRotation(rMimic, RotationType.Clockwise);
            PerformRotation(uMimic, RotationType.Clockwise);
            PerformRotation(rMimic, RotationType.CounterClockwise);
            PerformRotation(uMimic, RotationType.Clockwise);
            PerformRotation(rMimic, RotationType.Clockwise);
            PerformRotation(uMimic, RotationType.Halfturn);
            PerformRotation(rMimic, RotationType.CounterClockwise);
            PerformRotation(uMimic, RotationType.Clockwise);
        }
Beispiel #8
0
        private void Step4PerformCornersSwapAlgorithm(RSide lMimic, RSide rMimic)
        {
            // U R U' L' U R' U' L
            // instead of up we are using down, because we won't turn rubik upside down programmatically

            var uMimic = RSide.Down;

            PerformRotation(uMimic, RotationType.Clockwise);
            PerformRotation(rMimic, RotationType.Clockwise);
            PerformRotation(uMimic, RotationType.CounterClockwise);
            PerformRotation(lMimic, RotationType.CounterClockwise);
            PerformRotation(uMimic, RotationType.Clockwise);
            PerformRotation(rMimic, RotationType.CounterClockwise);
            PerformRotation(uMimic, RotationType.CounterClockwise);
            PerformRotation(lMimic, RotationType.Clockwise);
        }
Beispiel #9
0
        private void Step0SwapNearPairsParts(RSide side0, RSide side1)
        {
            //swaps upper edges parts (if they are neighbours) without cross breaking

            if (side0 == RSide.Left && side1 == RSide.Front)
            {
                PerformRotation(RSide.Front, RotationType.CounterClockwise);
                PerformRotation(RSide.Up, RotationType.CounterClockwise);
                PerformRotation(RSide.Front, RotationType.Clockwise);
                PerformRotation(RSide.Up, RotationType.Clockwise);
                PerformRotation(RSide.Front, RotationType.CounterClockwise);
            }
            else if (side0 == RSide.Front && side1 == RSide.Right)
            {
                PerformRotation(RSide.Right, RotationType.CounterClockwise);
                PerformRotation(RSide.Up, RotationType.CounterClockwise);
                PerformRotation(RSide.Right, RotationType.Clockwise);
                PerformRotation(RSide.Up, RotationType.Clockwise);
                PerformRotation(RSide.Right, RotationType.CounterClockwise);
            }
            else if (side0 == RSide.Right && side1 == RSide.Back)
            {
                PerformRotation(RSide.Back, RotationType.CounterClockwise);
                PerformRotation(RSide.Up, RotationType.CounterClockwise);
                PerformRotation(RSide.Back, RotationType.Clockwise);
                PerformRotation(RSide.Up, RotationType.Clockwise);
                PerformRotation(RSide.Back, RotationType.CounterClockwise);
            }
            else if (side0 == RSide.Back && side1 == RSide.Left)
            {
                PerformRotation(RSide.Left, RotationType.CounterClockwise);
                PerformRotation(RSide.Up, RotationType.CounterClockwise);
                PerformRotation(RSide.Left, RotationType.Clockwise);
                PerformRotation(RSide.Up, RotationType.Clockwise);
                PerformRotation(RSide.Left, RotationType.CounterClockwise);
            }
        }