예제 #1
0
        public IDictionary <Position, Position> Move(TurningDirection direction, int numberOfLayersDeep = 0)
        {
            Dictionary <Position, Position> _positions = new Dictionary <Position, Position>();

            foreach (Square square in GetSquares(numberOfLayersDeep))
            {
                foreach (Position pos in square.PositionsInSquare)
                {
                    PositionMover mover = new PositionMover(pos, square.PositionOne, square.PositionTwo, square.PositionThree, square.PositionFour);
                    int           numberOfPositionsToMoveForThreeOClock = _parentCubeSize - 1;
                    int           numberOfPositionToMove = numberOfPositionsToMoveForThreeOClock;
                    switch (direction)
                    {
                    case TurningDirection.ThreeoClock:
                        numberOfPositionToMove *= 1;
                        break;

                    case TurningDirection.SixoClock:
                        numberOfPositionToMove *= 2;
                        break;

                    case TurningDirection.NineoClock:
                        numberOfPositionToMove *= 3;
                        break;

                    default:
                        break;
                    }
                    _positions.Add(pos, mover.Move(numberOfPositionToMove));
                }
            }

            return(_positions);
        }
        private void PopulateDoubleAndTripleFaceCubies(CubeFace face, ref HashSet <Cubie> cubies)
        {
            PositionMover faceMover = new PositionMover(face.GetSquares(0).First());
            Func <RelativePosition, Position, Cubie> cubieCreator = _cubieCreators[face.FaceDirection];

            do
            {
                faceMover.Move(1);
                cubies.Add(cubieCreator(faceMover.CurrentRelativePosition, faceMover.CurrentPosition));
            }while (faceMover.CurrentRelativePosition != RelativePosition.OnPointOne);
        }
예제 #3
0
        public IEnumerable <Square> GetSquares(int numberOfLayersDeep)
        {
            int           max     = _parentCubeSize - 1;
            List <Square> squares = new List <Square>();

            for (int layer = 0; layer <= numberOfLayersDeep; layer++)
            {
                Position positionOne   = default(Position);
                Position positionTwo   = default(Position);
                Position positionThree = default(Position);
                Position positionFour  = default(Position);
                int      fixedValue    = 0;
                switch (FaceDirection)
                {
                case RubiksDirection.Front:
                    fixedValue  = _parentCubeSize - 1 - layer;
                    positionOne = new Position()
                    {
                        X = 0, Y = fixedValue, Z = 0
                    };
                    positionTwo = new Position()
                    {
                        X = 0, Y = fixedValue, Z = max
                    };
                    positionThree = new Position()
                    {
                        X = max, Y = fixedValue, Z = max
                    };
                    positionFour = new Position()
                    {
                        X = max, Y = fixedValue, Z = 0
                    };
                    break;

                case RubiksDirection.Back:
                    fixedValue  = layer;
                    positionOne = new Position()
                    {
                        X = 0, Y = fixedValue, Z = 0
                    };
                    positionTwo = new Position()
                    {
                        X = 0, Y = fixedValue, Z = max
                    };
                    positionThree = new Position()
                    {
                        X = max, Y = fixedValue, Z = max
                    };
                    positionFour = new Position()
                    {
                        X = max, Y = fixedValue, Z = 0
                    };
                    break;

                case RubiksDirection.Up:
                    fixedValue  = _parentCubeSize - 1 - layer;
                    positionOne = new Position()
                    {
                        X = 0, Y = max, Z = fixedValue
                    };
                    positionTwo = new Position()
                    {
                        X = 0, Y = 0, Z = fixedValue
                    };
                    positionThree = new Position()
                    {
                        X = max, Y = 0, Z = fixedValue
                    };
                    positionFour = new Position()
                    {
                        X = max, Y = max, Z = fixedValue
                    };
                    break;

                case RubiksDirection.Down:
                    fixedValue  = layer;
                    positionOne = new Position()
                    {
                        X = 0, Y = max, Z = fixedValue
                    };
                    positionTwo = new Position()
                    {
                        X = 0, Y = 0, Z = fixedValue
                    };
                    positionThree = new Position()
                    {
                        X = max, Y = 0, Z = fixedValue
                    };
                    positionFour = new Position()
                    {
                        X = max, Y = max, Z = fixedValue
                    };
                    break;

                case RubiksDirection.Left:
                    fixedValue  = layer;
                    positionOne = new Position()
                    {
                        X = fixedValue, Y = max, Z = 0
                    };
                    positionTwo = new Position()
                    {
                        X = fixedValue, Y = max, Z = max
                    };
                    positionThree = new Position()
                    {
                        X = fixedValue, Y = 0, Z = max
                    };
                    positionFour = new Position()
                    {
                        X = fixedValue, Y = 0, Z = 0
                    };
                    break;

                case RubiksDirection.Right:
                    fixedValue  = _parentCubeSize - 1 - layer;
                    positionOne = new Position()
                    {
                        X = fixedValue, Y = max, Z = 0
                    };
                    positionTwo = new Position()
                    {
                        X = fixedValue, Y = max, Z = max
                    };
                    positionThree = new Position()
                    {
                        X = fixedValue, Y = 0, Z = max
                    };
                    positionFour = new Position()
                    {
                        X = fixedValue, Y = 0, Z = 0
                    };
                    break;

                default:
                    break;
                }

                HashSet <Position> squarePoints = new HashSet <Position>();
                PositionMover      mover        = new PositionMover(positionOne, positionOne, positionTwo, positionThree, positionFour);
                squarePoints.Add(positionOne);
                Position next = new Position()
                {
                    X = -1, Y = -1, Z = -1
                };
                while (!next.Equals(positionOne))
                {
                    next = mover.Move(1);
                    if (!next.Equals(positionOne))
                    {
                        squarePoints.Add(next);
                    }
                }
                squares.Add
                (
                    new Square()
                {
                    PositionOne       = positionOne,
                    PositionTwo       = positionTwo,
                    PositionThree     = positionThree,
                    PositionFour      = positionFour,
                    PositionsInSquare = squarePoints
                }
                );
            }
            return(squares);
        }