lichess-org/fishnet

RFC: Would you accept a patch to support more of the FairyStockfish Variants?

lakinwecker opened this issue · 9 comments

Currently the first (only?) thing that's preventing other FairyStockfish supported variants from being supported by fishnet is the use of Shakmaty to validate incoming positions which doesn't support all of those variants.

I'm not sure what the "right" way is to support more of the FairyStockfish variants, but maybe it's a system of actually using FairyStockfish to validate the incoming position rather than using Shakmaty. Would you accept a patch to this effect?

Yes, possibly, if FairyStockfish can safely do this.

Internally, it has a validateFen method which can be used, but I assume that fishnet only treats it as an executable binary blob?

Correct. It bundles several executables, extracts the best executable for the CPU into a temporary directory, and starts multiple instances as subprocesses.

That may make it harder. Will look at it

Before I go too far down this road, I'm having to make a Rust wrapper for a C++ wrapper for FairyStockfish. The C++ wrapper is simply exposing a more "library" like interface for interacting with things like its validateFen method. The C++ wrapper will need to be improved (to expose things like UCI/FEN parsing/verification) and then I'll expose that in a nice rust-like library using the cxx crate.

It's more complicated than I expected, so I thought I would confirm that you will still consider this? For full disclosure, I have to do this anyways to be able to use fishnet as part of playstrategy.org with non-lichess variants. So it's likely I will be doing this regardless of whether the patch is accepted, but I would prefer to not diverge too much from upstream (this repo)

fishnet needs chess logic only for these things:

  • To normalize castling notation like e1g1 to e1h1 (UCI_Chess960 notation).
  • To guarantee memory safety (e.g. no engine crashes). This includes detecting standard chess positions with material too exotic to be handled by official Stockfish.

If Fairy-Stockfish could guarantee to accept standard castling notation even when it is in Chess960 mode, and if it could guarantee not to crash on illegal positions or moves, then fishnet wouldn't need any chess logic or bindings (except for standard chess, to protect official Stockfish). It would then almost be a simplification for fishnet, and naturally support all of Fairy-Stockfish's variants.

You also use shakmaty to parse UCI (and restrict it to 8x8 boards), while fairystockfish supports larger board variants (like shogi/xiangqi, among others). So UCI parsing would need to be updated, but this is pretty simple, so I'm not too worried about this.

Yeah. Also that is only needed to normalize and validate, which maybe Fairy-Stockfish will not need. Other than that, the sequence of moves can just be passed verbatim.

Continuing discussion in #224.