time calculation + feature selection
This commit is contained in:
@@ -38,9 +38,11 @@ impl PlayState {
|
|||||||
self.circles.push((x, y, Disk::P1));
|
self.circles.push((x, y, Disk::P1));
|
||||||
self.player_turn = false;
|
self.player_turn = false;
|
||||||
}
|
}
|
||||||
pub fn play_cpu(&mut self, cook: fn(&Board, Disk, &i32) -> Board) {
|
pub fn play_cpu(&mut self, diff: &i32, cook: fn(&Board, Disk, &i32) -> Board) {
|
||||||
self.board
|
self.board.play(
|
||||||
.play(Disk::P2, cook(&self.board, Disk::P2, &5).last_move as usize);
|
Disk::P2,
|
||||||
|
cook(&self.board, Disk::P2, diff).last_move as usize,
|
||||||
|
);
|
||||||
let column: i32 = self.board.last_move;
|
let column: i32 = self.board.last_move;
|
||||||
self.bottom[column as usize] -= 1;
|
self.bottom[column as usize] -= 1;
|
||||||
let (x, y) = get_circle_coords(column, self.bottom[column as usize]);
|
let (x, y) = get_circle_coords(column, self.bottom[column as usize]);
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -1,3 +1,5 @@
|
|||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use oxidised4::{
|
use oxidised4::{
|
||||||
bored::{GameState, MenuState, PlayState, Strategy},
|
bored::{GameState, MenuState, PlayState, Strategy},
|
||||||
gamedata::{
|
gamedata::{
|
||||||
@@ -63,14 +65,20 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false => match strategy {
|
false => {
|
||||||
Strategy::MiniMax => state.play_cpu(minimax_decision),
|
dbg!();
|
||||||
Strategy::AlphaBeta => state.play_cpu(minimax_decision_pruning),
|
let time = Instant::now();
|
||||||
},
|
match strategy {
|
||||||
}
|
Strategy::MiniMax => state.play_cpu(&difficulty, minimax_decision),
|
||||||
if state.board.game_over() {
|
Strategy::AlphaBeta => {
|
||||||
let scores = state.board.getscore();
|
state.play_cpu(&difficulty, minimax_decision_pruning)
|
||||||
println!("Player score: {} \n CPU Score: {}", scores.0, scores.1);
|
}
|
||||||
|
};
|
||||||
|
println!(
|
||||||
|
"Time elapsed in cpu turn: {} ms",
|
||||||
|
time.elapsed().as_millis()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for circle in state.clone().circles {
|
for circle in state.clone().circles {
|
||||||
@@ -93,11 +101,8 @@ const STARTY: i32 = 9;
|
|||||||
fn get_mouse_column(rl: &RaylibHandle, sw: i32) -> Option<i32> {
|
fn get_mouse_column(rl: &RaylibHandle, sw: i32) -> Option<i32> {
|
||||||
//row,col return
|
//row,col return
|
||||||
let mouse_pos = rl.get_mouse_x();
|
let mouse_pos = rl.get_mouse_x();
|
||||||
dbg!(mouse_pos);
|
|
||||||
for num in 1..NCOL + 1 {
|
for num in 1..NCOL + 1 {
|
||||||
dbg!(mouse_pos < sw * (num) - STARTY);
|
|
||||||
if (mouse_pos > sw * (num - 1) + STARTY) && (mouse_pos < sw * (num) - STARTY) {
|
if (mouse_pos > sw * (num - 1) + STARTY) && (mouse_pos < sw * (num) - STARTY) {
|
||||||
dbg!(num);
|
|
||||||
return Some(num - 1);
|
return Some(num - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user