chess SAN castling notation with zeroes '0-0' is unsupported
sprdk4 opened this issue · 8 comments
Currently the server will claim 0-0 and 0-0-0 (using zeroes) are illegal moves for designating castling.
both zeroes '0' and the capital letter 'O' should be acceptable ways to designate castling SAN notation.
The implementation could be as simple as replacing '0-0' and '0-0-0' (zeroes) with 'O-O' and 'O-O-O' on the server side before continuing with validation logic.
I expect AI implementers to google how to implement SAN notation, and the top links for 'chess SAN' either only mention using zeroes, or only mention the alternative of using capital letter 'O' as a sidenote:
https://en.wikipedia.org/wiki/Algebraic_notation_(chess)#Castling
Castling is indicated by the special notations 0-0 (for kingside castling) and 0-0-0 (queenside castling).While the FIDE Handbook, appendix C.13[5] uses the digit zero (0-0 and 0-0-0), PGN requires the uppercase letter O (O-O and O-O-O).
+-----------------+
8 | r n b q k . . r |
7 | p p p p b p p p |
6 | . . . . p n . . |
5 | . . . . . . . . |
4 | . . . . . . . . |
3 | . . . P . N P B |
2 | P P P . P P . P |
1 | R N B Q K . . R |
+-----------------+
a b c d e f g h
Game is over. I lost :( because: Made an invalid move ("0-0").
Interesting edge case.
Just for reference all move are fed through chess.js for all logic related stuff. We've enabled a flag they support called sloppy
that I was hoping would handle cases such as this.
I'll add a quick 0
-> O
conversion for you guys, as you mentioned. However be aware that the moves stored in game.history
will probably always be O
.
I took a look at move_from_san
in chess.js and I'm noticing the logic wouldn't properly handle the notation for enpassant either (e.p.). I'm guessing only the PGN format for SAN notation was referenced when it was implemented
https://en.wikipedia.org/wiki/Algebraic_notation_(chess)#Captures
En passant captures are indicated by specifying the capturing pawn's file of departure, the "x", the destination square (not the square of the captured pawn), and (optionally) the suffix "e.p." indicating the capture was en passant.[2] For example, exd6e.p.
(I've also seen some documentation that puts a space before the e.p.
ex exd6 e.p.
)
Also, I think it won't properly handle '++' notation for designating checkmate, instead of '#'
I would encourage replacing stripped_san
of chess.js to
(untested)
return move.replace(/=/, '').replace(/ ?e.p./,'').replace(/((++?)|(#))?[?!]*$/, '');
I also noticed a comment at line 1115 of chess.js saying SAN 'Rc1c4' is technically invalid. Am I missing something or is that actually a perfectly valid SAN?
+-----------------+
8 | . . . k . K . . |
7 | . . . . . . . . |
6 | . . R . . . . . |
5 | . . . . . . . . |
4 | . . p . R . . . |
3 | . . . . . . . . |
2 | . . . . . . . . |
1 | . . R . . . . . |
+-----------------+
a b c d e f g h
[edit], actually I see now the 'R1c4' is the correct way to represent this.
c1c4
looks valid to me, assuming it is that side's turn. Not sure how moody it will be on the start of that string having an R
or not (I would assume it won't care with sloppy
on). Though I am no chess master.
I seriously doubt there's an error in chess.js
's logic for standard chess games. They are used by a ton of projects, and in my experience literally every time someone thinks chess.js screwed up, they did instead.
In that case, it sounds like only PGN format for SAN notation is intended to be supported, and that it should be better documented to developers that they shouldn't be using FIDE format
Yes that sounds reasonable. If you are in the MST AI class this semester that's probably something the whole class should know so they don't have to fight the SAN formatting, as you've just done, and can focus on coding.
I'm just an alumni that's simply updating my engine with the latest framework to see if anyone can best me.
So if theres any mailing list for this years AI class, I'm not on it.
Ah ok. Chess just started for the students this semester so I've been fielding questions over a variety of platforms about this stuff. Sorry about that :P
Implemented with 7538170
If you or anyone else has any questions about the chess re-work, of any part of the Cadre AI framework feel free to make an issue of ask me :D