mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-14 15:25:08 +01:00
perf
This commit is contained in:
parent
c7a6bdf3c0
commit
6316c6b06e
6 changed files with 47 additions and 4 deletions
BIN
perf.data
BIN
perf.data
Binary file not shown.
BIN
perf.data.old
BIN
perf.data.old
Binary file not shown.
39
src/connect4/board.rs
Normal file
39
src/connect4/board.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use crate::Player;
|
||||
|
||||
type Position = Option<Player>;
|
||||
|
||||
const BOARD_WIDTH: usize = 7;
|
||||
const BOARD_HEIGHT: usize = 4;
|
||||
const BOARD_POSITIONS: usize = BOARD_WIDTH * BOARD_HEIGHT;
|
||||
|
||||
struct Winner<T>(Option<T>);
|
||||
|
||||
impl<T> std::ops::Try for Winner<T> {
|
||||
// Always None
|
||||
type Output = Winner<!>;
|
||||
|
||||
type Residual = Winner<T>;
|
||||
|
||||
fn from_output(_: Self::Output) -> Self {
|
||||
Self(None)
|
||||
}
|
||||
|
||||
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
|
||||
match self {
|
||||
Self(Some(_)) => ControlFlow::Break(self),
|
||||
Self(None) => ControlFlow::Continue(self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Board {
|
||||
positions: [Position; BOARD_POSITIONS],
|
||||
}
|
||||
|
||||
impl Board {
|
||||
fn winner() -> Winner<Player> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
1
src/connect4/mod.rs
Normal file
1
src/connect4/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
mod board;
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
#![feature(never_type, try_trait_v2)]
|
||||
|
||||
mod board;
|
||||
mod connect4;
|
||||
mod game;
|
||||
mod perfect;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
|
||||
let start = SystemTime::now();
|
||||
|
||||
for _ in 0..1000 {
|
||||
for _ in 0..1 {
|
||||
let result = play_round::<PerfectPlayer, GreedyPlayer>(false);
|
||||
let idx = Player::as_u8(result);
|
||||
results[idx as usize] += 1;
|
||||
|
|
@ -29,17 +29,17 @@ fn play_round<X: GamePlayer, O: GamePlayer>(print: bool) -> Option<Player> {
|
|||
let mut board = Board::empty();
|
||||
let result = board.play(&mut X::default(), &mut O::default());
|
||||
if print {
|
||||
//println!("{board}");
|
||||
println!("{board}");
|
||||
}
|
||||
match result {
|
||||
Some(winner) => {
|
||||
if print {
|
||||
//println!("player {winner} won!");
|
||||
println!("player {winner} won!");
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if print {
|
||||
//println!("a draw...")
|
||||
println!("a draw...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue