2020: day12: use i64 everwhere
This commit is contained in:
parent
f85bea7bb4
commit
fb981e8103
|
@ -59,7 +59,7 @@ impl Direction {
|
||||||
Direction::West,
|
Direction::West,
|
||||||
];
|
];
|
||||||
|
|
||||||
fn rotate(self, turn_dir: TurnDirection, degrees: u16) -> Direction {
|
fn rotate(self, turn_dir: TurnDirection, degrees: i64) -> Direction {
|
||||||
debug_assert!(degrees % 90 == 0, "only right angles are supported");
|
debug_assert!(degrees % 90 == 0, "only right angles are supported");
|
||||||
let quadrants = (degrees / 90) as usize;
|
let quadrants = (degrees / 90) as usize;
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ enum ActionKind {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Action {
|
struct Action {
|
||||||
kind: ActionKind,
|
kind: ActionKind,
|
||||||
arg: u16,
|
arg: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for Action {
|
impl std::str::FromStr for Action {
|
||||||
|
@ -188,7 +188,7 @@ impl Ship {
|
||||||
|
|
||||||
fn process(&mut self, action: Action) {
|
fn process(&mut self, action: Action) {
|
||||||
match action.kind {
|
match action.kind {
|
||||||
ActionKind::Move(dir) => self.coordinates.move_towards(dir, action.arg as i64),
|
ActionKind::Move(dir) => self.coordinates.move_towards(dir, action.arg),
|
||||||
|
|
||||||
ActionKind::Turn(turn_dir) => {
|
ActionKind::Turn(turn_dir) => {
|
||||||
self.direction = self.direction.rotate(turn_dir, action.arg);
|
self.direction = self.direction.rotate(turn_dir, action.arg);
|
||||||
|
@ -196,7 +196,7 @@ impl Ship {
|
||||||
|
|
||||||
ActionKind::Forward => self
|
ActionKind::Forward => self
|
||||||
.coordinates
|
.coordinates
|
||||||
.move_towards(self.direction, action.arg as i64),
|
.move_towards(self.direction, action.arg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ impl Ship {
|
||||||
ActionKind::Move(dir) => self
|
ActionKind::Move(dir) => self
|
||||||
.waypoint
|
.waypoint
|
||||||
.coordinates
|
.coordinates
|
||||||
.move_towards(dir, action.arg as i64),
|
.move_towards(dir, action.arg),
|
||||||
|
|
||||||
ActionKind::Turn(turn_dir) => {
|
ActionKind::Turn(turn_dir) => {
|
||||||
debug_assert!(action.arg % 90 == 0, "only right angles are supported");
|
debug_assert!(action.arg % 90 == 0, "only right angles are supported");
|
||||||
|
@ -220,9 +220,9 @@ impl Ship {
|
||||||
let (dx, dy) = self.waypoint.diff();
|
let (dx, dy) = self.waypoint.diff();
|
||||||
|
|
||||||
self.coordinates
|
self.coordinates
|
||||||
.move_towards(west_east, dx * action.arg as i64);
|
.move_towards(west_east, dx * action.arg);
|
||||||
self.coordinates
|
self.coordinates
|
||||||
.move_towards(north_south, dy * action.arg as i64);
|
.move_towards(north_south, dy * action.arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,8 +257,8 @@ impl Waypoint {
|
||||||
|
|
||||||
fn diff(&self) -> (i64, i64) {
|
fn diff(&self) -> (i64, i64) {
|
||||||
(
|
(
|
||||||
self.coordinates.x.abs() as i64,
|
self.coordinates.x.abs(),
|
||||||
self.coordinates.y.abs() as i64,
|
self.coordinates.y.abs(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue