remove counter from bag tile, they can output unlimited marbles now
This commit is contained in:
parent
1f9d07c862
commit
b9009021ec
3 changed files with 20 additions and 29 deletions
18
README.md
18
README.md
|
@ -16,15 +16,15 @@ P P
|
||||||
```
|
```
|
||||||
|
|
||||||
## symbols
|
## symbols
|
||||||
- `^v<>` Arrows: changes a marbles direction and moves it to the front, as long as there is a free space in the target location (or the marble is already at the target location)
|
- `^v<>` Arrows: changes a marbles direction and moves it to the front, as long as there is a free space in the target location (or the marble is already at the target location, making it effectively bounce)
|
||||||
- `\/` Mirrors: reflects marbles like an arrow, but depending on the incoming direction
|
- `\/` Mirrors: reflects marbles like an arrow, but depends on the incoming direction
|
||||||
- `#` Blocks: block marbles from moving further, without changing their direction
|
- `(text)`, `#` Comments: stops marbles from moving
|
||||||
- `|-+` Wires: powers adjacent tiles when powered, in the directions indicated
|
- `|-+` Wires: powers adjacent tiles when powered, in the directions indicated.
|
||||||
- `*` Trigger: powers all 4 adjacent tiles when a marble moves over it
|
- `*` Trigger: powers all 4 adjacent tiles when a marble moves over it.
|
||||||
- `F` Flipper: flips the direction of a wire, arrow and mirror tiles when powered
|
- `F` Flipper: flips the direction of a wire, arrow and mirror tiles when powered.
|
||||||
- `B` Bag: consumes marbles that move into it, and keeps count of how many marbles it has. When powered, it emits an empty (0) marble moving away from the bag.
|
- `B` Bag: consumes marbles that move into it, and emits an empty (0) marble when powered.
|
||||||
- `ASMDR` Math: Add/Subtract/Multiply/Divide/Remainder of the marble on the left and the right relative to the powered direction. Outputs a marble forward as long as at least one input exists
|
- `ASMDR` Math: Add/Subtract/Multiply/Divide/Remainder of the marble on the left and the right, relative to the power direction. Outputs a marble forward if at least one input exists.
|
||||||
- `LG=!` Logic gates: compare the left and right input (both treated as 0 if absent) and power forward if Left is Less/Greater/Equal/Not Equal with Right
|
- `LG=!` Logic gates: (Less/Greater/Equal/Not Equal) compares the left and right input (both treated as 0 if absent) when powered, and powers forward if the result is true.
|
||||||
- `P` Print: Prints the value of the front marble when powered
|
- `P` Print: Prints the value of the front marble when powered
|
||||||
- `I` Input: Outputs a marble with the next byte from the program input stream, if there are any
|
- `I` Input: Outputs a marble with the next byte from the program input stream, if there are any
|
||||||
- `0123456789` Digits: decimal digits are added to a marbles value after multiplying the marble with 10, this means that a marble passing over `123` would contain the number 123 afterwards. Digits are consumed by marbles passing over them.
|
- `0123456789` Digits: decimal digits are added to a marbles value after multiplying the marble with 10, this means that a marble passing over `123` would contain the number 123 afterwards. Digits are consumed by marbles passing over them.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
> * B
|
> * B
|
||||||
o
|
o
|
||||||
(check if 0)
|
(check if 0)
|
||||||
o 1
|
1
|
||||||
v < B=- 0
|
v < B=- 0
|
||||||
v o * D- (div/10)
|
v o * D- (div/10)
|
||||||
v B * <
|
v B * <
|
||||||
|
@ -19,7 +19,7 @@ v> * 1 o ^
|
||||||
| # <
|
| # <
|
||||||
#|
|
#|
|
||||||
-| v <
|
-| v <
|
||||||
| *-|o
|
| *-|
|
||||||
F +B * ^
|
F +B * ^
|
||||||
#< \F----
|
#< \F----
|
||||||
(ascii digit s)
|
(ascii digit s)
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -21,11 +21,8 @@ struct Machine {
|
||||||
enum Tile {
|
enum Tile {
|
||||||
#[default]
|
#[default]
|
||||||
Blank,
|
Blank,
|
||||||
Block,
|
|
||||||
Comment(u8),
|
Comment(u8),
|
||||||
Bag {
|
Bag,
|
||||||
count: u8,
|
|
||||||
},
|
|
||||||
Marble {
|
Marble {
|
||||||
value: u8,
|
value: u8,
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
|
@ -192,8 +189,7 @@ impl Machine {
|
||||||
Tile::Marble { value: _, dir: _ } => unreachable!(),
|
Tile::Marble { value: _, dir: _ } => unreachable!(),
|
||||||
Tile::Comment(_) => unreachable!(),
|
Tile::Comment(_) => unreachable!(),
|
||||||
Tile::Blank => ' ',
|
Tile::Blank => ' ',
|
||||||
Tile::Block => '#',
|
Tile::Bag => 'B',
|
||||||
Tile::Bag { count: _ } => 'B',
|
|
||||||
Tile::Trigger => '*',
|
Tile::Trigger => '*',
|
||||||
Tile::Wire(w, state) => {
|
Tile::Wire(w, state) => {
|
||||||
powered = state;
|
powered = state;
|
||||||
|
@ -283,8 +279,7 @@ impl Machine {
|
||||||
self.marbles[i] = next_pos;
|
self.marbles[i] = next_pos;
|
||||||
new_tile = Some(Tile::Blank);
|
new_tile = Some(Tile::Blank);
|
||||||
}
|
}
|
||||||
Tile::Bag { count } => {
|
Tile::Bag => {
|
||||||
*count += 1;
|
|
||||||
to_remove.push(i);
|
to_remove.push(i);
|
||||||
new_tile = Some(Tile::Blank);
|
new_tile = Some(Tile::Blank);
|
||||||
}
|
}
|
||||||
|
@ -386,15 +381,12 @@ impl Machine {
|
||||||
self.output.push(value);
|
self.output.push(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tile::Bag { count } => {
|
Tile::Bag => {
|
||||||
if *count > 0 {
|
|
||||||
*count -= 1;
|
|
||||||
if self.grid.get(front_pos).is_blank() {
|
if self.grid.get(front_pos).is_blank() {
|
||||||
*self.grid.get_mut(front_pos) = Tile::Marble { value: 0, dir };
|
*self.grid.get_mut(front_pos) = Tile::Marble { value: 0, dir };
|
||||||
self.marbles.push(front_pos);
|
self.marbles.push(front_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Tile::Input => {
|
Tile::Input => {
|
||||||
if self.input_index < self.input.len() && self.grid.get(front_pos).is_blank() {
|
if self.input_index < self.input.len() && self.grid.get(front_pos).is_blank() {
|
||||||
let value = self.input[self.input_index];
|
let value = self.input[self.input_index];
|
||||||
|
@ -469,7 +461,6 @@ impl Machine {
|
||||||
| Tile::Mirror(_)
|
| Tile::Mirror(_)
|
||||||
| Tile::Arrow(_)
|
| Tile::Arrow(_)
|
||||||
| Tile::Comment(_)
|
| Tile::Comment(_)
|
||||||
| Tile::Block
|
|
||||||
| Tile::Blank => (),
|
| Tile::Blank => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -620,9 +611,9 @@ fn parse(source: &str) -> (Vec<Vec<Tile>>, Vec<Pos>) {
|
||||||
'M' => Tile::Math(MathOp::Mul),
|
'M' => Tile::Math(MathOp::Mul),
|
||||||
'D' => Tile::Math(MathOp::Div),
|
'D' => Tile::Math(MathOp::Div),
|
||||||
'R' => Tile::Math(MathOp::Rem),
|
'R' => Tile::Math(MathOp::Rem),
|
||||||
'B' => Tile::Bag { count: 0 },
|
'B' => Tile::Bag,
|
||||||
d @ '0'..='9' => Tile::Digit(d as u8),
|
d @ '0'..='9' => Tile::Digit(d as u8),
|
||||||
'#' => Tile::Block,
|
'#' => Tile::Comment(b'#'),
|
||||||
' ' => Tile::Blank,
|
' ' => Tile::Blank,
|
||||||
'(' => {
|
'(' => {
|
||||||
in_comment = true;
|
in_comment = true;
|
||||||
|
|
Loading…
Reference in a new issue