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

Kytoshogi Bot move API doesn't match with Fairy-Stockfish notation #698

Closed
TheYoBots opened this issue Jun 26, 2023 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@TheYoBots
Copy link

I used the API endpoint /api/bot/game/{gameId}/move/{move} to try an make a move for my Bot.
My Bot gives the error:

                     DEBUG    >> bestmove 5e4e- ponder 2b1c-            usi.py:69
                     INFO     score: {'cp': 268}            engine_wrapper.py:101
                     INFO     depth: 16                     engine_wrapper.py:101
                     INFO     nodes: 1061173                engine_wrapper.py:101
                     INFO     nps: 2491016                  engine_wrapper.py:101
                     DEBUG    POST                                  lishogi.py:79
                              https://lishogi.org/api/bot/game/OnDB              
                              3Ed6/move/5e4e-                                    
 [06/26/23 17:51:17] DEBUG    https://lishogi.org:443 "POST connectionpool.py:546
                              /api/bot/game/OnDB3Ed6/move/5                      
                              e4e- HTTP/1.1" 400 30                              
                     DEBUG    Giving up api_post(...) after 1      _common.py:120
                              tries                                              
                              (requests.exceptions.HTTPError: 400                
                              Client Error: Bad Request for url:                 
                              https://lishogi.org/api/bot/game/OnD               
                              B3Ed6/move/5e4e-)

As shown above Fairy-Stockfish gives the move 5e4e- at the particular position (checked it's a legal move). But Lishogi expects something else to make this move (5e4e+ I'd assume?). Both moves are to be input in the usi format, but lishogi doesn't follow the same notation fairy-stockfish does.

@TheYoBots TheYoBots added the bug Something isn't working label Jun 26, 2023
@WandererXII
Copy link
Owner

WandererXII commented Jun 26, 2023

I forgot to mention this in the blog post. Internally we have promotion as boolean, so introducing demotion (-) as a third possible state into the mix, didn't seem worth it, especially since the +/- notation is just redundant and doesn't make much sense overall.
So I used different notation, I'm converting internally between them when communicating with fairy, but for bots this is rather unfortunate. Sfen and drops are also different btw (rook is just 'R' not '+P', etc.), but converting those is simple.
It's also just not that lishogi won't accept fairy notation, fairy won't like the lishogi one ('+' where it expects '-', etc.). So one needs to convert both ways.
I wrote the conversion in ts and scala. I should probably also write in python, that's gonna be a bit annoying... Fairy to lishogi direction is simple - just replace '-' with '+'. The opposite is trickier, because you need to know what piece is moving (you need to know whether fairy wants it to be promotion or demotion)... I can put something together in python if you want.

@WandererXII
Copy link
Owner

Alternatively I could just convert to the fairy notation and send that to the bots, probably easier to do...

@WandererXII
Copy link
Owner

Is it fine if I add 'fairySfen' and 'fairyMoves' field to the json sent to bots? That will mean that the bots will need to read different json fields with kyotoshogi. I would like to keep exposing the current implementation as main for consistency, since it's showed in various places around the site.
I will also of course make the fairy moves, accepted on the server (bot -> lishogi).

@TheYoBots
Copy link
Author

Is it fine if I add 'fairySfen' and 'fairyMoves' field to the json sent to bots? That will mean that the bots will need to read different json fields with kyotoshogi. I would like to keep exposing the current implementation as main for consistency, since it's showed in various places around the site. I will also of course make the fairy moves, accepted on the server (bot -> lishogi).

Yes, This would be great. Till that is done, could you send me the script you wrote in scala/ts to do this?

@WandererXII
Copy link
Owner

Scala:

TS:

toFairyKyotoFormat(sfen: Sfen, moves: string[]): string {

I will try to have this fixed this week.

@WandererXII
Copy link
Owner

It's live, so it should be fine now. if something doesn't work please let me know. The fairy fields are added only to kyotoshogi responses.

@TheYoBots
Copy link
Author

I'll try it out soon. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants