Skip to content

Commit

Permalink
update maze generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
oiwn committed Dec 13, 2023
1 parent 167e931 commit 68081a6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tarts" # shortcut from Terminal Arts
version = "0.1.3"
version = "0.1.4"
edition = "2021"

authors = ["oiwn <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion src/check/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Check {

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

#[test]
fn some_test() {}
Expand Down
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! # tarts
//!
//! `tarts` or TerminalArts is a collection of terminal-based screen savers written in Rust.
//! This crate provides a variety of screen savers like "Matrix Rain", "Conway's Game of Life",
//! and "Maze Generation" (not yet), all running directly in your terminal.
//! `tarts` or TerminalArts is a collection of terminal-based screen savers written
//! in Rust. This crate provides a variety of screen savers like "Matrix Rain",
//! "Conway's Game of Life", and "Maze Generation" (not yet), all running directly
//! in your terminal.
//!
//! ## Features
//!
Expand All @@ -12,7 +13,8 @@
//!
//! ## Usage
//!
//! To use the screen savers, run the executable with the desired screen saver's name as an argument:
//! To use the screen savers, run the executable with the desired screen saver's
//! name as an argument:
//!
//! ```bash
//! tarts matrix
Expand All @@ -30,11 +32,13 @@
//!
//! ## Configuration
//!
//! The screen savers can be configured via command line arguments (planning to add configuration file).
//! The screen savers can be configured via command line arguments
//! (planning to add configuration file).
//!
//! ## Contributing
//!
//! Contributions are welcome! Please feel free to submit pull requests, report bugs, and suggest features.
//! Contributions are welcome! Please feel free to submit pull requests,
//! report bugs, and suggest features.
//!
//! ## License
//!
Expand Down
58 changes: 12 additions & 46 deletions src/maze/gen_maze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,45 +123,6 @@ impl TerminalEffect for Maze {
self.maze_complete = true;
}
}

/*
fn update(&mut self) {
if self.maze_complete {
return;
}
if let Some((x, y)) = self.stack.pop_back() {
let directions = [(1, 0), (0, 1), (-1, 0), (0, -1)];
let mut shuffled_directions = directions;
shuffled_directions.shuffle(&mut self.rng);
let mut moved = false;
for &(dx, dy) in &shuffled_directions {
let new_x = x + dx;
let new_y = y + dy;
if self.is_valid_cell(new_x, new_y)
&& !self.paths.contains(&(new_x as usize, new_y as usize))
{
self.carve_path(new_x, new_y);
// Push the current position back for backtracking
self.stack.push_back((x, y));
self.stack.push_back((new_x, new_y)); // Push the new position
moved = true;
break;
}
}
if !moved {
// If we didn't move, it means we're at a dead-end and need to backtrack
self.stack.pop_back();
}
} else {
// If the stack is empty, the maze is complete
self.maze_complete = true;
}
}
*/
}

impl Maze {
Expand Down Expand Up @@ -251,7 +212,8 @@ mod tests {
initialized_cells += 1;
}
}
assert_eq!(initialized_cells, 9);
assert_eq!(initialized_cells, 0);
assert_eq!(maze.initial_walls.buffer.len(), 9);

// path and stack are empty, and maze is not completed
assert!(maze.paths.is_empty());
Expand All @@ -262,21 +224,25 @@ mod tests {
#[test]
fn check_flow() {
let options = MazeOptionsBuilder::default()
.screen_size((3, 3))
.screen_size((5, 5))
.build()
.unwrap();
let mut maze = Maze::new(options);
maze.update();
let diff = maze.get_diff();
assert_eq!(diff.len(), 1);
assert_eq!(diff.len(), 25);

// /* NOTE: why no path_cells set in buffer after update?
// maze.update();
// let _ = maze.get_diff();
// buffer correctly processed
let mut initialized_cells = 0;
let mut path_cells = 0;
for cell in maze.buffer.iter() {
if cell.symbol != ' ' {
initialized_cells += 1;
if cell.symbol != '' {
path_cells += 1;
}
}
assert_eq!(initialized_cells, 8);
assert_eq!(path_cells, 23);
// */
}
}
4 changes: 2 additions & 2 deletions src/rain/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ mod tests {
let _ = crate::common::run_loop(&mut stdout, &mut digital_rain, Some(10));
}

// #[test]
// NOTE: this test failed on github CI pipeline
#[test]
fn run_loop_fps_gte_0() {
// NOTE: this test failed on github CI pipeline
let mut stdout = Vec::new();
let mut digital_rain = get_default_rain();
let mut fps: f64 = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/rain/rain_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mod tests {
let mut rng = rand::thread_rng();
let mut new_drop = RainDrop::new(&get_sane_options(), 1, &mut rng);
assert!(new_drop.body.len() > 0);
assert!(new_drop.speed > 10);
assert!(new_drop.speed > 0);

new_drop.reset(&get_sane_options(), &mut rng);
assert_eq!(new_drop.fy, 0.0);
Expand Down

0 comments on commit 68081a6

Please sign in to comment.