public void NorthTurningRight90DegreesIsEast() { int shipDirection = Direction.NORTH; shipDirection = FerryMover.RotateShip(shipDirection, Rotate.RIGHT, 90); Assert.Equal(Direction.EAST, shipDirection); }
public void EastTurningLeft180DegreesIsWest() { int shipDirection = Direction.EAST; shipDirection = FerryMover.RotateShip(shipDirection, Rotate.LEFT, 180); Assert.Equal(Direction.WEST, shipDirection); }
public void EastTurningLeft90DegreesIsNorth() { int shipDirection = Direction.EAST; shipDirection = FerryMover.RotateShip(shipDirection, Rotate.LEFT, 90); Assert.Equal(Direction.NORTH, shipDirection); }
public void EastTurningRight360DegreesIsEast() { int shipDirection = Direction.EAST; shipDirection = FerryMover.RotateShip(shipDirection, Rotate.RIGHT, 360); Assert.Equal(Direction.EAST, shipDirection); }
public void NorthTurningRight360DegreesIsNorth() { int shipDirection = Direction.NORTH; shipDirection = FerryMover.RotateShip(shipDirection, Rotate.RIGHT, 360); Assert.Equal(Direction.NORTH, shipDirection); }
static void Main(string[] args) { var instructions = FileHelper.GetFileContents <string>("./data/data.txt"); int currentDirection = Direction.EAST; ManhattanLocation position = new(); foreach (string instruction in instructions) { char directive = instruction[0]; int amount = int.Parse(instruction.Substring(1)); // brute force it with a switch for now switch (directive) { case Directive.MOVE_NORTH: case Directive.MOVE_SOUTH: case Directive.MOVE_EAST: case Directive.MOVE_WEST: position = FerryMover.MoveDirectionally(position, directive, amount); break; case Directive.MOVE_FORWARD: position = FerryMover.MoveForward(position, currentDirection, amount); break; case Directive.ROTATE_RIGHT: case Directive.ROTATE_LEFT: currentDirection = FerryMover.RotateShip(currentDirection, directive, amount); break; default: throw new Exception("Undefined directive"); } } Console.WriteLine(Math.Abs(position.HorizontalPosition) + Math.Abs(position.VerticalPosition)); }