time calculation + feature selection

This commit is contained in:
LinlyBoi
2023-05-06 23:24:15 +03:00
parent 31f5b2cdc7
commit bc2e56f4b9
2 changed files with 21 additions and 14 deletions

View File

@@ -38,9 +38,11 @@ impl PlayState {
self.circles.push((x, y, Disk::P1));
self.player_turn = false;
}
pub fn play_cpu(&mut self, cook: fn(&Board, Disk, &i32) -> Board) {
self.board
.play(Disk::P2, cook(&self.board, Disk::P2, &5).last_move as usize);
pub fn play_cpu(&mut self, diff: &i32, cook: fn(&Board, Disk, &i32) -> Board) {
self.board.play(
Disk::P2,
cook(&self.board, Disk::P2, diff).last_move as usize,
);
let column: i32 = self.board.last_move;
self.bottom[column as usize] -= 1;
let (x, y) = get_circle_coords(column, self.bottom[column as usize]);

View File

@@ -1,3 +1,5 @@
use std::time::Instant;
use oxidised4::{
bored::{GameState, MenuState, PlayState, Strategy},
gamedata::{
@@ -63,14 +65,20 @@ fn main() {
}
}
}
false => match strategy {
Strategy::MiniMax => state.play_cpu(minimax_decision),
Strategy::AlphaBeta => state.play_cpu(minimax_decision_pruning),
},
}
if state.board.game_over() {
let scores = state.board.getscore();
println!("Player score: {} \n CPU Score: {}", scores.0, scores.1);
false => {
dbg!();
let time = Instant::now();
match strategy {
Strategy::MiniMax => state.play_cpu(&difficulty, minimax_decision),
Strategy::AlphaBeta => {
state.play_cpu(&difficulty, minimax_decision_pruning)
}
};
println!(
"Time elapsed in cpu turn: {} ms",
time.elapsed().as_millis()
);
}
}
for circle in state.clone().circles {
@@ -93,11 +101,8 @@ const STARTY: i32 = 9;
fn get_mouse_column(rl: &RaylibHandle, sw: i32) -> Option<i32> {
//row,col return
let mouse_pos = rl.get_mouse_x();
dbg!(mouse_pos);
for num in 1..NCOL + 1 {
dbg!(mouse_pos < sw * (num) - STARTY);
if (mouse_pos > sw * (num - 1) + STARTY) && (mouse_pos < sw * (num) - STARTY) {
dbg!(num);
return Some(num - 1);
}
}