pydraughts, a draughts library in Python

Discussion about development of draughts in the time of computer and Internet.
Post Reply
AttackingOrDefending
Posts: 4
Joined: Sun Apr 17, 2022 08:03
Real name: Ioannis Pantidis

pydraughts, a draughts library in Python

Post by AttackingOrDefending » Sun Dec 03, 2023 21:30

Hello,

I have created a library for draughts in Python called pydraughts (https://github.com/AttackingOrDefending/pydraughts). It was originally created to create bots on lidraughts (https://lidraughts.org/player/bots). In June, I added a tournament manager which would allow for the automation of draughts tournaments. While I don't have that much free time at the moment, I was looking for some feedback on what I need to work on next.

Features:
  • Variants:
    • International
      Russian
      Brazilian
      English/American
      Italian
      Turkish
      Frisian
      frysk!
      Antidraughts
      Breakthrough
    Engine protocols:
    • Hub
      DXP
      CheckerBoard
    PDN Reading and Writing
    Ballots
    Tournaments

BertTuyt
Posts: 1592
Joined: Wed Sep 01, 2004 19:42

Re: pydraughts, a draughts library in Python

Post by BertTuyt » Tue Dec 05, 2023 16:11

Thanks for sharing.

I have basically 2 questions , in your github example you have a tournament with 2 players, are more players also possible (and in that case) are engines switched on and off automatically.

And last but not least what we would like to see; a tournament with multiple engines which run an a local computer, but where the game in progress, games played so far, and tournament scores so far can be live seen on LiDraughts. So really automatically, so that one does not need to manually operate all constantly during the tournament.

Bert

AttackingOrDefending
Posts: 4
Joined: Sun Apr 17, 2022 08:03
Real name: Ioannis Pantidis

Re: pydraughts, a draughts library in Python

Post by AttackingOrDefending » Wed Dec 06, 2023 18:16

You can tournaments with more than 2 engines. I have tested with up to 3 engines (scan dxp, kr hub, mobydam dxp) and it worked correctly. I couldn't find more engines to test it, but there shouldn't be any issue with more engines.

Lidraughts doesn't support user-created broadcasts and doesn't have an API for them, like lichess. I sent a message to RoepStoep requesting the addition of a broadcast API but I haven't gotten a reply yet. Playstrategy (https://playstrategy.org), which is also based on lichess, supports broadcasts and has draughts, so this is probably a better choice even though it's less popular.

gwiesenekker
Posts: 21
Joined: Sun Feb 20, 2011 21:04
Real name: Gijsbert Wiesenekker

Re: pydraughts, a draughts library in Python

Post by gwiesenekker » Thu Feb 08, 2024 15:20

Hi,

Thank you! At least for GWD (but I guess also for other engines) it is required it is launched from the directory they are installed in so they can find configuration files etc. By inspecting the source code this is supported for the HubEngine command through the 'cwd' argument:

from draughts.engine import HubEngine, Limit
engine=HubEngine(["C:/Tmp2/GWD7/x64/Release-AVX2/GWD7.exe", ""],cwd="C:/Tmp2/GWD7/x64/Release-AVX2")

But as far as I can see this is not supported for tournament play. I modified lines 60 of tournament.py as follows to launch the engine from the directory it is installed in:

#print(command, os.path.dirname(command[0]))
engine = HubEngine(command, cwd = os.path.dirname(command[0]))

I can then have play GWD against itself as:

from draughts.tournament import RoundRobin
player1 = (["C:/Tmp2/GWD7/x64/Release-AVX2/GWD7.exe", ""], "hub", {})
player2 = (["C:/Tmp2/GWD7/x64/Opponent/GWD7.exe", ""], "hub", {})
players = [player1, player2]
tournament = RoundRobin("tournament.pdn", players, start_time=20, increment=0.2, games_per_pair=4)
scores = tournament.play()
print(scores)

Could you also add 'cwd' support for tournament play?

Thanks,
GW

AttackingOrDefending
Posts: 4
Joined: Sun Apr 17, 2022 08:03
Real name: Ioannis Pantidis

Re: pydraughts, a draughts library in Python

Post by AttackingOrDefending » Thu Feb 15, 2024 18:35

Hi,

I just released a new version with the change you requested. Let me know if you have any problems with it.

gwiesenekker
Posts: 21
Joined: Sun Feb 20, 2011 21:04
Real name: Gijsbert Wiesenekker

Re: pydraughts, a draughts library in Python

Post by gwiesenekker » Tue Aug 27, 2024 08:50

Hi,

How does the DXP mode work? Is pydrauhts the DXP server or listener? I guess pydraughts is the DXP initiator? All engines should use a different DXP port number when running on the same machine? Will pydraughts launch the engine or is the engine supposed to be started and configured in DXP mode already? GWD and Scan can be launched in DXP mode, but suppose the engine has a GUI only and has to be configured in DXP mode through the GUI: will pydraughts just launch the engine and wait until the engine is running in DXP mode?

Thanks,
GW

AttackingOrDefending
Posts: 4
Joined: Sun Apr 17, 2022 08:03
Real name: Ioannis Pantidis

Re: pydraughts, a draughts library in Python

Post by AttackingOrDefending » Thu Aug 29, 2024 11:11

Is pydrauhts the DXP server or listener? I guess pydraughts is the DXP initiator?
Pydraughts is the listener and the initiator.
All engines should use a different DXP port number when running on the same machine?
Yes.
Will pydraughts launch the engine or is the engine supposed to be started and configured in DXP mode already?
Pydraughts supports both starting an engine and using an already opened one. An already opened one should be already configures for DXP. If pydaughts starts the engine, the engine must already be in DXP or accept an arguement that tells it to use DXP (e.g. for Scan it calls `scan.exe dxp`).
GWD and Scan can be launched in DXP mode, but suppose the engine has a GUI only and has to be configured in DXP mode through the GUI: will pydraughts just launch the engine and wait until the engine is running in DXP mode?
It will launch the engine and wait a predefined amount of time (called `wait-to-open-time`), in which the engine must be configured to use DXP.

See the code below for an example on how to use scan in dxp (`engine-opened: False` means that the engine isn't already open and that pydraughts should open it, `wait-to-open-time` is the amount of time pydraughts will wait for the engine to launch):

Code: Select all

import draughts
from draughts.engine import DXPEngine

dxp = DXPEngine(['scan.exe', 'dxp'], {'engine-opened': False, 'ip': '127.0.0.1', 'port': 27531, 'wait-to-open-time': 10, 'max-moves': 100, 'initial-time': 30})
game = draughts.Board()
while not game.is_over():
    if len(game.move_stack) % 2 == 0:
        best_move = dxp.play(game)
    else:
        best_move = random_move_engine(game)
    if best_move.move:
        game.push(best_move.move)
    else:
        break
dxp.quit()
dxp.kill_process()

gwiesenekker
Posts: 21
Joined: Sun Feb 20, 2011 21:04
Real name: Gijsbert Wiesenekker

Re: pydraughts, a draughts library in Python

Post by gwiesenekker » Thu Aug 29, 2024 21:43

Thank you!

Regards,
GW

Post Reply