From a3c27fbc5cf95fc3b0fd4eb0c6b284d184078a28 Mon Sep 17 00:00:00 2001 From: "Tristan F." Date: Sun, 3 Nov 2024 21:48:56 -0800 Subject: [PATCH] chore: refactor nim -> naive_nim --- crates/games-cli/src/main.rs | 4 ++-- crates/games-ui/src/app.rs | 4 ++-- crates/games/src/lib.rs | 16 ++++++++-------- crates/games/src/{nim => naive_nim}/README.md | 5 +++++ crates/games/src/{nim => naive_nim}/gui.rs | 0 crates/games/src/{nim => naive_nim}/mod.rs | 0 crates/nimnim/README.md | 3 +++ 7 files changed, 20 insertions(+), 12 deletions(-) rename crates/games/src/{nim => naive_nim}/README.md (53%) rename crates/games/src/{nim => naive_nim}/gui.rs (100%) rename crates/games/src/{nim => naive_nim}/mod.rs (100%) create mode 100644 crates/nimnim/README.md diff --git a/crates/games-cli/src/main.rs b/crates/games-cli/src/main.rs index 5c36810..7baf0be 100644 --- a/crates/games-cli/src/main.rs +++ b/crates/games-cli/src/main.rs @@ -1,7 +1,7 @@ use anyhow::Result; use clap::Parser; use games::{ - chomp::Chomp, domineering::Domineering, nim::Nim, order_and_chaos::OrderAndChaos, + chomp::Chomp, domineering::Domineering, naive_nim::Nim, order_and_chaos::OrderAndChaos, reversi::Reversi, sprouts::Sprouts, tic_tac_toe::TicTacToe, util::cli::play, Games, }; @@ -24,7 +24,7 @@ fn main() -> Result<()> { Games::OrderAndChaos(args) => { play::>(args.try_into().unwrap(), cli.plain) } - Games::Nim(args) => play::(args.try_into().unwrap(), cli.plain), + Games::NaiveNim(args) => play::(args.try_into().unwrap(), cli.plain), Games::Domineering(args) => play::>(args.try_into().unwrap(), cli.plain), Games::Chomp(args) => play::(args.try_into().unwrap(), cli.plain), Games::Sprouts(args) => play::(args.try_into().unwrap(), cli.plain), diff --git a/crates/games-ui/src/app.rs b/crates/games-ui/src/app.rs index f9f82fd..ae718c1 100644 --- a/crates/games-ui/src/app.rs +++ b/crates/games-ui/src/app.rs @@ -1,4 +1,4 @@ -use games::{nim, util::gui::egui_display::EguiDisplay, Games, DEFAULT_GAMES}; +use games::{naive_nim, util::gui::egui_display::EguiDisplay, Games, DEFAULT_GAMES}; /// We derive Deserialize/Serialize so we can persist app state on shutdown. #[derive(serde::Deserialize, serde::Serialize)] @@ -66,7 +66,7 @@ impl eframe::App for TemplateApp { game.description_egui(ui) }); - let game = nim::Nim::new(vec![5, 3, 1]); + let game = naive_nim::Nim::new(vec![5, 3, 1]); game.display(ui); } else { diff --git a/crates/games/src/lib.rs b/crates/games/src/lib.rs index 09df0bd..ebd2a78 100644 --- a/crates/games/src/lib.rs +++ b/crates/games/src/lib.rs @@ -2,14 +2,14 @@ pub mod util; pub mod chomp; pub mod domineering; -pub mod nim; +pub mod naive_nim; pub mod order_and_chaos; pub mod reversi; pub mod sprouts; pub mod tic_tac_toe; use crate::{ - chomp::ChompArgs, domineering::DomineeringArgs, nim::NimArgs, + chomp::ChompArgs, domineering::DomineeringArgs, naive_nim::NimArgs, order_and_chaos::OrderAndChaosArgs, reversi::ReversiArgs, sprouts::SproutsArgs, tic_tac_toe::TicTacToeArgs, }; @@ -22,7 +22,7 @@ pub enum Games { Reversi(ReversiArgs), TicTacToe(TicTacToeArgs), OrderAndChaos(OrderAndChaosArgs), - Nim(NimArgs), + NaiveNim(NimArgs), Domineering(DomineeringArgs), Chomp(ChompArgs), Sprouts(SproutsArgs), @@ -33,7 +33,7 @@ pub static DEFAULT_GAMES: Lazy<[Games; 7]> = Lazy::new(|| { Games::Reversi(Default::default()), Games::TicTacToe(Default::default()), Games::OrderAndChaos(Default::default()), - Games::Nim(Default::default()), + Games::NaiveNim(Default::default()), Games::Domineering(Default::default()), Games::Chomp(Default::default()), Games::Sprouts(Default::default()), @@ -46,7 +46,7 @@ impl Games { Self::Reversi(_) => "Reversi".to_string(), Self::TicTacToe(_) => "Tic Tac Toe".to_string(), Self::OrderAndChaos(_) => "Order and Chaos".to_string(), - Self::Nim(_) => "Nim".to_string(), + Self::NaiveNim(_) => "Nim (Naive)".to_string(), Self::Domineering(_) => "Domineering".to_string(), Self::Chomp(_) => "Chomp".to_string(), Self::Sprouts(_) => "Sprouts".to_string(), @@ -58,7 +58,7 @@ impl Games { Self::Reversi(_) => include_str!("./reversi/README.md"), Self::TicTacToe(_) => include_str!("./tic_tac_toe/README.md"), Self::OrderAndChaos(_) => include_str!("./order_and_chaos/README.md"), - Self::Nim(_) => include_str!("./nim/README.md"), + Self::NaiveNim(_) => include_str!("./naive_nim/README.md"), Self::Domineering(_) => include_str!("./domineering/README.md"), Self::Chomp(_) => include_str!("./chomp/README.md"), Self::Sprouts(_) => include_str!("./sprouts/README.md"), @@ -87,11 +87,11 @@ impl Games { &mut cache, "crates/games/src/order_and_chaos/README.md" ), - Self::Nim(_) => egui_commonmark::commonmark_str!( + Self::NaiveNim(_) => egui_commonmark::commonmark_str!( "nim", ui, &mut cache, - "crates/games/src/nim/README.md" + "crates/games/src/naive_nim/README.md" ), Self::Domineering(_) => egui_commonmark::commonmark_str!( "domineering", diff --git a/crates/games/src/nim/README.md b/crates/games/src/naive_nim/README.md similarity index 53% rename from crates/games/src/nim/README.md rename to crates/games/src/naive_nim/README.md index d69b7d6..49ccdea 100644 --- a/crates/games/src/nim/README.md +++ b/crates/games/src/naive_nim/README.md @@ -3,4 +3,9 @@ Its a game about removing objects from heaps. Despite its ability to be rigidly analyzed, it still makes a great example as an implementation of the `Game` trait. +This implements a _naive_ version of Nim - i.e., it doesn't benefit +from any of the impartial analysis techniques implemented in this game solver. + +If you are looking for a fast variant of nim, one is implemented in the core `game-solver` crate. + Learn more about Nim here: diff --git a/crates/games/src/nim/gui.rs b/crates/games/src/naive_nim/gui.rs similarity index 100% rename from crates/games/src/nim/gui.rs rename to crates/games/src/naive_nim/gui.rs diff --git a/crates/games/src/nim/mod.rs b/crates/games/src/naive_nim/mod.rs similarity index 100% rename from crates/games/src/nim/mod.rs rename to crates/games/src/naive_nim/mod.rs diff --git a/crates/nimnim/README.md b/crates/nimnim/README.md new file mode 100644 index 0000000..753f873 --- /dev/null +++ b/crates/nimnim/README.md @@ -0,0 +1,3 @@ +# nimnim + +implementation of nimbers and their operations.