Пример #1
0
        public bool IsMatch(Cube cube)
        {
            for (int f = 0; f < 4; f++)
            {
                CubeFace face = CubeSolver.MiddleLayerFaces[f];

                CubeColor[] tiles =
                {
                    cube.At(face, 6),
                    cube.At(face, 7),
                    cube.At(face, 8)
                };

                int delta0 = SolvingUtility.NormalizeCount(middleLayerColors[tiles[0]] - middleLayerColors[tiles[1]]);
                int delta1 = SolvingUtility.NormalizeCount(middleLayerColors[tiles[0]] - middleLayerColors[tiles[2]]);
                int delta2 = SolvingUtility.NormalizeCount(middleLayerColors[tiles[1]] - middleLayerColors[tiles[2]]);

                if (delta0 != patternData[f][0] || delta1 != patternData[f][1] || delta2 != patternData[f][2])
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Bring einen weißen falsch orientierten Kantenstein auf der mittleren Ebene in die richtige Position relativ zum Pivotstein.
        /// </summary>
        /// <param name="edge">Der Kantenstein, der in die richtige Position gebracht werden soll</param>
        protected void HandleFalseOrientatedStone(EdgeStone edge)
        {
            if (Array.TrueForAll(MiddleLayerFaces, f => edge.GetColorPosition(WHITE).Face != f) || edge.GetColorPosition(WHITE).Tile == 3 || edge.GetColorPosition(WHITE).Tile == 5)
            {
                throw new ArgumentOutOfRangeException("Der weiße Kantenstein muss sich in der oberen oder unteren Ebene befinden und die weiße Fläche muss auf einer der seitlichen Seiten (Orange, Grün, Rot, Blau) sein", nameof(edge));
            }

#if DEBUG
            Log.LogStuff("Handle false orientated stone\r\n\t" + edge.ToString());
#endif

            // get edge information
            CubeColor secndColor = GetSecondColor(edge);
            Position  whitePos   = edge.GetColorPosition(WHITE);

            // get face of white pos
            int middleLayerFaceID = Array.IndexOf(MiddleLayerFaces, whitePos.Face);
            // face in anti clockwise rotation of white position face
            CubeFace leftFace = MiddleLayerFaces[(middleLayerFaceID + 3) % 4];
            // face in clockwise roation of white position face
            CubeFace rightFace = MiddleLayerFaces[(middleLayerFaceID + 1) % 4];

            int leftDelta  = Math.Abs(SolvingUtility.NormalizeCount(SolvingUtility.GetDelta(secndColor, leftFace, UP), -1));
            int rightDelta = Math.Abs(SolvingUtility.NormalizeCount(SolvingUtility.GetDelta(secndColor, rightFace, UP), -1));

            // on up layer
            if (whitePos.Tile == 1)
            {
                // move edge to middle layer
                if (leftDelta < rightDelta)
                {
                    DoMove(whitePos.Face, -1);
                }
                else
                {
                    DoMove(whitePos.Face);
                }
                HandleStoneMiddleLayer(edge);
            }
            else
            {
                // check if the face must rotated back after stone handling
                int[] tiles   = { 3, 7, 5, 1 };
                bool  rotBack = cube.At(UP, tiles[middleLayerFaceID]) == WHITE;

                // move edge to middle layer
                int direction = leftDelta > rightDelta ? 1 : -1;
                DoMove(whitePos.Face, direction);

                HandleStoneMiddleLayer(edge);

                if (rotBack)
                {
                    DoMove(whitePos.Face, -direction);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Gibt die Anzahl der Züge zurück, die benötigt wird, um den Kantenstein in die richtige Position zu bringen.
        /// </summary>
        /// <param name="edge">Der Kantenstein, der in die richtige Position gebracht werden soll</param>
        /// <returns></returns>
        protected int GetStoneRating(EdgeStone edge)
        {
            // on white face and same delta as pivot stone
            if (IsEdgeRight(edge))
            {
                return(0);
            }

            Position whitePosition = edge.GetColorPosition(WHITE);
            int      edgeDelta;

            // on white face and not same delta as pivot stone or on yellow face
            if (whitePosition.Face == UP || whitePosition.Face == DOWN)
            {
                // get delta of edge
                if (whitePosition.Face == DOWN)
                {
                    edgeDelta = SolvingUtility.GetDelta(
                        GetSecondColor(edge),                        // second color
                        edge.GetColorPosition(c => c != WHITE).Face, // second color face color
                        UP);                                         // face to rotate
                }
                else
                {
                    edgeDelta = GetDelta(edge);
                }

                // return 2 + moves white face count
                int sortingMoves = Math.Abs(SolvingUtility.NormalizeCount(edgeDelta - WhiteFaceOrientation, -1));
                return(2 + sortingMoves);
            }
            // on middle layer
            else
            {
                switch (whitePosition.Tile)
                {
                // false orientated on white face
                case 1:
                    edgeDelta = SolvingUtility.GetDelta(
                        GetSecondColor(edge),              //second color
                        edge.GetColorPosition(WHITE).Face, // middle layer face with white side of edge
                        UP);                               //face to rotate
                    int edgePivotDelta = SolvingUtility.NormalizeCount(edgeDelta - WhiteFaceOrientation);

                    // return number of moves
                    return((edgePivotDelta % 2) * -1 + 3);

                // false orientated on yellow face
                case 7:
                    // this position can always solved in 3 moves
                    return(3);

                // on middle layer
                default:
                    edgeDelta = SolvingUtility.GetDelta(
                        edge.GetColors().First(c => c != WHITE),     // second color
                        edge.GetColorPosition(c => c != WHITE).Face, // second color face color
                        UP);                                         // face to rotate
                    int sortingMoves = Math.Abs(SolvingUtility.NormalizeCount(edgeDelta - WhiteFaceOrientation, -1));
                    return(1 + sortingMoves);
                }
            }
        }