diff options
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/mod.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs index 06b61bb..ce8c076 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -1,3 +1,5 @@ +use std::io::stdin; + use rand::{rngs::StdRng,SeedableRng,Rng}; use crate::{bitboard::{Bitboard, serialize_bitboard, bitscan, pop_count}, moves::{Move, MoveKind}, attacks::Attacks, square::Square}; @@ -146,6 +148,22 @@ impl Board { Self::from_FEN(default_fen) } + pub fn read_move(&self) -> Move { + let mut s = String::new(); + stdin().read_line(&mut s).unwrap(); + let chars = &mut s.chars(); + let source = Square::from_notation(chars); + let target = Square::from_notation(chars); + + let moves = self.generate_pseudolegal_moves(self.color()); + + let mov = match moves.iter().find(|m| m.source == source && m.target == target) { + Some(m) => *m, + None => panic!("Move is not valid"), + }; + mov + } + /// Color to move at this ply pub fn color(&self) -> Color { Color::from(self.ply as u8 % 2) |