From bc2e56f4b9e485b75f6d4b8845c5bd9a48fbfe5b Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Sat, 6 May 2023 23:24:15 +0300 Subject: [PATCH] time calculation + feature selection --- src/bored/mod.rs | 8 +++++--- src/main.rs | 27 ++++++++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/bored/mod.rs b/src/bored/mod.rs index 95148e8..10cdbf0 100644 --- a/src/bored/mod.rs +++ b/src/bored/mod.rs @@ -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]); diff --git a/src/main.rs b/src/main.rs index 31f4d04..a98e191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { //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); } }