Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

En passant target squares not properly generated in FEN EPD #88

Closed
B1tWhys opened this issue Aug 6, 2022 · 2 comments
Closed

En passant target squares not properly generated in FEN EPD #88

B1tWhys opened this issue Aug 6, 2022 · 2 comments

Comments

@B1tWhys
Copy link

B1tWhys commented Aug 6, 2022

Hello,

Thanks for writing this library, it's extremely useful! The only thing I'm having trouble with is that it doesn't seem like en passant target squares are correctly handled by the FEN generation code. Here's an example:

import {Chess} from "chessops/chess";
import {makeFen} from "chessops/fen";
import {parseSan} from "chessops/san";

describe("When generating FEN", () => {
    test("en passant target square is in EPD", () => {
        const chess = Chess.default();
        chess.play(parseSan(chess, "a4"));
        expect(makeFen(chess.toSetup())).toBe("rnbqkbnr/pppppppp/8/8/P7/8/1PPPPPPP/RNBQKBNR b KQkq a3 0 1");
    });
}

which fails with:

Error: expect(received).toBe(expected) // Object.is equality

Expected: "rnbqkbnr/pppppppp/8/8/P7/8/1PPPPPPP/RNBQKBNR b KQkq a3 0 1"
Received: "rnbqkbnr/pppppppp/8/8/P7/8/1PPPPPPP/RNBQKBNR b KQkq - 0 1"
@niklasf
Copy link
Owner

niklasf commented Aug 6, 2022

Hi, like on Lichess and similar to X-FEN, the en passant square is only included if there is actually a legal en passant move. If you really need it, you can force it as follows:

const setup = chess.toSetup();
setup.epSquare = chess.epSquare;
makeFen(chess.toSetup())

@B1tWhys
Copy link
Author

B1tWhys commented Aug 6, 2022

Oh, that makes sense & is completely fine for my needs; I just need to adjust some of my my test cases a little. Thanks for the very fast response (and wonderful library)!

@B1tWhys B1tWhys closed this as completed Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants