This commit is contained in:
parent
411d6aa26d
commit
c261ee56fe
11
src/day15.rs
11
src/day15.rs
@ -18,12 +18,7 @@ impl Warehouse {
|
|||||||
fn step_robot(&mut self, dir: Move) {
|
fn step_robot(&mut self, dir: Move) {
|
||||||
let start = self.robot_pos.clone();
|
let start = self.robot_pos.clone();
|
||||||
if self.push(&start, &dir) {
|
if self.push(&start, &dir) {
|
||||||
self.robot_pos = match dir {
|
self.robot_pos = &self.robot_pos + dir.ofs();
|
||||||
Move::Left => (self.robot_pos.x() - 1, self.robot_pos.y()).to_coord(),
|
|
||||||
Move::Right => (self.robot_pos.x() + 1, self.robot_pos.y()).to_coord(),
|
|
||||||
Move::Up => (self.robot_pos.x(), self.robot_pos.y() - 1).to_coord(),
|
|
||||||
Move::Down => (self.robot_pos.x(), self.robot_pos.y() + 1).to_coord(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +56,7 @@ impl Warehouse {
|
|||||||
|
|
||||||
fn can_push(&mut self, pos: &Coord2d, dir: &Move) -> bool {
|
fn can_push(&mut self, pos: &Coord2d, dir: &Move) -> bool {
|
||||||
let target = pos + dir.ofs();
|
let target = pos + dir.ofs();
|
||||||
return match self.map.get(&target).unwrap() {
|
match self.map.get(&target).unwrap() {
|
||||||
b'#' => false,
|
b'#' => false,
|
||||||
b'.' => true,
|
b'.' => true,
|
||||||
b'O' => self.can_push(&target, dir),
|
b'O' => self.can_push(&target, dir),
|
||||||
@ -69,7 +64,7 @@ impl Warehouse {
|
|||||||
b']' => self.can_push(&target, dir) && self.can_push(&(&target + (-1, 0)), dir),
|
b']' => self.can_push(&target, dir) && self.can_push(&(&target + (-1, 0)), dir),
|
||||||
b'[' => self.can_push(&target, dir) && self.can_push(&(&target + (1, 0)), dir),
|
b'[' => self.can_push(&target, dir) && self.can_push(&(&target + (1, 0)), dir),
|
||||||
c => panic!("unexpected char {}", c),
|
c => panic!("unexpected char {}", c),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn embiggen(&mut self) {
|
fn embiggen(&mut self) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user