最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Chess FEN in pyton chess and chess js - Stack Overflow

programmeradmin0浏览0评论

I wrote my chess openings database using python chess lib and now I'm trying to use it as an api on a website to determine the position name. But python chess and chessjs use different methods to write FEN

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

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

is there any way to convert python FENs to another?

I wrote my chess openings database using python chess lib and now I'm trying to use it as an api on a website to determine the position name. But python chess and chessjs use different methods to write FEN

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

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

is there any way to convert python FENs to another?

Share Improve this question asked Feb 2 at 13:23 EbloEblo 12 bronze badges 1
  • 1 IWelcome to Stack Overflow. Please take the tour to learn how Stack Overflow works and read How to Ask on how to improve the quality of your question. It is unclear what you are asking or what the problem is. Please edit your question to include a more detailed description of the problem you have. – Progman Commented Feb 2 at 13:57
Add a comment  | 

1 Answer 1

Reset to default 1

The only difference that I can see is that Python chess is failing to encode the potential en passant pawn capture move after 1. e4. Python chess is apparently broken in that respect if that is really what it outputs.

Although it is also possible that it is being clever and knows that no black pawn is in a position to exploit the en passant capture so shows "-" instead. You will have to test it to see if this is indeed the case...

This quirk would be much easier to see if you aligned the two strings. viz:

NBG python chess: rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1

correct chess js: rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1

See for example Wiki Forsythe-Edwards notation examples which happens to include the correct encoding of the board before any moves are made and immediately after white's first move of 1. e4

I suggest you fix the code of Python's FEN encoder so that it correctly flags any potential en passant captures after a double pawn move. It is probably broken and without knowing the previous move it is not fixable.

You might want to play the following move sequence and see if it does encode a potential en passant capture move if one of blacks pieces can make it. eg.

 1. e4 c5
 2. Nf3 c4
 3. d4

And save position as FEN which if my hand encoding is OK should give:

 python chess: rnbqkbnr/pp1ppppp/8/8/2pPP3/5N2/PPP2PPP/RNBQKB1R b KQkq d3 0 1

If it still shows "-" then it is most defnitely broken and needs fixing. En passant capture rules cause a lot of obscure bugs in chess engines.

In some compacted FEN databases you sometimes find an odd variant that omits trailing empty square counts on a line and or has escape codes for N repeats of previous character. Terse form looking something like:

chess js: rnbqkbnr/p&///4P//PPPP1P"/RNBQKBNR b KQkq e3 0 1

Obviously without the rule that all rows must sum to 8 you lose the ability to double check the position.

发布评论

评论列表(0)

  1. 暂无评论