typing improvements

This commit is contained in:
Simon Gardling 2025-04-18 23:52:13 -04:00
parent 85e3a11897
commit 625b02c13a
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
4 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,7 @@
use crate::{
agent::{Agent, AgentMove},
repr::{Board, CoordPair, Piece, Winner},
logic::MoveCoord,
repr::{Board, Piece, Winner},
};
impl std::fmt::Display for GameInner {
@ -30,7 +31,7 @@ pub struct GameInner {
players: [Box<dyn Agent>; 2],
board: Board,
do_print: bool,
move_log: Vec<(Option<CoordPair>, Piece)>,
move_log: Vec<(MoveCoord, Piece)>,
first_board: Board,
}

View File

@ -1,6 +1,6 @@
use crate::{
logic::r#move::Move,
repr::{Board, CoordPair, Piece, Winner},
repr::{Board, Piece, Winner},
};
use allocative::Allocative;
use indicatif::{ParallelProgressIterator, ProgressStyle};
@ -15,6 +15,8 @@ use std::{
},
};
use super::r#move::MoveCoord;
#[derive(Allocative)]
pub struct FutureMoves {
/// Arena containing all [`Move`]
@ -354,7 +356,7 @@ impl FutureMoves {
}
}
fn move_history(&self, idx: usize) -> Option<Vec<(Option<CoordPair>, Piece)>> {
fn move_history(&self, idx: usize) -> Option<Vec<(MoveCoord, Piece)>> {
if let Some(root) = self.current_root {
let mut hist = Vec::new();
@ -395,7 +397,7 @@ impl FutureMoves {
}
/// Return the best move which is a child of `self.current_root`
pub fn best_move(&self) -> Option<Option<CoordPair>> {
pub fn best_move(&self) -> Option<MoveCoord> {
self.current_root
.and_then(|x| {
self.arena[x]

View File

@ -2,3 +2,4 @@ mod board_value;
mod future_moves;
mod r#move;
pub use future_moves::{ChildrenEvalMethod, FutureMoveConfig, FutureMoves};
pub use r#move::MoveCoord;

View File

@ -2,10 +2,12 @@ use super::board_value::BoardValueMap;
use crate::repr::{Board, CoordPair, Piece, Winner};
use allocative::Allocative;
pub type MoveCoord = Option<CoordPair>;
#[derive(Clone, Debug, Allocative)]
pub struct Move {
/// Coordinates (i, j) of the move (if it exists)
pub coord: Option<CoordPair>,
pub coord: MoveCoord,
/// Current winner of the match
pub winner: Winner,
@ -34,7 +36,7 @@ pub struct Move {
}
impl Move {
pub fn new(coord: Option<CoordPair>, board: Board, color: Piece, agent_color: Piece) -> Self {
pub fn new(coord: MoveCoord, board: Board, color: Piece, agent_color: Piece) -> Self {
let mut m = Move {
coord,
winner: board.game_winner(),