Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
bananasmoothii committed Oct 12, 2023
1 parent 2e232ec commit 32c0050
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
26 changes: 23 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -24,6 +24,24 @@ fn main() {
max_depth - 1,
worst_case.separate_with_commas()
);

if bot_vs_bot {
let mut times: Vec<u64> = Vec::new();
loop {
let time = game(max_depth, bot_vs_bot);
times.push(time);
println!(
"Average time: {}ms",
times.iter().sum::<u64>() / 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();

Expand Down Expand Up @@ -68,7 +86,9 @@ fn main() {

p1_score = game.get_score(p1);

if p1_score == <ConnectFour as Game>::Score::MAX || p1_score == <ConnectFour as Game>::Score::MIN {
if p1_score == <ConnectFour as Game>::Score::MAX
|| p1_score == <ConnectFour as Game>::Score::MIN
{
println!("Player {current_player} won!\n");
game.print();
break;
Expand All @@ -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<ConnectFour>) -> Result<(), &str> {
Expand Down
2 changes: 1 addition & 1 deletion src/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<G: Game> GameNode<G> {
}
}

const FORK_DEPTH: u32 = 3;
const FORK_DEPTH: u32 = 4;

const USE_GAME_SCORE: bool = true;

Expand Down

0 comments on commit 32c0050

Please sign in to comment.