Skip to content

Commit

Permalink
chore: refactor nim -> naive_nim
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Nov 4, 2024
1 parent e12d2b9 commit a3c27fb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/games-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -24,7 +24,7 @@ fn main() -> Result<()> {
Games::OrderAndChaos(args) => {
play::<OrderAndChaos<6, 6, 5, 6>>(args.try_into().unwrap(), cli.plain)
}
Games::Nim(args) => play::<Nim>(args.try_into().unwrap(), cli.plain),
Games::NaiveNim(args) => play::<Nim>(args.try_into().unwrap(), cli.plain),
Games::Domineering(args) => play::<Domineering<5, 5>>(args.try_into().unwrap(), cli.plain),
Games::Chomp(args) => play::<Chomp>(args.try_into().unwrap(), cli.plain),
Games::Sprouts(args) => play::<Sprouts>(args.try_into().unwrap(), cli.plain),
Expand Down
4 changes: 2 additions & 2 deletions crates/games-ui/src/app.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions crates/games/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -22,7 +22,7 @@ pub enum Games {
Reversi(ReversiArgs),
TicTacToe(TicTacToeArgs),
OrderAndChaos(OrderAndChaosArgs),
Nim(NimArgs),
NaiveNim(NimArgs),
Domineering(DomineeringArgs),
Chomp(ChompArgs),
Sprouts(SproutsArgs),
Expand All @@ -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()),
Expand All @@ -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(),
Expand All @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://en.wikipedia.org/wiki/Nim>
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions crates/nimnim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# nimnim

implementation of nimbers and their operations.

0 comments on commit a3c27fb

Please sign in to comment.