KYLChiu / sporkfish

Chess engine in Python
MIT License
5 stars 0 forks source link

[Feature] Lichess bot to accept challenges from other players #38

Closed KYLChiu closed 8 months ago

KYLChiu commented 10 months ago

Requirements:

Tips:

KYLChiu commented 9 months ago

I suggest sticking with multithreading (the history is that before we had load of issues with multiprocessing on Jeremy/Claudia's PC). Additionally there is already a multiprocess implementation at https://github.com/lichess-bot-devs/lichess-bot - but I do not know how this interacts with JIT with numba since we have to freeze our python program into an exe.

The result is going to be slow but given most of the time we play 1 game only it should still be ok: 1) Create a managed bunch of threads to execute tasks (thread pool) 2) Synchronisation method is going to be a queue - we have one thread dedicated to checking the queue, popping tasks off it and running it, Tasks on the queue are all requests (berserk calls) to lichess, because these are rate limited and only one can be fired at a time. 4) Each individual game is also launched as a new thread in the pool as well, and can be launched asynchronously once we get a state to do so

Pros: No multiprocessing, i.e. no pain with different Os'es (yes even with docker) No pain with shared state across processes Maybe more performant when we explore no-GIL python

Cons: Python doesn't like multithreading, i.e. CPU instructions are blocked via GIL - so no progress can be made if awaiting a CPU instruction. Anyway this may be remedied with no-GIL python anyway. But at least we can continue making requests...

@kwngggg @richardhunghhw let me know what you think?