This commit is contained in:
Simon Gardling 2025-01-26 00:44:19 -05:00
parent 283158b00f
commit ad551391b2
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
4 changed files with 52 additions and 8 deletions

View File

@ -1,15 +1,41 @@
use crate::repr::Piece;
use std::collections::VecDeque;
pub struct Agent {
use crate::repr::{Board, Piece};
pub trait Agent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)>;
}
pub struct ManualAgent {}
impl Agent for ManualAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
todo!("user input not implemented")
}
}
pub struct QueueAgent {
moves: VecDeque<(usize, usize)>,
}
impl Agent for QueueAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
self.moves.pop_front()
}
}
pub struct AutoAgent {
color: Piece,
}
impl Agent {
pub const fn new(color: Piece) -> Self {
Self { color }
}
pub fn next_move() -> (usize, usize) {
impl Agent for AutoAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
todo!("next_move not implemented")
}
}
impl AutoAgent {
pub const fn new(color: Piece) -> Self {
Self { color }
}
}

6
src/game.rs Normal file
View File

@ -0,0 +1,6 @@
use crate::{agent::Agent, repr::Board};
pub struct Game {
players: [Box<dyn Agent>; 2],
board: Board,
}

View File

@ -1,4 +1,5 @@
mod agent;
mod game;
mod repr;
fn main() {

View File

@ -4,6 +4,15 @@ pub enum Piece {
White,
}
impl Piece {
pub const fn flip(&self) -> Self {
match self {
Piece::Black => Piece::White,
Piece::White => Piece::Black,
}
}
}
const BOARD_SIZE: usize = 8;
#[derive(Copy, Clone)]
@ -116,6 +125,8 @@ impl Board {
mod test {
use super::*;
// TODO! add tests for double prop
#[test]
fn place_and_get() {
let mut board = Board::new();