예제 #1
0
        private void FirstLayer()
        {
            for (int c = 0; c < SideColors.Length; c++)
            {
                // Sets the view with the current color in the front face and the white on the top.
                ChangeView(new CubeView(SideColors[c], STARTING_COLOR));

                // Gets the corner that needs to be moved.
                Cubie corner = _cube.FindCorner(STARTING_COLOR, SideColors[c], SideColors[(c + 1) % 4]);

                if (!_cube.IsCubiePlacedCorrectly(corner))
                {
                    // If the corner is in the top layer, the program will rotate it until the corner is on
                    // the top-right of the front face, then use the separate algorithm and rotate the layer back.
                    if (corner.Y == 0)
                    {
                        int rotations;
                        for (rotations = 0; corner.Z != 0 || corner.X != 2; rotations++)
                        {
                            AddMove(Move.Up);
                        }

                        if (corner.FrontColor == STARTING_COLOR || corner.UpColor == STARTING_COLOR)
                        {
                            AddMoveList(Algorithms.SeparateCorner1);
                        }
                        else if (corner.RightColor == STARTING_COLOR)
                        {
                            AddMoveList(Algorithms.SeparateCorner2);
                        }

                        for (int i = 0; i < rotations; i++)
                        {
                            AddMove(Move.UpPrime);
                        }
                    }

                    // Rotates the lower layer until the corner is in the bottom-right of the front face.
                    while (corner.X != 2 || corner.Z != 0)
                    {
                        AddMove(Move.Down);
                    }

                    // Uses the correct algorithm to place the corner in its position.
                    if (corner.FrontColor == STARTING_COLOR)
                    {
                        AddMoveList(Algorithms.WhiteFront);
                    }
                    else if (corner.DownColor == STARTING_COLOR)
                    {
                        AddMoveList(Algorithms.WhiteDown);
                    }
                    else
                    {
                        AddMoveList(Algorithms.WhiteRight);
                    }
                }
            }
        }