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); }
private Cubie CreateDownCubie(RelativePosition relativePosition, Position cubiePosition) { Cubie upCubie = CreateUpCubie(relativePosition, cubiePosition); return(new Cubie ( frontSide: upCubie.FrontSide, backSide: upCubie.BackSide, rightSide: upCubie.RightSide, leftSide: upCubie.LeftSide, upSide: null, downSide: _downColor, postion: cubiePosition )); }
private Cubie CreateLeftCubie(RelativePosition relativePosition, Position cubiePosition) { Cubie rightCubie = CreateRightCubie(relativePosition, cubiePosition); return(new Cubie ( frontSide: rightCubie.FrontSide, backSide: rightCubie.BackSide, rightSide: null, leftSide: _leftColor, upSide: rightCubie.UpSide, downSide: rightCubie.DownSide, postion: cubiePosition )); }
private Cubie CreateBackCubie(RelativePosition relativePosition, Position cubiePosition) { Cubie frontCubie = CreateFrontCubie(relativePosition, cubiePosition); return(new Cubie ( frontSide: null, backSide: _backColor, rightSide: frontCubie.RightSide, leftSide: frontCubie.LeftSide, upSide: frontCubie.UpSide, downSide: frontCubie.DownSide, postion: cubiePosition )); }
public Cubie this[int x, int y, int z] { get { Position requestedPosition = new Position() { X = x, Y = y, Z = z }; Cubie cubie = _cubies.FirstOrDefault(cub => cub.Position.Equals(requestedPosition)); if (cubie == null) { throw new InvalidOperationException(string.Format("Could not find requested cube at {0}", requestedPosition)); } else { return(cubie); } } }
private void PopulateSingleFaceCubies(CubeFace face, ref HashSet <Cubie> cubies) { Square square = face.GetSquares(0).First(); HashSet <Position> allFacePositions = new HashSet <Position>(face.CubiePositions); allFacePositions.ExceptWith(square.PositionsInSquare); foreach (Position position in allFacePositions) { Cubie singleFacedCubie = null; switch (face.FaceDirection) { case RubiksDirection.Front: singleFacedCubie = new Cubie ( frontSide: _frontColor, backSide: null, rightSide: null, leftSide: null, upSide: null, downSide: null, postion: position ); break; case RubiksDirection.Back: singleFacedCubie = new Cubie ( frontSide: null, backSide: _backColor, rightSide: null, leftSide: null, upSide: null, downSide: null, postion: position ); break; case RubiksDirection.Up: singleFacedCubie = new Cubie ( frontSide: null, backSide: null, rightSide: null, leftSide: null, upSide: _upColor, downSide: null, postion: position ); break; case RubiksDirection.Down: singleFacedCubie = new Cubie ( frontSide: null, backSide: null, rightSide: null, leftSide: null, upSide: null, downSide: _downColor, postion: position ); break; case RubiksDirection.Left: singleFacedCubie = new Cubie ( frontSide: null, backSide: null, rightSide: null, leftSide: _leftColor, upSide: null, downSide: null, postion: position ); break; case RubiksDirection.Right: singleFacedCubie = new Cubie ( frontSide: null, backSide: null, rightSide: _rightColor, leftSide: null, upSide: null, downSide: null, postion: position ); break; default: break; } cubies.Add(singleFacedCubie); } }