admin管理员组文章数量:1307740
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
1 Answer
Reset to default 1The 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.
本文标签: Chess FEN in pyton chess and chess jsStack Overflow
版权声明:本文标题:Chess FEN in pyton chess and chess js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741846918a2400833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论