switch coordinates to global 'Coord' type

This commit is contained in:
2025-02-26 23:45:58 -05:00
parent a10b762b39
commit 7ec8a66a4e
10 changed files with 63 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
use crate::repr::{Board, Piece};
use crate::repr::{Board, Coord, Piece};
use rand::prelude::*;
use std::io;
use std::io::prelude::*;
@@ -6,7 +6,7 @@ use std::io::prelude::*;
#[allow(dead_code)]
pub trait Agent {
/// Returns the move of an [`Agent`]
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)>;
fn next_move(&mut self, board: &Board) -> Option<(Coord, Coord)>;
/// Returns the name of the [`Agent`]
fn name(&self) -> &'static str;
/// Returns the color the [`Agent`] is playing
@@ -27,7 +27,7 @@ impl ManualAgent {
#[allow(dead_code)]
impl Agent for ManualAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
fn next_move(&mut self, board: &Board) -> Option<(Coord, Coord)> {
let stdin = io::stdin();
let mut input = String::new();
println!("Your turn! ('Skip' to skip)");
@@ -44,7 +44,7 @@ impl Agent for ManualAgent {
.map(str::parse)
.map(Result::ok)
.collect::<Option<Vec<_>>>()
.and_then(|x| -> Option<[usize; 2]> { x.try_into().ok() })
.and_then(|x| -> Option<[Coord; 2]> { x.try_into().ok() })
.map(|x| (x[0], x[1]));
if let Some(got) = got {
@@ -73,7 +73,7 @@ pub struct RandomAgent {
#[allow(dead_code)]
impl Agent for RandomAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
fn next_move(&mut self, board: &Board) -> Option<(Coord, Coord)> {
board.possible_moves(self.color).choose(&mut rand::rng())
}