kreibaum / pacosako

This code drives the pacoplay.com website where you can play Paco Ŝako.
http://pacoplay.com
MIT License
23 stars 3 forks source link

Allow Online Play against an AI #122

Closed kreibaum closed 5 months ago

kreibaum commented 7 months ago

On PacoPlay you should be able to play against an AI that is running on your local device.

Current plan is to use an ONNX version of Hedwig + something that can execute ONNX in WASM.

I am currently considering https://lib.rs/crates/tract-onnx

Already Failed: Burn (Static ONNX only), ORT (wasm support bad).

Apart from running an ML model, I also want an opening book as well as traditional Ŝako analysis in the engine.

kreibaum commented 6 months ago

Tract failed, it is super slow when running in the browser.

With 4d4c6474ae57e14f7a8e0ef0a54e5096a59547ec we now have onnxruntime-web (that I called ORT earlier) and I'll just have to accept that there is an extra boundary between rust/wasm and the onnx runtime. I get good times running a Hedwig model in the browser.

Quantization to UInt8 also works great, the model is much smaller and appears to run a bit faster.

kreibaum commented 6 months ago

Here are some thoughts on how to change the client -> server interface, but it looks like that information is really hard to get right now.

/// An extension of the current match state that contains the player metadata.
/// Only this one is actually serializable, to make sure we don't send the
/// data object missing this metadata to the client.
#[derive(Serialize, Clone, Debug)]
pub struct CurrentMatchStateClient {
    key: String,
    actions: Vec<StampedAction>,
    pub controlling_player: pacosako::PlayerColor,
    pub timer: Option<Timer>,
    pub victory_state: pacosako::VictoryState,
    pub setup_options: SetupOptions,
    pub white_player: Option<PublicUserData>,
    pub black_player: Option<PublicUserData>,
    /// We need to communicate to the client which pieces they move and if they
    /// need to run the AI as well.
    /// We just tell them which sides they control, and if they control a player
    /// that is marked as AI, they'll need to run the AI.
    /// We don't send a "this is what you need to do now" state, as then the
    /// client would need to wait for a ping to the server before starting the
    /// AI. This way the client can start the AI immediately.
    pub your_colors: Vec<pacosako::PlayerColor>,
}
kreibaum commented 5 months ago

Works now, any improvements get extra tickets.