uci: use new Move struct
This commit is contained in:
parent
e4d2b20e23
commit
91e1fbbe21
|
@ -10,7 +10,7 @@ const START_WH_K_POS: Square = E1;
|
||||||
const START_BL_K_POS: Square = E8;
|
const START_BL_K_POS: Square = E8;
|
||||||
|
|
||||||
/// A movement, with before/after positions and optional promotion.
|
/// A movement, with before/after positions and optional promotion.
|
||||||
#[derive(PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct Move {
|
pub struct Move {
|
||||||
pub source: Square,
|
pub source: Square,
|
||||||
pub dest: Square,
|
pub dest: Square,
|
||||||
|
@ -23,7 +23,8 @@ impl fmt::Debug for Move {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SAN_NULL_MOVE: &str = "0000";
|
/// Null move string in UCI exchanges.
|
||||||
|
pub const UCI_NULL_MOVE_STR: &str = "0000";
|
||||||
|
|
||||||
impl Move {
|
impl Move {
|
||||||
/// Build a move from `source` to `dest`, no promotion.
|
/// Build a move from `source` to `dest`, no promotion.
|
||||||
|
|
21
src/uci.rs
21
src/uci.rs
|
@ -7,8 +7,8 @@ use std::thread;
|
||||||
|
|
||||||
use crate::analysis::AnalysisInfo;
|
use crate::analysis::AnalysisInfo;
|
||||||
use crate::engine;
|
use crate::engine;
|
||||||
use crate::movement::Move;
|
use crate::fen;
|
||||||
use crate::notation;
|
use crate::movement::{Move, UCI_NULL_MOVE_STR};
|
||||||
|
|
||||||
const VATU_NAME: &str = env!("CARGO_PKG_NAME");
|
const VATU_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
const VATU_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
const VATU_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
||||||
|
@ -64,7 +64,7 @@ pub enum UciCmd {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum PositionArgs {
|
pub enum PositionArgs {
|
||||||
Startpos,
|
Startpos,
|
||||||
Fen(notation::Fen),
|
Fen(fen::Fen),
|
||||||
Moves(Vec<Move>),
|
Moves(Vec<Move>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ impl Uci {
|
||||||
s.push_str(&format!(" nps {}", n));
|
s.push_str(&format!(" nps {}", n));
|
||||||
}
|
}
|
||||||
AnalysisInfo::CurrentMove(m) => {
|
AnalysisInfo::CurrentMove(m) => {
|
||||||
s.push_str(&format!(" currmove {}", notation::move_to_string(m)));
|
s.push_str(&format!(" currmove {}", m.to_uci_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,11 +280,10 @@ impl Uci {
|
||||||
|
|
||||||
/// Send best move.
|
/// Send best move.
|
||||||
fn send_bestmove(&mut self, m: &Option<Move>) {
|
fn send_bestmove(&mut self, m: &Option<Move>) {
|
||||||
let move_str = match m {
|
self.send(&format!(
|
||||||
Some(m) => notation::move_to_string(m),
|
"bestmove {}",
|
||||||
None => notation::NULL_MOVE.to_string(),
|
if let Some(m) = m { &m.to_uci_string() } else { UCI_NULL_MOVE_STR }
|
||||||
};
|
));
|
||||||
self.send(&format!("bestmove {}", move_str));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +318,7 @@ fn parse_position_command(fields: &[&str]) -> UciCmd {
|
||||||
match fields[i] {
|
match fields[i] {
|
||||||
// Subcommand "fen" is followed by a FEN string.
|
// Subcommand "fen" is followed by a FEN string.
|
||||||
"fen" => {
|
"fen" => {
|
||||||
if let Some(fen) = notation::parse_fen_fields(&fields[i + 1 .. i + 7]) {
|
if let Some(fen) = fen::parse_fen_fields(&fields[i + 1 .. i + 7]) {
|
||||||
subcommands.push(PositionArgs::Fen(fen))
|
subcommands.push(PositionArgs::Fen(fen))
|
||||||
} else {
|
} else {
|
||||||
return UciCmd::Unknown(format!("Bad format for position fen"))
|
return UciCmd::Unknown(format!("Bad format for position fen"))
|
||||||
|
@ -332,7 +331,7 @@ fn parse_position_command(fields: &[&str]) -> UciCmd {
|
||||||
"moves" => {
|
"moves" => {
|
||||||
let mut moves = vec!();
|
let mut moves = vec!();
|
||||||
while i + 1 < num_fields {
|
while i + 1 < num_fields {
|
||||||
moves.push(notation::parse_move(fields[i + 1]));
|
moves.push(Move::from_uci_string(fields[i + 1]));
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
subcommands.push(PositionArgs::Moves(moves));
|
subcommands.push(PositionArgs::Moves(moves));
|
||||||
|
|
Reference in a new issue