jhlywa/chess.js

En passant square handled differently between move() and pgn() methods

JeffML opened this issue · 3 comments

JeffML commented

If loading the pgn "1. e4", then the FEN output is:

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1

but if moving e4, an en passant square is generated in the FEN:

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1

Technically, both are correct, even if e3 can't be played in response, but it would be preferable to only generate an en passant move if it is a legal move.

version: 1.0.0-beta.6

jhlywa commented

Hi @JeffML and thanks for the report. I'm unable to reproduce using the latest from npm:

import { Chess } from 'chess.js'

const chess = new Chess()
chess.loadPgn('1. e4')
console.log(chess.fen())
// -> rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1

chess.reset()
chess.move('e4')
console.log(chess.fen())
// -> rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1

The FEN export only contains an en passant square if en passant is a legal move for the side to move. Are you using the put() method for any piece placement? That code is relatively new and alters the en passant square in certain conditions.

JeffML commented
JeffML commented

Well, I upgraded chess.js in come directory somewhere, but not in the project directory I had intended, so that was still on the alpha version. Bumping it to beta (and double checking the version in yarn), the en passant issue went away...so, closing due to user error.