aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-26 21:42:36 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-26 21:42:36 +0300
commit54e72754d0fae2b2768b66c39c72e9afaba0cba8 (patch)
treef563104d3dabb5a8782a803e8b951399484f930e
parentef9156656c752c6e1bd52f8b0c77bd101e464f7b (diff)
downloadchessnost-54e72754d0fae2b2768b66c39c72e9afaba0cba8.tar.gz
fix: validate moves provided by UCI
-rw-r--r--src/grossmeister/UCI.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/grossmeister/UCI.rs b/src/grossmeister/UCI.rs
index cd00ad7..d5e67a1 100644
--- a/src/grossmeister/UCI.rs
+++ b/src/grossmeister/UCI.rs
@@ -52,10 +52,15 @@ impl Grossmeister {
if let Some(token) = tokens.next() {
if token == "moves" {
for token in tokens.by_ref() {
- let mov = Move::from_notation(token.chars());
- self.board.make_move(mov);
- println!("{:?}", mov);
- self.board.print();
+ let input_move = Move::from_notation(token.chars());
+ let moves = self.board.generate_pseudolegal_moves();
+ if let Some(mov) = moves
+ .iter()
+ .find(|m| m.source == input_move.source && m.target == input_move.target) {
+ self.board.make_move(*mov);
+ } else {
+ panic!("Illegal move: {}", input_move);
+ }
}
} else {
panic!("Unexpected token: {}. CMD: {}", token, cmd);
@@ -69,9 +74,7 @@ impl Grossmeister {
self.board = Board::from_FEN(fen.to_string());
};
}
- _ => {
- todo!("Parse FEN")
- }
+ _ => {}
}
} else {
todo!("Decide what to do when position is now provided")