Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
596 changes: 268 additions & 328 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ You can also use the `home-manager` module to install and configure `trmt`. Firs
config = {
simulation = {
autoplay = true;
mode = "halt";
heads = 3;
rule = "RL";
speed_ms = 20;
Expand Down Expand Up @@ -193,6 +194,7 @@ https://github.com/user-attachments/assets/eefc272b-09b2-4c9c-93dc-984c1ae60ed0
```toml
[simulation]
autoplay = true # If true, simulation starts running automatically on launch, reset and config reload
mode = "halt" # What happens when a run stalls or repeats exactly. "halt" = pause, "loop" = restart
heads = 3 # Number of heads on initialization
rule = "RL" # Rules for the simulation
speed_ms = 20 # Simulation speed in milliseconds
Expand Down
1 change: 1 addition & 0 deletions examples/builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 6
rule = "L1>1,R1>1:R1>1,R0>0"
speed_ms = 8.0
Expand Down
1 change: 1 addition & 0 deletions examples/critter_highway.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 6
rule = "WRSWNL"
speed_ms = 10.0
Expand Down
1 change: 1 addition & 0 deletions examples/dotgrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 6
rule = "R1>1,L0>2,U1>0:D0>0,R1>1:L0>1,R1>2"
speed_ms = 30.0
Expand Down
1 change: 1 addition & 0 deletions examples/factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 4
rule = "R1>1,L0>1:U1>0,D0>1"
speed_ms = 5.0
Expand Down
1 change: 1 addition & 0 deletions examples/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Inspired by [cmatrix](https://github.com/abishekvashok/cmatrix) and [unimatrix](
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 128
rule = "S"
speed_ms = 100.0
Expand Down
1 change: 1 addition & 0 deletions examples/pipedream.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 4
rule = "DUWLWWRWD"
speed_ms = 10.0
Expand Down
1 change: 1 addition & 0 deletions examples/scaffold.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 4
rule = "DULNESWUNW"
speed_ms = 10.0
Expand Down
1 change: 1 addition & 0 deletions examples/transistor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```toml
[simulation]
autoplay = true
mode = "halt"
heads = 5
rule = "WUNRSL"
speed_ms = 9.0
Expand Down
4 changes: 3 additions & 1 deletion nix/modules/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ in {
{
simulation = {
autoplay = true;
mode = "halt";
heads = 3;
rule = "RL";
speed_ms = 20;
Expand All @@ -39,11 +40,12 @@ in {
cell_char = "░░";
randomize_heads = false;
randomize_trails = false;
direction_based_chars = false
direction_based_chars = false;
};
controls = {
quit = "q";
toggle = " ";
step = ".";
reset = "r";
faster = "+";
slower = "-";
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ratatui::style::Color;
use serde::{Deserialize, Serialize};
use std::{error::Error, fs, path::PathBuf};

pub use simulation::SimulationConfig;
pub use simulation::{SimulationConfig, SimMode};
pub use display::{DisplayConfig, CharData};
pub use controls::ControlsConfig;

Expand Down
32 changes: 31 additions & 1 deletion src/config/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize};
use rand::Rng;
use std::collections::{HashSet};

// What to do when detection proves a run is done
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SimMode {
Halt,
Loop,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SimulationConfig {
#[serde(default = "autoplay")]
Expand All @@ -18,6 +26,8 @@ pub struct SimulationConfig {
pub color_cells: bool,
#[serde(default = "seed")]
pub seed: Option<String>,
#[serde(default = "mode")]
pub mode: SimMode,
}

// Default functions
Expand All @@ -28,6 +38,7 @@ fn speed() -> f64 { 5.0 }
fn trail_length() -> usize { 16 }
fn color_cells() -> bool { true }
fn seed() -> Option<String> { Some(String::new()) }
fn mode() -> SimMode { SimMode::Halt }

impl Default for SimulationConfig {
fn default() -> Self {
Expand All @@ -39,6 +50,7 @@ impl Default for SimulationConfig {
trail_length: trail_length(),
color_cells: color_cells(),
seed: seed(),
mode: mode(),
}
}
}
Expand Down Expand Up @@ -166,7 +178,7 @@ impl SimulationConfig {

transitions.join(",")
}

// Score rules based on potential for interesting behavior
fn score_rule_potential(rule: &str) -> i32 {
let mut score = 0;
Expand Down Expand Up @@ -194,4 +206,22 @@ impl SimulationConfig {

score
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn mode_parses_from_toml_and_defaults_to_halt() {
let parsed: SimulationConfig = toml::from_str("mode = \"loop\"").unwrap();
assert_eq!(parsed.mode, SimMode::Loop);
let empty: SimulationConfig = toml::from_str("").unwrap();
assert_eq!(empty.mode, SimMode::Halt);
assert_eq!(SimulationConfig::default().mode, SimMode::Halt);
assert!(toml::from_str::<SimulationConfig>("mode = \"disco\"").is_err());
// create_example_config serializes this, so the TOML name has to round-trip
let serialized = toml::to_string(&SimulationConfig::default()).unwrap();
assert!(serialized.contains("mode = \"halt\""), "{serialized}");
}
}
Loading
Loading