diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-08-22 02:59:20 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-08-22 05:56:11 +0300 |
commit | a3bef6f93a960ad51d7601ed8e53c6a83a532f71 (patch) | |
tree | fffffe84df9c1e4903ccf0fd48db099758078a60 /src/grossmeister/UCI.rs | |
parent | bc599d145a8d3a5e69128bc9e702ac7a32d73a4c (diff) | |
download | chessnost-a3bef6f93a960ad51d7601ed8e53c6a83a532f71.tar.gz |
feat: improve UCI position fen moves case
Diffstat (limited to 'src/grossmeister/UCI.rs')
-rw-r--r-- | src/grossmeister/UCI.rs | 68 |
1 files changed, 28 insertions, 40 deletions
diff --git a/src/grossmeister/UCI.rs b/src/grossmeister/UCI.rs index e10088a..1bd5f92 100644 --- a/src/grossmeister/UCI.rs +++ b/src/grossmeister/UCI.rs @@ -44,49 +44,37 @@ impl Grossmeister { *self = Self::default() } "position" => { - if let Some(token) = tokens.next() { - match token { - "startpos" => { - self.board = Board::new(); - - if let Some(token) = tokens.next() { - if token == "moves" { - for token in tokens.by_ref() { - let input_move = Move::from_notation(token.chars()); - let moves = self.board.generate_pseudolegal_moves(); - if let Some(mov) = moves - .iter() - .find(|m| { - let promo_matches = match input_move.kind { - MoveKind::Promotion(piece) => match m.kind { - MoveKind::Promotion(another_piece) => piece.without_color() == another_piece.without_color(), - _ => false - }, - _ => true, - }; - promo_matches && m.source == input_move.source && m.target == input_move.target - }) { - self.board.make_move(*mov); - } else { - panic!("Illegal move: {}", input_move); - } - } + match tokens.next() { + Some("startpos") => { + self.board = Board::new(); + } + Some("fen") => { + let fen = (0..6).filter_map(|_| tokens.next()).collect::<Vec<_>>().join(" "); + self.board = Board::from_FEN(fen.to_string()); + } + _ => panic!("Expected position"), + } + if let Some("moves") = tokens.next() { + for token in tokens.by_ref() { + let input_move = Move::from_notation(token.chars()); + let moves = self.board.generate_pseudolegal_moves(); + if let Some(mov) = moves + .iter() + .find(|m| { + let promo_matches = match input_move.kind { + MoveKind::Promotion(piece) => match m.kind { + MoveKind::Promotion(another_piece) => piece.without_color() == another_piece.without_color(), + _ => false + }, + _ => true, + }; + promo_matches && m.source == input_move.source && m.target == input_move.target + }) { + self.board.make_move(*mov); } else { - panic!("Unexpected token: {}. CMD: {}", token, cmd); + panic!("Illegal move: {}", input_move); } - } - } - "fen" => { - // TODO: handle "moves" command after "fen"? - let index = "position fen".len() + 1; - if let Some(fen) = cmd.get(index..) { - self.board = Board::from_FEN(fen.to_string()); - }; - } - _ => {} } - } else { - todo!("Decide what to do when position is now provided") } } "go" => { |