Skip to content

Commit a5bfdd3

Browse files
committed
Big breaking refactoring of the old code into multiple files.
1 parent 6fa58c8 commit a5bfdd3

12 files changed

Lines changed: 603 additions & 561 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "e2rs"
33
version = "0.1.0"
44
edition = "2021"
5-
author = "turingatemyhamster@gmail.com"
5+
authors = ["turingatemyhamster@gmail.com"]
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

@@ -17,8 +17,6 @@ path = "src/bin/test_main.rs"
1717
[[bin]]
1818
name = "render_solution"
1919
path = "src/bin/render_solution.rs"
20-
author = "turingatemyhamster@gmail.com"
21-
version = "0.1.0"
2220

2321
[dependencies]
2422
clap = { version = "4.1.1", features = ["derive"] }

src/bin/render_solution.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
use std::{io::{BufReader, Read}, fs::File};
1+
#![feature(is_some_and)]
2+
3+
use std::{
4+
fs::File,
5+
io::{BufReader, Read},
6+
};
27

38
use clap::Parser;
49
use e2rs::{e2::E2_BOARD_SPEC, images::board_image};
@@ -12,8 +17,7 @@ struct Cli {
1217
/// file to write the board image to
1318
image: std::path::PathBuf,
1419
/// set the rotation direction to clockwise (default anti-clockwise)
15-
#[arg(default_value_t = false)]
16-
clockwise: bool,
20+
clockwise: Option<bool>,
1721
}
1822

1923
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -23,8 +27,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2327
let mut solution_txt = String::new();
2428
solution.read_to_string(&mut solution_txt)?;
2529

26-
let clues = E2_BOARD_SPEC.tiles.parse_clues(solution_txt.as_str(), args.clockwise);
27-
let mut board = E2_BOARD_SPEC.dimensions.unwrap().new_board();
30+
let clues = E2_BOARD_SPEC
31+
.parse_clues(solution_txt.as_str(), args.clockwise.is_some_and(|b| b));
32+
let mut board = E2_BOARD_SPEC.dimensions.new_board();
2833

2934
for clue in clues {
3035
clue.apply(&mut board);
@@ -34,4 +39,4 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3439
img.save(args.image)?;
3540

3641
Ok(())
37-
}
42+
}

src/bin/test_main.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
//! Eternity 2-family puzzles.
22
3+
use rand::{
4+
distributions::{Slice, Uniform},
5+
prelude::Distribution,
6+
};
37

4-
use rand::{distributions::{Slice, Uniform}, prelude::Distribution};
5-
6-
use e2rs::{board::{Clue, ROTATIONS, Indx}, e2::{self, E2_CLUES}, images::{board_image}};
7-
8+
use e2rs::{
9+
model::{Clue, Indx, ROTATIONS, Rotate},
10+
e2::{self, E2_CLUES},
11+
images::board_image,
12+
};
813

914
fn main() {
1015
let spec = e2::board_spec();
1116
let tiles = &spec.tiles;
12-
let dims = spec.dimensions.unwrap();
17+
let dims = &spec.dimensions;
1318

1419
println!("Loaded tiles.");
1520
for (i, t) in tiles.into_iter().enumerate() {
@@ -26,7 +31,7 @@ fn main() {
2631

2732
let mut rng = rand::thread_rng();
2833
let r_tile = Slice::new(&tiles[..]).unwrap().map(Clone::clone);
29-
let r_col= Uniform::new(0, dims.columns);
34+
let r_col = Uniform::new(0, dims.columns);
3035
let r_row = Uniform::new(0, dims.rows);
3136
let r_rot = Slice::new(&ROTATIONS).unwrap().map(Clone::clone);
3237

@@ -37,7 +42,10 @@ fn main() {
3742
let clue = Clue {
3843
tile: r_tile.sample(&mut rng),
3944
rotation: r_rot.sample(&mut rng),
40-
at: Indx { col: r_col.sample(&mut rng), row: r_row.sample(&mut rng) }
45+
at: Indx {
46+
col: r_col.sample(&mut rng),
47+
row: r_row.sample(&mut rng),
48+
},
4149
};
4250
println!("Applying clue: {:?}", clue);
4351

0 commit comments

Comments
 (0)