File tree Expand file tree Collapse file tree
app/src/engine/uci_engine Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,15 +24,16 @@ fn is_uci_move(token: &str) -> bool {
2424 if token. len ( ) != 4 && token. len ( ) != 5 {
2525 return false ;
2626 }
27- // First two and next two chars should be file (a-h) and rank (1-8)
27+
2828 let bytes = token. as_bytes ( ) ;
29- if !bytes[ 0 ] . is_ascii_lowercase ( ) || !bytes[ 1 ] . is_ascii_digit ( ) {
29+ if !matches ! ( bytes[ 0 ] , b'a' ..= b'h' ) || !matches ! ( bytes[ 1 ] , b'1' ..= b'8' ) {
3030 return false ;
3131 }
32- if !bytes[ 2 ] . is_ascii_lowercase ( ) || !bytes[ 3 ] . is_ascii_digit ( ) {
32+
33+ if !matches ! ( bytes[ 2 ] , b'a' ..=b'h' ) || !matches ! ( bytes[ 3 ] , b'1' ..=b'8' ) {
3334 return false ;
3435 }
35- // Optional 5th char for promotion (q, r, b, n)
36+
3637 if token. len ( ) == 5 && !matches ! ( bytes[ 4 ] , b'q' | b'r' | b'b' | b'n' ) {
3738 return false ;
3839 }
@@ -924,8 +925,8 @@ mod tests {
924925 #[ test]
925926 fn test_is_uci_move ( ) {
926927 assert ! ( is_uci_move( "e2e4" ) ) ;
927- assert ! ( is_uci_move( "7g7f" ) ) ;
928928 assert ! ( is_uci_move( "e7e8q" ) ) ;
929+ assert ! ( !is_uci_move( "7g7f" ) ) ;
929930 assert ! ( !is_uci_move( "e9e4" ) ) ;
930931 assert ! ( !is_uci_move( "e2e9" ) ) ;
931932 assert ! ( !is_uci_move( "e2e4x" ) ) ;
You can’t perform that action at this time.
0 commit comments