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:
@@ -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()
|
||||
|
||||
@@ -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(()),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user