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,
|
color: Piece,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Agent {
|
impl Agent for AutoAgent {
|
||||||
pub const fn new(color: Piece) -> Self {
|
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
|
||||||
Self { color }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_move() -> (usize, usize) {
|
|
||||||
todo!("next_move not implemented")
|
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 agent;
|
||||||
|
mod game;
|
||||||
mod repr;
|
mod repr;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
11
src/repr.rs
11
src/repr.rs
@ -4,6 +4,15 @@ pub enum Piece {
|
|||||||
White,
|
White,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Piece {
|
||||||
|
pub const fn flip(&self) -> Self {
|
||||||
|
match self {
|
||||||
|
Piece::Black => Piece::White,
|
||||||
|
Piece::White => Piece::Black,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const BOARD_SIZE: usize = 8;
|
const BOARD_SIZE: usize = 8;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -116,6 +125,8 @@ impl Board {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
// TODO! add tests for double prop
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn place_and_get() {
|
fn place_and_get() {
|
||||||
let mut board = Board::new();
|
let mut board = Board::new();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user