time calculation + feature selection
This commit is contained in:
@@ -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]);
|
||||
|
||||
25
src/main.rs
25
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),
|
||||
},
|
||||
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()
|
||||
);
|
||||
}
|
||||
if state.board.game_over() {
|
||||
let scores = state.board.getscore();
|
||||
println!("Player score: {} \n CPU Score: {}", scores.0, scores.1);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user