Alistair-Crompton / DGTCentaurMods

DGT Centaur Modifications
GNU General Public License v3.0
5 stars 6 forks source link

Alistair DGT Centaur mods

The original DGT Centaur mods project adds features to the DGT Centaur electronic chessboard.

This current project overrides the legacy one, re-coding and re-factoring all the unstable scripts, adding new features.

Inside the DGT Centaur is a Raspberry Pi Zero with an SD Card, by replacing that with a Raspberry Pi Zero 2 W (or Raspberry Pi Zero W) and using a modified software, we get a wireless enabled chessboard that can be easily extended and improved.

A word of caution!

All functionality is based on the fact that the Raspberry Pi Zero inside the board is being replaced with a Raspberry Pi Zero 2 W (or Raspberry Pi Zero W) and this breaks the product warranty. Proceed at your own risk!

Current features

Lichess demo

Roadmap

Currently we are working on...

  1. Squashing bugs
  2. Improving performance
  3. Adding new features

Install procedure

  1. From your Pi, download the latest available release:
wget -O ./_DGTCentaurMods_A.alpha-latest.deb `curl -s https://api.github.com/repos/Alistair-Crompton/DGTCentaurMods/releases/latest | grep browser_download_url | cut -d '"' -f 4`
  1. Install the downloaded package:
sudo apt install -y ./_DGTCentaurMods_A.alpha-latest.deb
  1. Reboot:
sudo reboot

This project uses...

Support & Requests

You can send an email to: dgtcentaurmods@moult.org or join our discord server at: https://discord.gg/d8JXud22RE

Contributors welcome!

If you can offer some time and effort to the project please get in contact! Everybody is more than welcome!

Few screenshots of the web UI

Plugin creation

If you know a bit Python, you can easily create new plugins and play with them. New plugins are dynamically recognized as soon as they are copied within the "plugins" directory.

Few examples of plugins are available, they show the basic structure of a plugin.

El Professor demo

If you know Python, create easily your own plugin! Here is an example of a "Random bot" that plays random moves:

import chess, random

from DGTCentaurMods.classes.Plugin import Plugin, Centaur
from DGTCentaurMods.consts import Enums, fonts

from typing import Optional

HUMAN_COLOR = chess.WHITE

# The plugin must inherits of the Plugin class.
# Filename must match the class name.
class RandomBot(Plugin):

    # This function is automatically invoked each
    # time the player pushes a key.
    # Except the BACK key which is handled by the engine.
    def key_callback(self, key:Enums.Btn) -> bool:

        # If the user pushes HELP,
        # we display an hint using Stockfish engine.
        if key == Enums.Btn.HELP:
            Centaur.hint()

            # Key has been handled.
            return True

        # Key can be handled by the engine.
        return False

    # When exists, this function is automatically invoked
    # when the game engine state is affected.
    def event_callback(self, event:Enums.Event, outcome:Optional[chess.Outcome]):

        # If the user chooses to leave,
        # we quit the plugin.
        if event == Enums.Event.QUIT:
            self.stop()

        if event == Enums.Event.PLAY:

            turn = self.chessboard.turn

            current_player = "You" if turn == chess.WHITE else "Random bot"

            # We display the board header.
            Centaur.header(f"{current_player} {'W' if turn == chess.WHITE else 'B'}")

            if turn == (not HUMAN_COLOR):

                # We choose a random move
                uci_move = str(random.choice(list(self.chessboard.legal_moves)))

                Centaur.play_computer_move(uci_move)

    # When exists, this function is automatically invoked
    # at start, after splash screen, on PLAY button.
    def on_start_callback(self, key:Enums.Btn) -> bool:

        # Start a new game.
        Centaur.start_game(
            white="You", 
            black="Random bot", 
            event="Bots chess event 2024",
            flags=Enums.BoardOption.CAN_UNDO_MOVES)

        # Game started.
        return True

    # When exists, this function is automatically invoked
    # when the plugin starts.
    def splash_screen(self) -> bool:

        print = Centaur.print

        Centaur.clear_screen()

        print("RANDOM", row=2)
        print("BOT", font=fonts.DIGITAL_FONT, row=4)
        print("Push PLAY", row=8)
        print("to")
        print("start")
        print("the game!")

        # The splash screen is activated.
        return True

Live script module

A sample of live script is available within the "scripts" directory.

Here is a simple macro that plays against the Random bot:

from DGTCentaurMods.classes import LiveScript, CentaurScreen
from DGTCentaurMods.consts import Enums

import time, random

SCREEN = CentaurScreen.get()
LS = LiveScript.get()

# Back to home menu
LS.push_button(Enums.Btn.BACK)
LS.push_button(Enums.Btn.BACK)
LS.push_button(Enums.Btn.BACK)
LS.push_button(Enums.Btn.BACK)

def play_random_move():
  legal_moves = LS.chessboard().legal_moves
  uci_move = str(random.choice(list(legal_moves)))[0:4]
  return LS.play(uci_move)

# Choose PLUGINS
LS.select_menu("PLUGINS")

# Launch Random bot plugin
LS.select_menu("RANDOM BOT")
time.sleep(2)

# Pass the splash screen
LS.push_button(Enums.Btn.PLAY)
time.sleep(2)

# Random moves
for _ in range(10):
  play_random_move()
  bot_move = LS.waitfor_computer_move()
  LS.play(bot_move)

LS.write_text(4, "SCRIPT")
LS.write_text(5, "DONE!")