Parse UCI and FEN moves

This commit is contained in:
Artlef 2020-03-07 13:07:55 +01:00
parent 749bef8f78
commit 3725457134

View File

@ -2,6 +2,7 @@ use colored::Colorize;
use shakmaty::san::ParseSanError; use shakmaty::san::ParseSanError;
use shakmaty::san::San; use shakmaty::san::San;
use shakmaty::san::SanError; use shakmaty::san::SanError;
use shakmaty::uci::Uci;
use shakmaty::{Chess, Color, IllegalMoveError, Position, Setup, Square}; use shakmaty::{Chess, Color, IllegalMoveError, Position, Setup, Square};
use std::fmt; use std::fmt;
use std::io; 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> { pub fn try_to_play_move(chess: &Chess, movestr: String) -> Result<Chess, MoveInputError> {
let san: San = movestr.parse()?; //if uci parse error, try to parse with san.
let mv = san.to_move(chess)?; let mv = match movestr.parse::<Uci>() {
Ok(uci) => uci.to_move(chess)?,
Err(_) => movestr.parse::<San>()?.to_move(chess)?,
};
Ok((*chess).clone().play(&mv)?) Ok((*chess).clone().play(&mv)?)
} }