Пример #1
0
        /// <summary>
        /// this functions checks if the white corners are in the right place
        /// </summary>
        /// <returns>true or false</returns>
        public Boolean WhiteCornersSolved()
        {
            Corner front_left_corner  = new Corner(Color.White, Color.Hidden, Color.Green, Color.Hidden, Color.Purple, Color.Hidden);
            Corner front_right_corner = new Corner(Color.White, Color.Hidden, Color.Green, Color.Hidden, Color.Hidden, Color.Red);
            Corner back_right_corner  = new Corner(Color.White, Color.Hidden, Color.Hidden, Color.Blue, Color.Hidden, Color.Red);
            Corner back_left_corner   = new Corner(Color.White, Color.Hidden, Color.Hidden, Color.Blue, Color.Purple, Color.Hidden);

            return(front_left_corner.Equals(cube.GetBlock(0, 2, 0)) &&
                   front_right_corner.Equals(cube.GetBlock(2, 2, 0)) &&
                   back_right_corner.Equals(cube.GetBlock(2, 2, 2)) &&
                   back_left_corner.Equals(cube.GetBlock(0, 2, 2)));
        }
Пример #2
0
        /// <summary>
        /// this function will solve the white corners and not stop until done
        /// </summary>
        public void SolveWhiteCorners()
        {
            //blocks that represent the corners in their proper positions
            Corner front_left_corner_in_prop_pos  = new Corner(Color.White, Color.Hidden, Color.Green, Color.Hidden, Color.Purple, Color.Hidden);
            Corner front_right_corner_in_prop_pos = new Corner(Color.White, Color.Hidden, Color.Green, Color.Hidden, Color.Hidden, Color.Red);
            Corner back_right_corner_in_prop_pos  = new Corner(Color.White, Color.Hidden, Color.Hidden, Color.Blue, Color.Hidden, Color.Red);
            Corner back_left_corner_in_prop_pos   = new Corner(Color.White, Color.Hidden, Color.Hidden, Color.Blue, Color.Purple, Color.Hidden);

            //get the corner block that has a green, white and Purple side
            Corner front_left_corner  = (Corner)cube.GetBlock(Color.Purple, false, cube.GetBlock(Color.Green, false, cube.GetBlock(Color.White, false)))[0];
            Corner front_right_corner = (Corner)cube.GetBlock(Color.Red, false, cube.GetBlock(Color.Green, false, cube.GetBlock(Color.White, false)))[0];
            Corner back_right_corner  = (Corner)cube.GetBlock(Color.Red, false, cube.GetBlock(Color.Blue, false, cube.GetBlock(Color.White, false)))[0];
            Corner back_left_corner   = (Corner)cube.GetBlock(Color.Purple, false, cube.GetBlock(Color.Blue, false, cube.GetBlock(Color.White, false)))[0];

            int     max_sequence_applications = 5;
            int     max_rotations             = 4;
            Boolean corner_in_bottom_layer    = true;

            while (!WhiteCornersSolved())
            {
                //if the front left corner peice isn't in the proper position
                if (!front_left_corner_in_prop_pos.Equals(front_left_corner))
                {
                    //if the front left corner piece is in the correct position, but oriented incorrecly
                    //then perform this step's rotation algorithm
                    if (front_left_corner.Equals(cube.GetBlock(0, 2, 0)))
                    {
                        CornersRotation(Color.Purple);
                    }

                    corner_in_bottom_layer = true;
                    //while the front left corner isn't directly underneith where it's supposed to be
                    //then cube.Rotate it until it is, will stop if doesn't find after 4 rotations
                    while (!front_left_corner.Equals(cube.GetBlock(0, 0, 0)) && (max_rotations-- > 0))
                    {
                        cube.Rotate(Color.Yellow, Direction.Clockwise);
                        //if you have cube.Rotated the yellow face four times, and the corner still isn't where
                        //it's supposed to be
                        if (max_rotations == 0)
                        {
                            corner_in_bottom_layer = false;
                        }
                    }

                    //reset max_rotations
                    max_rotations = 4;

                    //if corner not in the correct position, figure out where it is, and put it in the bottom layer.
                    if (!corner_in_bottom_layer)
                    {
                        if (front_left_corner.Equals(cube.GetBlock(2, 2, 0)))
                        {
                            PutCornerInBottomLayer(Color.Green);
                        }
                        else if (front_left_corner.Equals(cube.GetBlock(2, 2, 2)))
                        {
                            PutCornerInBottomLayer(Color.Red);
                        }
                        else if (front_left_corner.Equals(cube.GetBlock(0, 2, 2)))
                        {
                            PutCornerInBottomLayer(Color.Blue);
                        }
                        continue;
                    }
                    else
                    {
                        //while the corner piece isn't in the correct position, and while the max number of times
                        //the rotation algorithm (5 times) isn't exceeded: perfrom this step's rotation algorithm
                        while (!front_left_corner_in_prop_pos.Equals(front_left_corner) && (max_sequence_applications-- > 0))
                        {
                            CornersRotation(Color.Purple);
                            max_sequence_applications = 5;
                        }
                    }
                }
                if (!front_right_corner_in_prop_pos.Equals(front_right_corner))
                {
                    if (front_right_corner.Equals(cube.GetBlock(2, 2, 0)))
                    {
                        CornersRotation(Color.Green);
                    }

                    corner_in_bottom_layer = true;
                    while (!front_right_corner.Equals(cube.GetBlock(2, 0, 0)) && (max_rotations-- > 0))
                    {
                        cube.Rotate(Color.Yellow, Direction.Clockwise);
                        if (max_rotations == 0)
                        {
                            corner_in_bottom_layer = false;
                        }
                    }
                    max_rotations = 4;

                    if (!corner_in_bottom_layer)
                    {
                        if (front_right_corner.Equals(cube.GetBlock(0, 2, 0)))
                        {
                            PutCornerInBottomLayer(Color.Purple);
                        }
                        else if (front_right_corner.Equals(cube.GetBlock(2, 2, 2)))
                        {
                            PutCornerInBottomLayer(Color.Red);
                        }
                        else if (front_right_corner.Equals(cube.GetBlock(0, 2, 2)))
                        {
                            PutCornerInBottomLayer(Color.Blue);
                        }
                        continue;
                    }
                    else
                    {
                        while (!front_right_corner_in_prop_pos.Equals(front_right_corner) && (max_sequence_applications-- > 0))
                        {
                            CornersRotation(Color.Green);
                            max_sequence_applications = 5;
                        }
                    }
                }
                if (!back_right_corner_in_prop_pos.Equals(back_right_corner))
                {
                    if (back_right_corner.Equals(cube.GetBlock(2, 2, 2)))
                    {
                        CornersRotation(Color.Red);
                    }

                    corner_in_bottom_layer = true;
                    while (!back_right_corner.Equals(cube.GetBlock(2, 0, 2)) && (max_rotations-- > 0))
                    {
                        cube.Rotate(Color.Yellow, Direction.Clockwise);
                        if (max_rotations == 0)
                        {
                            corner_in_bottom_layer = false;
                        }
                    }
                    max_rotations = 4;

                    if (!corner_in_bottom_layer)
                    {
                        if (back_right_corner.Equals(cube.GetBlock(2, 2, 0)))
                        {
                            PutCornerInBottomLayer(Color.Green);
                        }
                        else if (back_right_corner.Equals(cube.GetBlock(0, 2, 0)))
                        {
                            PutCornerInBottomLayer(Color.Purple);
                        }
                        else if (back_right_corner.Equals(cube.GetBlock(0, 2, 2)))
                        {
                            PutCornerInBottomLayer(Color.Blue);
                        }
                        continue;
                    }
                    else
                    {
                        while (!back_right_corner_in_prop_pos.Equals(back_right_corner) && (max_sequence_applications-- > 0))
                        {
                            CornersRotation(Color.Red);
                            max_sequence_applications = 5;
                        }
                    }
                }
                if (!back_left_corner_in_prop_pos.Equals(back_left_corner))
                {
                    if (back_left_corner.Equals(cube.GetBlock(0, 2, 2)))
                    {
                        CornersRotation(Color.Blue);
                    }

                    corner_in_bottom_layer = true;
                    while (!back_left_corner.Equals(cube.GetBlock(0, 0, 2)) && (max_rotations-- > 0))
                    {
                        cube.Rotate(Color.Yellow, Direction.Clockwise);
                        if (max_rotations == 0)
                        {
                            corner_in_bottom_layer = false;
                        }
                    }
                    max_rotations = 4;

                    if (!corner_in_bottom_layer)
                    {
                        if (back_left_corner.Equals(cube.GetBlock(2, 2, 0)))
                        {
                            PutCornerInBottomLayer(Color.Green);
                        }
                        else if (back_left_corner.Equals(cube.GetBlock(2, 2, 2)))
                        {
                            PutCornerInBottomLayer(Color.Red);
                        }
                        else if (back_left_corner.Equals(cube.GetBlock(0, 2, 0)))
                        {
                            PutCornerInBottomLayer(Color.Purple);
                        }
                        continue;
                    }
                    else
                    {
                        while (!back_left_corner_in_prop_pos.Equals(back_left_corner) && (max_sequence_applications-- > 0))
                        {
                            CornersRotation(Color.Blue);
                            max_sequence_applications = 5;
                        }
                    }
                }
            }
        }