From 32c005078de0e3d0d3e8f434e01b22e86c533d89 Mon Sep 17 00:00:00 2001 From: Bananasmoothii <45853225+bananasmoothii@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:25:51 +0200 Subject: [PATCH] cleaning up --- README.md | 2 +- src/main.rs | 26 +++++++++++++++++++++++--- src/min_max.rs | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e3ed860..3d6545f 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,5 @@ This game currently plays in the terminal. To play, run the following command (a cargo run --release ``` -By default, the bot computes 9 moves ahead. You can change this in the first line of the `main` function +By default, the bot computes 10 moves ahead. You can change this in the first line of the `main` function in `src/main.rs`. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 349e26a..3ca423c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ mod scalar; fn main() { let max_depth = 10; - let bot_vs_bot = true; + let bot_vs_bot = false; let worst_case: u64 = (1..=max_depth).into_iter().map(|n| 7u64.pow(n)).sum(); println!( @@ -24,6 +24,24 @@ fn main() { max_depth - 1, worst_case.separate_with_commas() ); + + if bot_vs_bot { + let mut times: Vec = Vec::new(); + loop { + let time = game(max_depth, bot_vs_bot); + times.push(time); + println!( + "Average time: {}ms", + times.iter().sum::() / times.len() as u64 + ); + } + } else { + let time = game(max_depth, bot_vs_bot); + println!("Average time: {}ms", time); + } +} + +fn game(max_depth: u32, bot_vs_bot: bool) -> u64 { let p1 = NonZeroU8::new(1).unwrap(); let p2 = NonZeroU8::new(2).unwrap(); @@ -68,7 +86,9 @@ fn main() { p1_score = game.get_score(p1); - if p1_score == ::Score::MAX || p1_score == ::Score::MIN { + if p1_score == ::Score::MAX + || p1_score == ::Score::MIN + { println!("Player {current_player} won!\n"); game.print(); break; @@ -81,7 +101,7 @@ fn main() { current_player = current_player.other(); } - println!("Average time: {}ms", bot.average_time()); + bot.average_time() } fn player_play(bot: &mut Bot) -> Result<(), &str> { diff --git a/src/min_max.rs b/src/min_max.rs index 0b18bd9..96dd7bf 100644 --- a/src/min_max.rs +++ b/src/min_max.rs @@ -58,7 +58,7 @@ impl GameNode { } } - const FORK_DEPTH: u32 = 3; + const FORK_DEPTH: u32 = 4; const USE_GAME_SCORE: bool = true;