diff options
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r-- | src/board/mod.rs | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs index 06b61bb..8f5fbde 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -1,3 +1,5 @@ +use std::io::{stdin, stdout, Write}; + use rand::{rngs::StdRng,SeedableRng,Rng}; use crate::{bitboard::{Bitboard, serialize_bitboard, bitscan, pop_count}, moves::{Move, MoveKind}, attacks::Attacks, square::Square}; @@ -31,7 +33,6 @@ pub struct Board { attacks: Attacks, } - #[derive(Debug, Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)] #[repr(usize)] pub enum PieceType { @@ -58,11 +59,11 @@ impl PieceType { // Return the price of the peice pub fn static_eval(&self) -> f32 { match self.without_color() { - PieceType::Pawn => 1., - PieceType::Bishop => 3., - PieceType::Knight => 3., - PieceType::Rook => 4.5, - PieceType::Queen => 9., + PieceType::Pawn => 1.0, + PieceType::Bishop => 3.3, + PieceType::Knight => 3.2, + PieceType::Rook => 5.0, + PieceType::Queen => 9.0, PieceType::King => 0., _ => panic!("Piece should be without color"), } @@ -146,6 +147,32 @@ impl Board { Self::from_FEN(default_fen) } + pub fn read_move(&self) -> Result<Move, String> { + print!("\nEnter a move: "); + stdout().flush().unwrap(); + let mut s = String::new(); + stdin().read_line(&mut s).unwrap(); + let chars = &mut s.chars(); + + let source = match Square::from_notation(chars) { + Ok(s) => s, + Err(e) => return Err(e), + }; + let target = match Square::from_notation(chars) { + Ok(s) => s, + Err(e) => return Err(e), + }; + + 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 => return Err(String::from("Move is not valid")), + }; + + Ok(mov) + } + /// Color to move at this ply pub fn color(&self) -> Color { Color::from(self.ply as u8 % 2) @@ -493,7 +520,8 @@ impl Board { } PieceType::Queen => { for source in serialize_bitboard(*piece) { - mobility += pop_count(self.attacks.queen(self.occupancy, source) & (empty | opponent_occupancy)) as f32; + // Scale down mobility because we don't want our queen to be rushing too much + mobility += pop_count(self.attacks.queen(self.occupancy, source) & (empty | opponent_occupancy)) as f32 / 3.0; } } incorrect_type => panic!("Incorrect piece type: {:?}", incorrect_type), |