Fix best move in FFI

This commit is contained in:
nora 2023-01-28 09:56:40 +01:00
parent 545cb5dce3
commit 6b309efd32
2 changed files with 5 additions and 8 deletions

View file

@ -35,8 +35,9 @@ impl<G: Game> PerfectPlayer<G> {
self self
} }
pub fn best_move(&self) -> G::Move { pub fn best_move(&self, board: &G) -> G::Move {
self.best_move.expect("no move made yet") self.best_move
.unwrap_or_else(|| board.possible_moves().next().expect("cannot make move"))
} }
fn minmax<P: MinmaxPlayer>( fn minmax<P: MinmaxPlayer>(
@ -141,11 +142,7 @@ impl<G: Game> GamePlayer<G> for PerfectPlayer<G> {
0, 0,
); );
board.make_move( board.make_move(self.best_move(board), this_player);
self.best_move
.unwrap_or_else(|| board.possible_moves().next().expect("cannot make move")),
this_player,
);
if self.print_time { if self.print_time {
let duration = start.elapsed(); let duration = start.elapsed();

View file

@ -74,7 +74,7 @@ pub fn play_move(env: JNIEnv<'_>, current_player: i8, board: JObject<'_>) -> i32
}; };
player.next_move(&mut board, current_player_rust); player.next_move(&mut board, current_player_rust);
let result_move = player.best_move(); let result_move = player.best_move(&board);
board.undo_move(result_move); board.undo_move(result_move);
let result_move = board.drop_player(result_move); let result_move = board.drop_player(result_move);