Parse UCI and FEN moves
This commit is contained in:
parent
749bef8f78
commit
3725457134
@ -2,6 +2,7 @@ use colored::Colorize;
|
||||
use shakmaty::san::ParseSanError;
|
||||
use shakmaty::san::San;
|
||||
use shakmaty::san::SanError;
|
||||
use shakmaty::uci::Uci;
|
||||
use shakmaty::{Chess, Color, IllegalMoveError, Position, Setup, Square};
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
@ -168,8 +169,11 @@ fn board_string_representation(chess: &Chess, side: Color) -> Vec<Vec<SquareToPr
|
||||
}
|
||||
|
||||
pub fn try_to_play_move(chess: &Chess, movestr: String) -> Result<Chess, MoveInputError> {
|
||||
let san: San = movestr.parse()?;
|
||||
let mv = san.to_move(chess)?;
|
||||
//if uci parse error, try to parse with san.
|
||||
let mv = match movestr.parse::<Uci>() {
|
||||
Ok(uci) => uci.to_move(chess)?,
|
||||
Err(_) => movestr.parse::<San>()?.to_move(chess)?,
|
||||
};
|
||||
Ok((*chess).clone().play(&mv)?)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user