Skip to content

Commit

Permalink
Refactoring path file management
Browse files Browse the repository at this point in the history
  • Loading branch information
be-next committed Jan 4, 2024
1 parent eaa9ffe commit d350645
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license.workspace = true
[dependencies]
serde = { version = "1.0.194", features = ["derive"] }
serde_json = "1.0.110"
clap = { version = "4.4.12", features = ["derive"] }
#clap = { version = "4.4.12", features = ["derive"] }


[workspace]
Expand Down
2 changes: 1 addition & 1 deletion examples/example_01/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"num_states": 3,
"num_cells": 14,
"world_initialisation" : "0 0 1 1 1 1 0 1 1 1 1 1 0 0",
"rules_file_name": "examples/example_01/rules.json"
"rules_file_name": "rules.json"
}
2 changes: 1 addition & 1 deletion examples/example_02/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"num_states": 7,
"num_cells": 22,
"world_initialisation" : "0 0 1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0",
"rules_file_name": "examples/example_02/rules.json"
"rules_file_name": "rules.json"
}
2 changes: 1 addition & 1 deletion examples/example_04/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"num_states": 4,
"num_cells": 15,
"world_initialisation" : "0 0 1 1 1 1 0 1 1 1 1 1 1 0 0",
"rules_file_name": "examples/example_04/rules.json"
"rules_file_name": "rules.json"
}
1 change: 0 additions & 1 deletion examples/example_04/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "Invert",
"num_states": 4,
"rules": [
{"neighborhood": [4, 0, 0], "next_state": 0},
{"neighborhood": [1, 0, 1], "next_state": 2},
{"neighborhood": [1, 1, 2], "next_state": 2},
{"neighborhood": [2, 1, 1], "next_state": 2},
Expand Down
2 changes: 1 addition & 1 deletion examples/example_06/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"num_states": 5,
"num_cells": 12,
"world_initialisation" : "0 0 1 1 1 1 1 1 1 1 0 0",
"rules_file_name": "examples/example_06/rules.json"
"rules_file_name": "rules.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "Divide by 2",
"num_states": 5,
"rules": [
{"neighborhood": [5, 0, 0], "next_state": 0},
{"neighborhood": [0, 1, 1], "next_state": 2},
{"neighborhood": [2, 1, 1], "next_state": 2},
{"neighborhood": [2, 2, 1], "next_state": 1},
Expand Down
2 changes: 1 addition & 1 deletion examples/example_07/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"num_states": 7,
"num_cells": 22,
"world_initialisation" : "0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"rules_file_name": "examples/example_07/rules.json"
"rules_file_name": "rules.json"
}
1 change: 0 additions & 1 deletion examples/example_07/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "+1 suite",
"num_states": 7,
"rules": [
{"neighborhood": [7, 0, 0], "next_state": 0},
{"neighborhood": [1, 0, 0], "next_state": 2},
{"neighborhood": [1, 1, 2], "next_state": 3},
{"neighborhood": [1, 3, 2], "next_state": 4},
Expand Down
2 changes: 1 addition & 1 deletion examples/rule_184/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"num_states": 2,
"num_cells": 15,
"world_initialisation" : "0 0 0 0 0 0 0 1 0 0 0 0 0 0 0",
"rules_file_name": "examples/rule_184/rules.json"
"rules_file_name": "rules.json"
}
7 changes: 6 additions & 1 deletion src/core/cellular_automaton_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use crate::core::cellular_automaton::CA1D;
use crate::core::cellular_automaton_configuration::CA1DConfiguration;
use crate::core::cellular_automaton_configuration::CA1DConfigurationError;
Expand Down Expand Up @@ -30,10 +31,14 @@ impl CellularAutomatonBuilder {
}

pub fn build(&self, configuration_file_name: &str) -> Result<CA1D, CellularAutomatonBuilderError> {
let configuration_file_path = Path::new(configuration_file_name);
let parent_path = configuration_file_path.parent().unwrap();

let ca1d_configuration = CA1DConfiguration::new_from_json_file(configuration_file_name)?;
let rules_file_name = parent_path.join(ca1d_configuration.get_rules_file_name());

let lookup_table_builder = LookupTableBuilder::new();
let lookup_table = lookup_table_builder.build(ca1d_configuration.get_rules_file_name())?;
let lookup_table = lookup_table_builder.build(rules_file_name.as_os_str().to_str().unwrap())?;

let mut ca1d = CA1D::new(
ca1d_configuration.get_num_states(),
Expand Down

0 comments on commit d350645

Please sign in to comment.