stuff
This commit is contained in:
parent
283158b00f
commit
ad551391b2
42
src/agent.rs
42
src/agent.rs
@ -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
6
src/game.rs
Normal file
@ -0,0 +1,6 @@
|
||||
use crate::{agent::Agent, repr::Board};
|
||||
|
||||
pub struct Game {
|
||||
players: [Box<dyn Agent>; 2],
|
||||
board: Board,
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
mod agent;
|
||||
mod game;
|
||||
mod repr;
|
||||
|
||||
fn main() {
|
||||
|
||||
11
src/repr.rs
11
src/repr.rs
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user