Ejemplo n.º 1
0
        /// <summary>
        /// this function moves the corner to the bottom layer
        /// </summary>
        /// <param name="front_face_color">this parameter is a color from a face</param>
        private void PutCornerInBottomLayer(Color front_face_color)
        {
            Orientor front_face = Cube.GetOrientation(front_face_color);

            cube.Rotate(front_face.right, Direction.CounterClockwise);
            cube.Rotate(front_face.bottom, Direction.CounterClockwise);
            cube.Rotate(front_face.right, Direction.Clockwise);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// this functions does the corner algorithm that moves the corners around
        /// </summary>
        /// <param name="front_face_color">this parameter is a color that will make a block</param>
        private void CornersRotation(Color front_face_color)
        {
            Orientor front_face = Cube.GetOrientation(front_face_color);

            //Ri Di R D
            cube.Rotate(front_face.right, Direction.CounterClockwise);
            cube.Rotate(front_face.bottom, Direction.CounterClockwise);
            cube.Rotate(front_face.right, Direction.Clockwise);
            cube.Rotate(front_face.bottom, Direction.Clockwise);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// this function does the final turns to complete the cube
        /// </summary>
        private void CornersRotationFinal()
        {
            Orientor front_face = Cube.GetOrientation(Color.Green);

            //Ri Di R D
            cube.Rotate(front_face.left, Direction.CounterClockwise);
            cube.Rotate(front_face.top, Direction.CounterClockwise);
            cube.Rotate(front_face.left, Direction.Clockwise);
            cube.Rotate(front_face.top, Direction.Clockwise);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// this function is the algorithm used in solving the bottom face
        /// </summary>
        /// <param name="front_face_color">this parameter is the front facing face</param>
        private void SolveBottomEdgesRotation(Color front_face_color)
        {
            Orientor front_face = Cube.GetOrientation(front_face_color);

            // R U R' U R U U R'
            // L B L' B L B B L'
            cube.Rotate(front_face.left, Direction.Clockwise);
            cube.Rotate(front_face.bottom, Direction.Clockwise);
            cube.Rotate(front_face.left, Direction.CounterClockwise);
            cube.Rotate(front_face.bottom, Direction.Clockwise);
            cube.Rotate(front_face.left, Direction.Clockwise);
            cube.Rotate(front_face.bottom, Direction.Clockwise);
            cube.Rotate(front_face.bottom, Direction.Clockwise);
            cube.Rotate(front_face.left, Direction.CounterClockwise);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// this function will solve the middle layer
        /// </summary>
        /// <param name="front">this parameter is used to find a front face</param>
        public void SolveMiddleLayer(Color front)
        {
            Edge gr_edge_corr_orient = new Edge(Color.Hidden, Color.Hidden, Color.Green, Color.Hidden, Color.Hidden, Color.Red);
            Edge rb_edge_corr_orient = new Edge(Color.Hidden, Color.Hidden, Color.Hidden, Color.Blue, Color.Hidden, Color.Red);
            Edge bo_edge_corr_orient = new Edge(Color.Hidden, Color.Hidden, Color.Hidden, Color.Blue, Color.Purple, Color.Hidden);
            Edge go_edge_corr_orient = new Edge(Color.Hidden, Color.Hidden, Color.Green, Color.Hidden, Color.Purple, Color.Hidden);

            /* BASE CASE */
            if (front > Color.Blue) // All sides have been solved
            {
                return;
            }

            Orientor orientation = Cube.GetOrientation(front);
            Edge     target_edge = (Edge)cube.GetBlock(orientation.left, true, cube.GetBlock(orientation.front, true))[0];

            if (target_edge.Equals(gr_edge_corr_orient) ||
                target_edge.Equals(rb_edge_corr_orient) ||
                target_edge.Equals(bo_edge_corr_orient) ||
                target_edge.Equals(go_edge_corr_orient))
            {
                front++;
            }
            else if (target_edge.bottom == orientation.left || target_edge.bottom == orientation.front) // Edge is on bottom
            {
                Color side_where_found = RotateBottomEdgeIntoPlace(orientation, target_edge);

                if (side_where_found == orientation.front)
                {
                    MiddleLayerEdgeFrontRotation(orientation);
                }
                else
                {
                    MiddleLayerEdgeLeftRotation(orientation);
                }

                front++;
            }
            else // Edge is in middle layer
            {
                // Find our edge piece by rotating the cube and looking for it on the right
                Orientor target_orient = FindBlockInMiddleLayer(target_edge);
                MiddleLayerEdgeLeftRotation(target_orient);
            }

            //gui.Refresh();
            SolveMiddleLayer(front);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// this function is the algorithm for the bottom corners
        /// </summary>
        /// <param name="front_face_color">this parameter is the face at the front</param>
        private void SolveBottomCornersRotation(Color front_face_color)
        {
            Orientor front_face = Cube.GetOrientation(front_face_color);

            //U R U' L' U R' U' L ::
            //D L D' R' D L' D' R

            cube.Rotate(front_face.bottom, Direction.Clockwise);
            cube.Rotate(front_face.left, Direction.Clockwise);
            cube.Rotate(front_face.bottom, Direction.CounterClockwise);
            cube.Rotate(front_face.right, Direction.CounterClockwise);
            cube.Rotate(front_face.bottom, Direction.Clockwise);
            cube.Rotate(front_face.left, Direction.CounterClockwise);
            cube.Rotate(front_face.bottom, Direction.CounterClockwise);
            cube.Rotate(front_face.right, Direction.Clockwise);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// this function will find the middle layer block
        /// </summary>
        /// <param name="target_edge">this parameter will be the edge that will be used for the left face</param>
        /// <returns>a block that is in the middle layer</returns>
        private Orientor FindBlockInMiddleLayer(Edge target_edge)
        {
            Orientor orient;
            Color    color = Color.Red;

            while (color <= Color.Blue)
            {
                orient = Cube.GetOrientation(color);
                Edge left = (Edge)cube.GetBlock(0, 1, color);

                if (left.Equals(target_edge))
                {
                    return(orient);
                }
                else
                {
                    color++;
                }
            }

            throw new Exception("Middle layer failure");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// this function will solve the white cross
        /// </summary>
        public void SolveWhiteCross()
        {
            while (!WhiteCrossSolved())
            {
                List <Block> yellow_slice = cube.GetSlice(Color.Yellow);
                Orientor     front_face;
                Edge         edge_piece;
                Boolean      block_with_white_on_bottom = false, block_with_white_in_center, block_on_top_not_oriented_correctly;

                //will take any edge piece with the white on the bottom and place it where it needs to be.
                foreach (Block block_in_yellow_slice in yellow_slice)
                {
                    //if the blocks in the yellow slice that have a white color also have a green color
                    //is an edge piece
                    if (cube.GetBlock(Color.Green, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1)
                    {
                        block_with_white_on_bottom = true;

                        edge_piece = (Edge)cube.GetBlock(Color.Green, true, cube.GetBlock(Color.White, true, yellow_slice))[0];

                        //while the edgepeice isn't directly under the side it needs to be,
                        //cube.Rotate it until it is.
                        while (!edge_piece.Equals(cube.GetBlock(1, 0, 0)))
                        {
                            cube.Rotate(Color.Yellow, Direction.Clockwise);
                        }

                        //get the block that will give you the orientation to use as the front face
                        front_face = Cube.GetOrientation(Color.Green);

                        PlaceBottomEdgePieceInCross(edge_piece, front_face);
                        //yellow_slice = cube.GetSlice(Color.Yellow);
                        break;
                    }
                    else if (cube.GetBlock(Color.Purple, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1)
                    {
                        block_with_white_on_bottom = true;

                        edge_piece = (Edge)cube.GetBlock(Color.Purple, true, cube.GetBlock(Color.White, true, yellow_slice))[0];

                        while (!edge_piece.Equals(cube.GetBlock(0, 0, 1)))
                        {
                            cube.Rotate(Color.Yellow, Direction.Clockwise);
                        }

                        front_face = Cube.GetOrientation(Color.Purple);

                        PlaceBottomEdgePieceInCross(edge_piece, front_face);
                        //yellow_slice = cube.GetSlice(Color.Yellow);
                        break;
                    }
                    else if (cube.GetBlock(Color.Red, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1)
                    {
                        block_with_white_on_bottom = true;

                        edge_piece = (Edge)cube.GetBlock(Color.Red, true, cube.GetBlock(Color.White, true, yellow_slice))[0];

                        while (!edge_piece.Equals(cube.GetBlock(2, 0, 1)))
                        {
                            cube.Rotate(Color.Yellow, Direction.Clockwise);
                        }

                        front_face = Cube.GetOrientation(Color.Red);

                        PlaceBottomEdgePieceInCross(edge_piece, front_face);
                        //yellow_slice = cube.GetSlice(Color.Yellow);
                        break;
                    }
                    else if (cube.GetBlock(Color.Blue, true, cube.GetBlock(Color.White, true, yellow_slice)).Count == 1)
                    {
                        block_with_white_on_bottom = true;

                        edge_piece = (Edge)cube.GetBlock(Color.Blue, true, cube.GetBlock(Color.White, true, yellow_slice))[0];
                        //Block temp = cube.GetBlock(1, 0, 2);

                        while (!edge_piece.Equals(cube.GetBlock(1, 0, 2)))
                        {
                            cube.Rotate(Color.Yellow, Direction.Clockwise);
                        }

                        front_face = Cube.GetOrientation(Color.Blue);

                        PlaceBottomEdgePieceInCross(edge_piece, front_face);
                        break;
                    }
                    else
                    {
                        block_with_white_on_bottom = false;
                    }
                }

                /*
                 * if edge piece is in the center, then put it in the bottom layer,
                 * and the above will put it in the correct position.
                 */
                if (block_with_white_in_center = cube.GetBlock(0, 1, 0).HasColor(Color.White))
                {
                    cube.Rotate(Color.Green, Direction.CounterClockwise);
                }
                else if (block_with_white_in_center = cube.GetBlock(0, 1, 2).HasColor(Color.White))
                {
                    cube.Rotate(Color.Purple, Direction.CounterClockwise);
                }
                else if (block_with_white_in_center = cube.GetBlock(2, 1, 2).HasColor(Color.White))
                {
                    cube.Rotate(Color.Blue, Direction.CounterClockwise);
                }
                else if (block_with_white_in_center = cube.GetBlock(2, 1, 0).HasColor(Color.White))
                {
                    cube.Rotate(Color.Red, Direction.CounterClockwise);
                }
                else
                {
                    block_with_white_in_center = false;
                }

                if (block_with_white_in_center)
                {
                    continue;
                }


                /*
                 * if edge piece is in the correct position, but the incorrect
                 * orientation, then put it in the bottom layer, and let the
                 * placeBottomEdgePieceInCross(...) function handle puting it
                 * in the correct position
                 */
                if (block_on_top_not_oriented_correctly = cube.GetBlock(1, 2, 0).front == Color.White)
                {
                    front_face = Cube.GetOrientation(Color.Green);
                }
                else if (block_on_top_not_oriented_correctly = cube.GetBlock(0, 2, 1).left == Color.White)
                {
                    front_face = Cube.GetOrientation(Color.Purple);
                }
                else if (block_on_top_not_oriented_correctly = cube.GetBlock(1, 2, 2).back == Color.White)
                {
                    front_face = Cube.GetOrientation(Color.Blue);
                }
                else if (block_on_top_not_oriented_correctly = cube.GetBlock(2, 2, 1).right == Color.White)
                {
                    front_face = Cube.GetOrientation(Color.Red);
                }
                else
                {
                    front_face = null;
                    block_on_top_not_oriented_correctly = false;
                }

                if (block_on_top_not_oriented_correctly)
                {
                    cube.Rotate(front_face.front, Direction.Clockwise);
                    cube.Rotate(front_face.front, Direction.Clockwise);
                }


                /*
                 * if the cross is solved, but incorreclty oriented
                 */
                if (!block_with_white_on_bottom &&
                    !block_with_white_in_center &&
                    !block_on_top_not_oriented_correctly)
                {
                    CheckWhiteCross();
                }
            }
        }