keeshii / ryuu-play

Simulator for the Pokémon Trading Card Game
https://ptcg.ryuu.eu
MIT License
52 stars 13 forks source link

About Python API #2

Open gemelom opened 1 month ago

gemelom commented 1 month ago

Hi there! Is it possible to write a python API to receive state information and interact with local server? For AI bots training by machine learning, it will be very nice to have an encapsulated environment in python to interact with, like those in gym.

keeshii commented 1 month ago

Honestly, it will be difficult to write any AI in python. The game-state in PTCG is quite unusual. There can be a moment when it is stable (the player can play any card from his hand, retreat, etc.), but it can also be intermediate, e.g. the player has played a Poke-ball and now he has to choose a Pokemon card from the deck and until then, any other action is prohibited. AI must be smart enough to know which operations are allowed at a given moment, because, after approximately 10 incorrect actions in a row, the server kicks the player from the room. The package "ptcg-server" containts a simulator that can check, if an action is valid, but it is written in JS. Reimplementing it to Python will be like rewriting the whole project from the scratch.

And in addition, there is also a "state-sanitizer", which removes secret information from the game-state before sending to the user - what are the Prize cards, what has opponent in his hand, etc.

Actually all communication is based on HTTP requests and websocket. In theory it should be possible to implement a client, that handles authentication, responds to game invites and plays the game. Of course it will require lots of work and I don't think it's worth the effort.

I'm no longer actively involved in this project and don't intend to implement anything, but I can answer your question if needed.