cleanup
This commit is contained in:
parent
635f0cf641
commit
e5eb4d7cfc
1 changed files with 14 additions and 27 deletions
|
@ -22,7 +22,6 @@ pub struct Machine {
|
||||||
steps: usize,
|
steps: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
pub fn new_empty(input: Vec<u8>, width: usize) -> Self {
|
pub fn new_empty(input: Vec<u8>, width: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -242,17 +241,20 @@ impl Machine {
|
||||||
let Some(front_tile) = self.board.get_mut(front_pos) else {
|
let Some(front_tile) = self.board.get_mut(front_pos) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut move_to = |tile, target_pos, dir, board: &mut Board| {
|
||||||
|
let value = match tile {
|
||||||
|
OpenTile::Blank => value,
|
||||||
|
OpenTile::Digit(n) => value.wrapping_mul(10).wrapping_add(n as MarbleValue),
|
||||||
|
};
|
||||||
|
board.set(*pos, Tile::default());
|
||||||
|
board.set(target_pos, Tile::Marble { value, dir });
|
||||||
|
*pos = target_pos;
|
||||||
|
};
|
||||||
|
|
||||||
if let Tile::Open(space_type, claim_state) = front_tile {
|
if let Tile::Open(space_type, claim_state) = front_tile {
|
||||||
if *claim_state == MarbleTarget::Claimed {
|
if *claim_state == MarbleTarget::Claimed {
|
||||||
let value = match space_type {
|
move_to(*space_type, front_pos, dir, &mut self.board);
|
||||||
OpenTile::Blank => value,
|
|
||||||
OpenTile::Digit(n) => {
|
|
||||||
value.wrapping_mul(10).wrapping_add(*n as MarbleValue)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
self.board.set(*pos, Tile::default());
|
|
||||||
self.board.set(front_pos, Tile::Marble { value, dir });
|
|
||||||
*pos = front_pos;
|
|
||||||
} else if *claim_state != MarbleTarget::Free {
|
} else if *claim_state != MarbleTarget::Free {
|
||||||
// (Free means a marble was just here but moved earlier this tick)
|
// (Free means a marble was just here but moved earlier this tick)
|
||||||
// bounce on failed direct movement
|
// bounce on failed direct movement
|
||||||
|
@ -283,12 +285,10 @@ impl Machine {
|
||||||
}
|
}
|
||||||
Tile::Powerable(PTile::Bag, _) => {
|
Tile::Powerable(PTile::Bag, _) => {
|
||||||
removed_marbles.push(i);
|
removed_marbles.push(i);
|
||||||
self.board.set(*pos, Tile::default());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Tile::Powerable(PTile::IO, _) => {
|
Tile::Powerable(PTile::IO, _) => {
|
||||||
removed_marbles.push(i);
|
removed_marbles.push(i);
|
||||||
self.board.set(*pos, Tile::default());
|
|
||||||
self.output.push(value as u8);
|
self.output.push(value as u8);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -298,21 +298,7 @@ impl Machine {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let Tile::Open(space_type, MarbleTarget::ClaimedIndirect) = target_tile {
|
if let Tile::Open(space_type, MarbleTarget::ClaimedIndirect) = target_tile {
|
||||||
let value = match space_type {
|
move_to(*space_type, target_pos, new_dir, &mut self.board);
|
||||||
OpenTile::Blank => value,
|
|
||||||
OpenTile::Digit(n) => {
|
|
||||||
value.wrapping_mul(10).wrapping_add(*n as MarbleValue)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
self.board.set(*pos, Tile::default());
|
|
||||||
self.board.set(
|
|
||||||
target_pos,
|
|
||||||
Tile::Marble {
|
|
||||||
value,
|
|
||||||
dir: new_dir,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
*pos = target_pos;
|
|
||||||
if is_trigger {
|
if is_trigger {
|
||||||
triggers_activated.push(front_pos);
|
triggers_activated.push(front_pos);
|
||||||
}
|
}
|
||||||
|
@ -328,6 +314,7 @@ impl Machine {
|
||||||
|
|
||||||
// remove marbles
|
// remove marbles
|
||||||
for &i in removed_marbles.iter().rev() {
|
for &i in removed_marbles.iter().rev() {
|
||||||
|
self.board.set(self.marbles[i], Tile::default());
|
||||||
self.marbles.swap_remove(i);
|
self.marbles.swap_remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue