group wires into one tool option
This commit is contained in:
parent
ea02eff82b
commit
465b5c40d1
4 changed files with 89 additions and 78 deletions
|
@ -315,57 +315,3 @@ impl Machine {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(source: &str) -> Board {
|
||||
let mut rows = Vec::new();
|
||||
|
||||
let mut width = 0;
|
||||
for line in source.lines() {
|
||||
width = width.max(line.len());
|
||||
let mut tiles = Vec::new();
|
||||
for char in line.chars() {
|
||||
tiles.push(tile_from_char(char));
|
||||
}
|
||||
rows.push(tiles);
|
||||
}
|
||||
for line in &mut rows {
|
||||
line.resize(width, Tile::Blank);
|
||||
}
|
||||
|
||||
Board::new(rows)
|
||||
}
|
||||
|
||||
pub const fn tile_from_char(c: char) -> Tile {
|
||||
match c {
|
||||
'o' => Tile::Marble {
|
||||
value: 0,
|
||||
dir: Direction::Down,
|
||||
},
|
||||
'*' => Tile::Powerable(PTile::Trigger, false),
|
||||
'-' => Tile::Powerable(PTile::Wire(WireType::Horizontal), false),
|
||||
'|' => Tile::Powerable(PTile::Wire(WireType::Vertical), false),
|
||||
'+' => Tile::Powerable(PTile::Wire(WireType::Cross), false),
|
||||
'/' => Tile::Mirror(MirrorType::Forward),
|
||||
'\\' => Tile::Mirror(MirrorType::Back),
|
||||
'^' => Tile::Arrow(Direction::Up),
|
||||
'v' => Tile::Arrow(Direction::Down),
|
||||
'<' => Tile::Arrow(Direction::Left),
|
||||
'>' => Tile::Arrow(Direction::Right),
|
||||
'=' => Tile::Powerable(PTile::Gate(GateType::Equal), false),
|
||||
'!' => Tile::Powerable(PTile::Gate(GateType::NotEqual), false),
|
||||
'L' => Tile::Powerable(PTile::Gate(GateType::LessThan), false),
|
||||
'G' => Tile::Powerable(PTile::Gate(GateType::GreaterThan), false),
|
||||
'P' => Tile::Powerable(PTile::Output, false),
|
||||
'I' => Tile::Powerable(PTile::Input, false),
|
||||
'F' => Tile::Powerable(PTile::Flipper, false),
|
||||
'A' => Tile::Powerable(PTile::Math(MathOp::Add), false),
|
||||
'S' => Tile::Powerable(PTile::Math(MathOp::Sub), false),
|
||||
'M' => Tile::Powerable(PTile::Math(MathOp::Mul), false),
|
||||
'D' => Tile::Powerable(PTile::Math(MathOp::Div), false),
|
||||
'R' => Tile::Powerable(PTile::Math(MathOp::Rem), false),
|
||||
'B' => Tile::Powerable(PTile::Bag, false),
|
||||
d @ '0'..='9' => Tile::Digit(d as u8 - b'0'),
|
||||
'#' => Tile::Block,
|
||||
' ' => Tile::Blank,
|
||||
_ => Tile::Blank,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue