コード例 #1
0
ファイル: UI.cs プロジェクト: KeiPG/rubixs
        private void ReadKeyboard()
        {
            KeyboardState keys = keyboard.GetCurrentKeyboardState();

            face = (keys[Key.R] || keys[Key.Y] || keys[Key.W] || keys[Key.B] || keys[Key.G] || keys[Key.O] || keys[Key.S]);

            if (face)
            {
                if (keys[Key.S] & keys[Key.LeftControl])
                {
                    if (keys[Key.RightArrow])
                    {
                        theta += .1f;
                    }
                    if (keys[Key.LeftArrow])
                    {
                        theta -= .1f;
                    }
                }
                if (!arrow)
                {
                    if (keys[Key.S])
                    {
                        if (keys[Key.D1])
                        {
                            solver.SolveWhiteCross();
                            //solver.SolveWhiteCorners();
                            //solver.SolveMiddleLayer();
                        }
                        if (keys[Key.UpArrow])
                        {
                            if (keys[Key.LeftControl])
                            {
                                spacing += .1f;
                            }
                            else
                            {
                                rho += 1;
                            }
                        }
                        if (keys[Key.DownArrow])
                        {
                            if (keys[Key.LeftControl])
                            {
                                spacing -= .1f;
                            }
                            else
                            {
                                rho -= 1;
                            }
                        }
                    }

                    if (keys[Key.LeftArrow])
                    {
                        if (keys[Key.R])
                        {
                            rubixCube.Rotate(Color.Red, Direction.CounterClockwise);
                        }
                        if (keys[Key.W])
                        {
                            rubixCube.Rotate(Color.White, Direction.CounterClockwise);
                        }
                        if (keys[Key.B])
                        {
                            rubixCube.Rotate(Color.Blue, Direction.CounterClockwise);
                        }
                        if (keys[Key.G])
                        {
                            rubixCube.Rotate(Color.Green, Direction.CounterClockwise);
                        }
                        if (keys[Key.Y])
                        {
                            rubixCube.Rotate(Color.Yellow, Direction.CounterClockwise);
                        }
                        if (keys[Key.O])
                        {
                            rubixCube.Rotate(Color.Orange, Direction.CounterClockwise);
                        }
                    }
                    else if (keys[Key.RightArrow])
                    {
                        if (keys[Key.R])
                        {
                            rubixCube.Rotate(Color.Red, Direction.Clockwise);
                        }
                        if (keys[Key.W])
                        {
                            rubixCube.Rotate(Color.White, Direction.Clockwise);
                        }
                        if (keys[Key.B])
                        {
                            rubixCube.Rotate(Color.Blue, Direction.Clockwise);
                        }
                        if (keys[Key.G])
                        {
                            rubixCube.Rotate(Color.Green, Direction.Clockwise);
                        }
                        if (keys[Key.Y])
                        {
                            rubixCube.Rotate(Color.Yellow, Direction.Clockwise);
                        }
                        if (keys[Key.O])
                        {
                            rubixCube.Rotate(Color.Orange, Direction.Clockwise);
                        }
                    }
                }
            }

            arrow = (keys[Key.LeftArrow] || keys[Key.RightArrow]);
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// this function waits for the user to press a button then checks
        /// if there is an event to that key.
        /// if one of the event keys are pressed then does that function.
        /// there is face rotation, cube rotation and zooming function
        /// </summary>
        private void ReadKeyboard()
        {
            KeyboardState keys = keyboard.GetCurrentKeyboardState();

            face = (keys[Key.R] || keys[Key.Y] || keys[Key.W] || keys[Key.B] || keys[Key.G] || keys[Key.O] || keys[Key.S]);

            if (face)
            {
                if (keys[Key.S] & keys[Key.LeftControl])
                {
                    if (keys[Key.RightArrow])
                    {
                        theta += .1f;
                    }
                    if (keys[Key.LeftArrow])
                    {
                        theta -= .1f;
                    }
                }
                if (!arrow)
                {
                    if (keys[Key.S])
                    {
                        if (keys[Key.Q])
                        {
                            solver.SolveWhiteCross();
                            solver.SolveWhiteCorners();
                            solver.SolveMiddleLayer(Color.Blue);
                            solver.SolveMiddleLayer(Color.Green);
                            solver.SolveMiddleLayer(Color.Red);
                            solver.SolveMiddleLayer(Color.Purple);
                            solver.SolveBottomCross(singleton);
                            solver.SolveBottomEdges(singleton);
                            solver.SolveBottomCorners(singleton);
                        }
                        if (keys[Key.UpArrow])
                        {
                            if (keys[Key.LeftControl])
                            {
                                spacing += .1f;
                            }
                            else
                            {
                                rho += 1;
                            }
                        }
                        if (keys[Key.DownArrow])
                        {
                            if (keys[Key.LeftControl])
                            {
                                spacing -= .1f;
                            }
                            else
                            {
                                rho -= 1;
                            }
                        }
                    }

                    if (keys[Key.LeftArrow])
                    {
                        if (keys[Key.R])
                        {
                            rubixCube.Rotate(Color.Red, Direction.CounterClockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.W])
                        {
                            rubixCube.Rotate(Color.White, Direction.CounterClockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.B])
                        {
                            rubixCube.Rotate(Color.Blue, Direction.CounterClockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.G])
                        {
                            rubixCube.Rotate(Color.Green, Direction.CounterClockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.Y])
                        {
                            rubixCube.Rotate(Color.Yellow, Direction.CounterClockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.O])
                        {
                            rubixCube.Rotate(Color.Purple, Direction.CounterClockwise);
                            rotateFace = Color.Hidden;
                        }
                    }
                    else if (keys[Key.RightArrow])
                    {
                        if (keys[Key.R])
                        {
                            rubixCube.Rotate(Color.Red, Direction.Clockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.W])
                        {
                            rubixCube.Rotate(Color.White, Direction.Clockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.B])
                        {
                            rubixCube.Rotate(Color.Blue, Direction.Clockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.G])
                        {
                            rubixCube.Rotate(Color.Green, Direction.Clockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.Y])
                        {
                            rubixCube.Rotate(Color.Yellow, Direction.Clockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.O])
                        {
                            rubixCube.Rotate(Color.Purple, Direction.Clockwise);
                            rotateFace = Color.Hidden;
                        }
                        else if (keys[Key.M])
                        {
                            Random r = new Random();
                            for (int i = 0; i < 50; i++)
                            {
                                Int32 color = r.Next(1, 7);
                                if (color == 1)
                                {
                                    rubixCube.Rotate(Color.Red, Direction.Clockwise);
                                }
                                else if (color == 2)
                                {
                                    rubixCube.Rotate(Color.Purple, Direction.Clockwise);
                                }
                                else if (color == 3)
                                {
                                    rubixCube.Rotate(Color.Blue, Direction.Clockwise);
                                }
                                else if (color == 4)
                                {
                                    rubixCube.Rotate(Color.Green, Direction.Clockwise);
                                }
                                else if (color == 5)
                                {
                                    rubixCube.Rotate(Color.Yellow, Direction.Clockwise);
                                }
                                else if (color == 6)
                                {
                                    rubixCube.Rotate(Color.White, Direction.Clockwise);
                                }
                                else
                                {
                                    rubixCube.Rotate(Color.Purple, Direction.Clockwise);
                                }
                            }
                        }
                    }
                }
            }

            arrow = (keys[Key.LeftArrow] || keys[Key.RightArrow]);
        }