TheYoBots / Lishogi-Bot

A bridge between Lishogi API and Lishogi USI Bots
https://lishogi.org/player/bots
GNU Affero General Public License v3.0
22 stars 33 forks source link
bot bot-account collaborate github lishogi lishogi-api lishogi-bot python shogi

Lishogi Bot

Lishogi Bot Build Python Build Lishogi Bots

A bridge between Lishogi's Bot API and Lishogi USI Bots. In case you don't know English, view the Japanese Translation here (日本語翻訳).

How to Install

Mac/Linux:

Windows:

Lishogi OAuth

Setup Engine

Within the file config.yml:

As an optional convenience, there is a folder named engines within the Lishogi-Bot folder where you can copy your engine and all the files it needs. This is the default executable location in the config.yml.default file.

Engine Configuration

Besides the above, there are many possible options within config.yml for configuring the engine for use with Lishogi-Bot.

One last option is go_commands. Beneath this option, arguments to the USI go command can be passed. For example,

  go_commands:
    nodes: 1
    depth: 5
    movetime: 1000

will append nodes 1 depth 5 movetime 1000 to the command to start thinking of a move: go startpos e2e4 e7e5 ....

Lishogi Upgrade to Bot Account

WARNING: This is irreversible. Read more about upgrading to bot account.

To Run

After activating the virtual environment created in the installation steps (the source line for Linux and Macs or the activate script for Windows), run

python3 lishogi-bot.py

The working directory for the engine execution will be the Lishogi-Bot directory. If your engine requires files located elsewhere, make sure they are specified by absolute path or copy the files to an appropriate location inside the Lishogi-Bot directory.

To output more information (including your engine's thinking output and debugging information), the -v option can be passed to Lishogi-Bot:

python3 lishogi-bot.py -v

If you want to record the output to a log file, add the -l or --logfile along with a file name:

python3 lishogi-bot.py --logfile log.txt

To Quit

Creating a homemade bot

As an alternative to creating an entire chess engine and implementing one of the communication protocols (USI), a bot can also be created by writing a single class with a single method. The search() method in this new class takes the current board and the game clock as arguments and should return a move based on whatever criteria you desires.

Steps to create a homemade bot:

  1. Do all the steps mentioned in How to Install.
  2. In the config.yml, change the engine protocol to homemade.
  3. Create a class in some file that extends the MinimalEngine class (in the strategies.py file).
    • Look at the strategies.py file to see some examples.
    • If you don't know what to implement, look at the EngineWrapper or USIEngine class.
      • You don't have to create your own engine, even though it's an EngineWrapper class.
        The examples just implement search.
  4. In the config.yml, change the name from engine_name to the name of your class.
    • In this case, you could change it to:
      name: "RandomMove"

Tips & Tricks

[Service] Environment="PYTHONUNBUFFERED=1" ExecStart=/usr/bin/python3/home/User/Lishogi-Bot/Lishogi-Bot.py WorkingDirectory=/home/User/lishogi-bot/ User=UserName Group=GroupName Restart=always

[Install] WantedBy=multi-user.target



## Acknowledgements
Thanks to the Lichess Team for creating a [repository](https://github.com/ShailChoksi/lichess-bot) that could be easily accessed and modified to help converting it to a format that supports Lishogi. Thanks to [Tasuku SUENAGA a.k.a. gunyarakun](https://github.com/gunyarakun) and his [python-shogi](https://pypi.org/pypi/python-shogi/) code which allows engine communication seamlessly. Thanks to  [WandererXII](https://github.com/WandererXII) for all his effort and help.

## License
Lishogi-Bot is licensed under the AGPLv3 (or any later version at your option). Check out the [LICENSE file](/LICENSE) for the full text.