예제 #1
0
 internal CubeFace(RubiksDirection direction, int parentCubeSize = 3)
 {
     _parentCubeSize = parentCubeSize;
     FaceDirection   = direction;
     InitializeStartingPoints(parentCubeSize);
     InitializeCubiePositions(parentCubeSize);
 }
예제 #2
0
        public RubiksColor?GetColor(RubiksDirection face)
        {
            switch (face)
            {
            case RubiksDirection.Front:
                return(FrontSide);

            case RubiksDirection.Back:
                return(BackSide);

            case RubiksDirection.Up:
                return(UpSide);

            case RubiksDirection.Down:
                return(DownSide);

            case RubiksDirection.Left:
                return(LeftSide);

            case RubiksDirection.Right:
                return(RightSide);

            default:
                return(null);
            }
        }
예제 #3
0
        private void OnCubeTurned(RubiksDirection side, TurningDirection direction, int numberOfLayersDeep)
        {
            EventHandler <GenericEventArgs <CubeTurnedEvent> > handler = CubeTurned;

            if (handler != null)
            {
                handler(this, new GenericEventArgs <CubeTurnedEvent>(new CubeTurnedEvent(side, direction, numberOfLayersDeep)));
            }
        }
예제 #4
0
        public void Shuffle(int numberOfTurns = 100)
        {
            Random rnd = new Random();

            for (int i = 0; i < numberOfTurns; i++)
            {
                int             faceInt = rnd.Next(6);
                RubiksDirection face    = default(RubiksDirection);
                if (faceInt == 0)
                {
                    face = RubiksDirection.Back;
                }
                else if (faceInt == 1)
                {
                    face = RubiksDirection.Down;
                }
                else if (faceInt == 2)
                {
                    face = RubiksDirection.Front;
                }
                else if (faceInt == 3)
                {
                    face = RubiksDirection.Left;
                }
                else if (faceInt == 4)
                {
                    face = RubiksDirection.Right;
                }
                else if (faceInt == 5)
                {
                    face = RubiksDirection.Up;
                }

                int turningDirectionInt           = rnd.Next(3);
                TurningDirection turningDirection = default(TurningDirection);
                if (turningDirectionInt == 0)
                {
                    turningDirection = TurningDirection.ThreeoClock;
                }
                else if (turningDirectionInt == 1)
                {
                    turningDirection = TurningDirection.SixoClock;
                }
                else if (turningDirectionInt == 2)
                {
                    turningDirection = TurningDirection.NineoClock;
                }

                int numberOfLayersDeep = rnd.Next(CubeSize - 1);

                Turn(face, turningDirection, numberOfLayersDeep);
            }
        }
예제 #5
0
        public void Turn(RubiksDirection side, TurningDirection direction = TurningDirection.ThreeoClock, int numberOfLayersDeep = 0)
        {
            TurningDirection modifiedDirection = direction;

            if (side == RubiksDirection.Back || side == RubiksDirection.Left || side == RubiksDirection.Down)
            {
                modifiedDirection = direction.InvertTurningDirection();
            }

            IDictionary <Position, Position> oldNewPositions = _faces[side].Move(modifiedDirection, numberOfLayersDeep);
            IEnumerable <KeyValuePair <Cubie, Position> > cubieToNewPositionPairs = oldNewPositions.Select
                                                                                        (pair => new KeyValuePair <Cubie, Position>(this[pair.Key], pair.Value)).ToList();

            foreach (KeyValuePair <Cubie, Position> cubieToNewPositionPair in cubieToNewPositionPairs)
            {
                Cubie cubieToMove = cubieToNewPositionPair.Key;
                switch (side)
                {
                case RubiksDirection.Front:
                    cubieToMove.Move(cubieToNewPositionPair.Value, Axes.Y, modifiedDirection);
                    break;

                case RubiksDirection.Back:
                    cubieToMove.Move(cubieToNewPositionPair.Value, Axes.Y, modifiedDirection);
                    break;

                case RubiksDirection.Up:
                    cubieToMove.Move(cubieToNewPositionPair.Value, Axes.Z, modifiedDirection);
                    break;

                case RubiksDirection.Down:
                    cubieToMove.Move(cubieToNewPositionPair.Value, Axes.Z, modifiedDirection);
                    break;

                case RubiksDirection.Left:
                    cubieToMove.Move(cubieToNewPositionPair.Value, Axes.X, modifiedDirection);
                    break;

                case RubiksDirection.Right:
                    cubieToMove.Move(cubieToNewPositionPair.Value, Axes.X, modifiedDirection);
                    break;

                default:
                    break;
                }
            }

            OnCubeTurned(side, direction, numberOfLayersDeep);
        }
예제 #6
0
        public static Color GetColor(this RubiksCube cube, TwoDPosition pos)
        {
            if (cube.CubeSize != 3)
            {
                throw new NotSupportedException("Currently we only draw 3x3x3 cubes two dimensionally :(");
            }

            Position        threeDPosition = default(Position);
            RubiksDirection direction      = default(RubiksDirection);

            if (_positionFaceMappings.ContainsKey(pos) && _positionMappings.ContainsKey(pos))
            {
                threeDPosition = _positionMappings[pos];
                direction      = _positionFaceMappings[pos];
            }


            RubiksColor?positionColor = cube[threeDPosition].GetColor(direction);

            if (positionColor == null)
            {
                //oops
                return(Colors.Gray);
            }

            switch (positionColor.Value)
            {
            case RubiksColor.Blue:
                return(Colors.Blue);

            case RubiksColor.Green:
                return(Colors.Green);

            case RubiksColor.Orange:
                return(Colors.Orange);

            case RubiksColor.Red:
                return(Colors.Red);

            case RubiksColor.White:
                return(Colors.White);

            case RubiksColor.Yellow:
                return(Colors.Yellow);

            default:
                return(Colors.Gray);
            }
        }
예제 #7
0
 public CubeTurnedEvent(RubiksDirection faceTurned, TurningDirection directionOfTurn, int numberOfLayersDeep)
 {
     FaceTurned         = faceTurned;
     DirectionOfTurn    = directionOfTurn;
     NumberOfLayersDeep = numberOfLayersDeep;
 }