niklasf/chessops

New issue on capture with SAN format

andrescavallin opened this issue · 3 comments

Hello!!!

I think there is still a bug when capturing pawns using SAN format.
So this happened on a real game played with the DGT Board. I tested also with this code on latest chessops (v.0.7.2)
Here is a sample code to reproduce the issue:

Basically on the position on the sample, when the move "bxc6" is played, it returns an undefined object.
If the same move is played using UCI then it works fine.

// https://lichess.org/editor/r4br1/pp1Npkp1/2P4p/5P2/6P1/5KnP/PP6/R1B5_b_-_-_0_1
import { parseFen } from 'chessops/fen';
import { Chess } from 'chessops/chess';
import { board } from 'chessops/debug';
import { NormalMove, parseUci } from 'chessops';
import { parseSan } from 'chessops/san';

const setup = parseFen('r4br1/pp1Npkp1/2P4p/5P2/6P1/5KnP/PP6/R1B5 b - - 0 1').unwrap();
const localBoard = Chess.fromSetup(setup).unwrap();
console.log(board(localBoard.board));
var nextMove = 'bxc6';
//var nextMove = 'b6';
var moveObject: NormalMove | undefined;
moveObject = <NormalMove>parseSan(localBoard, nextMove);

if (moveObject !== undefined) {
    //This never happens
    console.log('moveObj looks good');
}
else {
    //Now try the uci version
    console.log('moveObj is undefined');
    console.log('bxc6 was invalid lets try with b7c6 \n')
    moveObject = <NormalMove>parseUci('b7c6');    
}

localBoard.play(moveObject);
console.log(board(localBoard.board));

Output

r . . . . b r .
p p . N p k p .
. . P . . . . p
. . . . . P . .
. . . . . . P .
. . . . . K n P
P P . . . . . .
R . B . . . . .

moveObj is undefined
bxc6 was invalid lets try with b7c6

r . . . . b r .
p . . N p k p .
. . p . . . . p
. . . . . P . .
. . . . . . P .
. . . . . K n P
P P . . . . . .
R . B . . . . .

If nextMove value is set to "b6" then moveObjt looks good and works fine. So I think is something with the capture.

Thanks. You can probably tell you're the first to extensively use this part of the library, so these reports are very valuable.

For bxc6, the parser was looking for a bishop 🤦. Fixed by requiring uppercase letters for pieces, e.g., Bxc6 if it really is intended to be a bishop move.

Published in v0.7.3.

No problem my friend, thanks for all your great effort and for fixing this.