boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10.03k stars 709 forks source link

any bots support customized defined? #843

Closed yangboz closed 3 years ago

yangboz commented 3 years ago

does any bots support AI customized define by python aliked script?

delucis commented 3 years ago

@yangboz Could you provide more detail about what you’re looking for? The framework provides a bot that implements Monte Carlo tree search, but it is Javascript like the rest of the codebase. The Bots section of the tutorial shows how to get it up and running.

yangboz commented 3 years ago

I am trying using MuZero as AI bots's engine ,but the codebase is written with Python, so if possible the boardgame.io's bot compatible with external service?

delucis commented 3 years ago

There’s no out-of-the-box support, but a minimal bot is a class that extends Bot and implements a play method, so you can theoretically integrate with any external service:

import { Bot } from 'boardgame.io/ai';

class CustomBot extends Bot {
  async play({ G, ctx }, playerID) {
    const nextMove = await fetchActionFromService({ G, ctx }, playerID);
    return { action: nextMove };
  }
}

So if you can find a way to dispatch the request to the service — for example a request to a Python server — and parse its response into a boardgame.io action, that could work.

boardgame.io expects play to return an object like:

{
  action: {
    type: 'MAKE_MOVE' || 'GAME_EVENT',
    payload: {
      type: string,
      args: any,
      playerID: string,
    },
  },
}
larry801 commented 3 years ago

If you can deploy a bot separately as a client, please try this. https://github.com/boardgameio/boardgame.io/tree/master/python

delucis commented 3 years ago

I’m going to close this for now as I think it has been answered, but please feel free to re-open it if you have any further questions @yangboz.