Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var moves = LoadMovements("input.txt");
            var ship1 = new Pointish()
            {
                Facing = Direction.RIGHT
            };

            foreach (var move in moves)
            {
                MovePart1Style(ship1, move);
            }
            ship1.Pos.ManhattenDistance().AsResult1();

            var ship2    = new Pointish();
            var waypoint = new Pointish()
            {
                Pos = new Point(0, 0).Right(10).Up(1)
            };

            foreach (var move in moves)
            {
                MovePart2Style(ship2, move, waypoint);
            }
            ship2.Pos.ManhattenDistance().AsResult2();
            Report.End();
        }
Ejemplo n.º 2
0
        private static void MovePart2Style(Pointish ship, Movement move, Pointish waypoint)
        {
            switch (move.Act)
            {
            case "F":
                ship.Move(waypoint.Pos, move.Amount);
                break;

            case "E":
            case "N":
            case "W":
            case "S":
                var direction = PointParseUtils.ParseDirection(move.Act);
                waypoint.Move(direction, move.Amount);
                break;

            case "L":
            case "R":
                var rotation = PointParseUtils.ParseRotation(move.Act, move.Amount);
                waypoint.RotateOrientation(rotation);
                break;

            default:
                throw new Exception("Unknown act: " + move.Act);
            }
        }
Ejemplo n.º 3
0
        private static void MovePart1Style(Pointish ship, Movement move)
        {
            switch (move.Act)
            {
            case "F":
                ship.Move(ship.Facing, move.Amount);
                break;

            case "E":
            case "N":
            case "W":
            case "S":
                var direction = PointParseUtils.ParseDirection(move.Act);
                ship.Move(direction, move.Amount);
                break;

            case "L":
            case "R":
                var rotation = PointParseUtils.ParseRotation(move.Act, move.Amount);
                ship.RotateFacing(rotation);
                break;

            default:
                throw new Exception("Act not impl: " + move.Act);
            }
        }