fix update order dependent behavior of wires when flipped
This commit is contained in:
parent
42a355d387
commit
78027aaaa0
1 changed files with 23 additions and 15 deletions
|
@ -17,6 +17,7 @@ pub struct Machine {
|
||||||
marbles: Vec<Pos>,
|
marbles: Vec<Pos>,
|
||||||
powered: Vec<Pos>,
|
powered: Vec<Pos>,
|
||||||
events: Vec<Event>,
|
events: Vec<Event>,
|
||||||
|
flipper_events: Vec<Pos>,
|
||||||
|
|
||||||
input: Vec<u8>,
|
input: Vec<u8>,
|
||||||
input_index: usize,
|
input_index: usize,
|
||||||
|
@ -45,6 +46,7 @@ impl Machine {
|
||||||
marbles: Vec::new(),
|
marbles: Vec::new(),
|
||||||
powered: Vec::new(),
|
powered: Vec::new(),
|
||||||
events: Vec::new(),
|
events: Vec::new(),
|
||||||
|
flipper_events: Vec::new(),
|
||||||
input,
|
input,
|
||||||
input_index: 0,
|
input_index: 0,
|
||||||
output: Vec::new(),
|
output: Vec::new(),
|
||||||
|
@ -290,11 +292,31 @@ impl Machine {
|
||||||
}
|
}
|
||||||
|
|
||||||
// process triggers
|
// process triggers
|
||||||
|
self.flipper_events.clear();
|
||||||
for pos in triggers_activated {
|
for pos in triggers_activated {
|
||||||
for dir in Direction::ALL {
|
for dir in Direction::ALL {
|
||||||
self.propagate_power(dir, dir.step(pos));
|
self.propagate_power(dir, dir.step(pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process flipped tiles
|
||||||
|
for &p in &self.flipper_events {
|
||||||
|
let Some(target) = self.board.get_mut(p) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
match target {
|
||||||
|
Tile::Powerable(PTile::Wire(wire_type), _) => {
|
||||||
|
*wire_type = match *wire_type {
|
||||||
|
WireType::Vertical => WireType::Horizontal,
|
||||||
|
WireType::Horizontal => WireType::Vertical,
|
||||||
|
WireType::Cross => WireType::Cross,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Tile::Mirror(mirror) => mirror.flip(),
|
||||||
|
Tile::Arrow(dir) => *dir = dir.opposite(),
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn propagate_power(&mut self, dir: Direction, pos: Pos) {
|
fn propagate_power(&mut self, dir: Direction, pos: Pos) {
|
||||||
|
@ -359,21 +381,7 @@ impl Machine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PTile::Flipper => {
|
PTile::Flipper => {
|
||||||
let Some(target) = self.board.get_mut(front_pos) else {
|
self.flipper_events.push(front_pos);
|
||||||
return;
|
|
||||||
};
|
|
||||||
match target {
|
|
||||||
Tile::Powerable(PTile::Wire(wire_type), _) => {
|
|
||||||
*wire_type = match *wire_type {
|
|
||||||
WireType::Vertical => WireType::Horizontal,
|
|
||||||
WireType::Horizontal => WireType::Vertical,
|
|
||||||
WireType::Cross => WireType::Cross,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Tile::Mirror(mirror) => mirror.flip(),
|
|
||||||
Tile::Arrow(dir) => *dir = dir.opposite(),
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
PTile::Gate(gate) => {
|
PTile::Gate(gate) => {
|
||||||
let gate = *gate;
|
let gate = *gate;
|
||||||
|
|
Loading…
Reference in a new issue