WandererXII / lishogi

☗ lishogi.org: the forever free, adless and open source shogi server forked from lichess.org ☗
https://lishogi.org
GNU Affero General Public License v3.0
271 stars 41 forks source link

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

Closed TheYoBots closed 1 year ago

TheYoBots commented 1 year ago

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.

WandererXII commented 1 year ago

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 commented 1 year ago

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

WandererXII commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Scala: https://github.com/WandererXII/lishogi/blob/140d7a706f4934536bda0a78638e0253e78d7daf/modules/fishnet/src/main/JsonApi.scala#L37

TS: https://github.com/WandererXII/lishogi/blob/140d7a706f4934536bda0a78638e0253e78d7daf/ui/ceval/src/protocol.ts#L213

I will try to have this fixed this week.

WandererXII commented 1 year ago

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 commented 1 year ago

I'll try it out soon. Thanks!