Implement basic frontend-engine interaction

Use a Flask-based Python server as an adapter to the engine's
stdin-stdout inferface.
This commit is contained in:
2021-12-11 14:58:16 +01:00
parent 57931b29de
commit b5c252bd4d
4 changed files with 80 additions and 38 deletions

View File

@@ -224,15 +224,17 @@ impl Board {
};
}
pub fn new() -> Board {
let mut board = Board {
Board {
state: Default::default(),
};
}
}
pub fn reset(&mut self) {
self.state.clear();
for piece_type in &[PieceType::Pawn] {
for (piece, position) in piece_type.initial_setup() {
board.set_at(position, Some(piece));
self.set_at(position, Some(piece));
}
}
board
}
pub fn iter(&self) -> impl Iterator<Item = (&Position, &Piece)> {
self.state.iter()

View File

@@ -1,7 +1,19 @@
use std::io::BufRead;
mod board;
mod ui;
fn main() {
let board = board::Board::new();
println!("{}", board.to_string());
fn main() -> Result<(), ()> {
let mut board = board::Board::new();
board.reset();
let stdin = std::io::stdin();
let mut input_lines = stdin.lock().lines();
loop {
match input_lines.next() {
None => break Ok(()),
Some(line) => match &line.unwrap()[..] {
"get_state" => println!("{}", board.to_string()),
_ => break Err(()),
},
}
}
}