Libot TheYoBots commited on
Commit
e56aff4
·
1 Parent(s): 08aef79

Minor fixes/updates (#32)

Browse files

Thanks to https://github.com/ShailChoksi/lichess-bot/pull/337 for engine configuration.

Co-authored-by: TheYoBots <elton_nathan@yahoo.com>

Files changed (3) hide show
  1. README.md +129 -26
  2. lishogi.py +1 -1
  3. tests.py +3 -3
README.md CHANGED
@@ -1,15 +1,12 @@
1
  # Lishogi Bot
2
-
3
  [![Lishogi Bot Build](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/lishogi-bot-build.yml/badge.svg)](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/lishogi-bot-build.yml)
4
  [![Python Build](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/python-build.yml/badge.svg)](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/python-build.yml)
5
  [![Lishogi Bots](https://img.shields.io/badge/Lishogi_Bots-%40Bot-blue.svg)](https://lishogi.org/player/bots)
6
 
7
- A bridge between [Lichess API](https://lichess.org/api#tag/Bot) and Lishogi USI Bots. In case you don't know English, view the [Japanese Translation here (日本語翻訳)](https://github.com/TheYoBots/Lishogi-Bot/wiki/Japanese-Translation).
8
 
9
  ## How to Install
10
-
11
  ### Mac/Linux:
12
-
13
  - **NOTE: Only Python 3.7 or later is supported!**
14
  - Download the repo into Lishogi-Bot directory.
15
  - Navigate to the directory in cmd/Terminal: `cd Lishogi-Bot`.
@@ -18,55 +15,162 @@ A bridge between [Lichess API](https://lichess.org/api#tag/Bot) and Lishogi USI
18
  - Setup virtualenv: `apt install python3-venv`.
19
  ```python
20
  python3 -m venv venv # if this fails you probably need to add Python3 to your PATH.
21
- virtualenv .venv -p python3 # if this fails you probably need to add Python3 to your PATH.
22
  source ./venv/bin/activate
23
  python3 -m pip install -r requirements.txt
24
  ```
25
  - Copy `config.yml.default` to `config.yml`.
26
- - Edit the `config.yml` file to your liking by changing the supported [variants](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L42-L44), [timings](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L45-L51), [challenge modes](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L52-L54) and [incoming challenges](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L31-L41), so that it plays shogi the way you want it to.
27
 
28
  ### Windows:
29
-
30
  - **NOTE: Only Python 3.7 or later is supported!**
31
  - If you don't have Python, you may download it [here](https://www.python.org/downloads/). When installing it, enable `add Python to PATH`, then go to custom installation (this may be not necessary, but on some computers it won't work otherwise) and enable all options (especially `install for all users`), except the last . It's better to install Python in a path without spaces, like `C:\Python\`.
32
- - To type commands it's better to use PowerShell. Go to Start menu and type `PowerShell`.
33
  - Then you may need to upgrade pip. Execute `python -m pip install --upgrade pip` in PowerShell.
34
  - Download the repo into lishogi-bot directory.
35
- - Navigate to the directory in PowerShell: `cd [folder's adress]` (like `cd C:\shogi\lishogi-bot`).
36
  - Install virtualenv: `pip install virtualenv`.
37
  - Setup virtualenv:
38
-
39
  ```python
40
  python -m venv .venv # if this fails you probably need to add Python to your PATH.
41
- ./.venv/Scripts/Activate.ps1 # .\.venv\Scripts\activate.bat should work in cmd in administator mode. This may not work on Windows, and in this case you need to execute "Set-ExecutionPolicy RemoteSigned" first and choose "Y" there (you may need to run Powershell as administrator). After you executed the script, change execution policy back with "Set-ExecutionPolicy Restricted" and pressing "Y").
42
  pip install -r requirements.txt
43
  ```
44
  - Copy `config.yml.default` to `config.yml`.
45
- - Edit the `config.yml` file to your liking by changing the supported [variants](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L42-L44), [timings](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L45-L51), [challenge modes](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L52-L54) and [incoming challenges](https://github.com/TheYoBots/Lishogi-Bot/blob/master/config.yml.default#L31-L41), so that it plays shogi the way you want it to.
46
 
47
  ## Lishogi OAuth
48
-
49
  - Create an account for your bot on [Lishogi.org](https://lishogi.org/signup).
50
  - **NOTE: If you have previously played games on an existing account, you will not be able to use it as a bot account.**
51
- - Once your account has been created and you are logged in, [create a personal OAuth2 token with the "Play games with the bot API" ('play:bot' scopes), "Read incoming challenges" ('challenge:read' scopes) and "Create, accept, decline challenges" ('challenge:write' scopes)](https://lishogi.org/account/oauth/token/create?scopes[]=bot:play&scopes[]=challenge:read&scopes[]=challenge:write&description=Lishogi+Bot+Token) selected and a description added.
52
- - A `token` e.g. `xxxxxxxxxxxxxxxx` will be displayed. Store this in `config.yml` as the `token` field.
53
  - **NOTE: You won't see this token again on Lishogi, so save it or store it somewhere.**
54
 
55
  ## Setup Engine
56
-
57
- - Place your engine(s) in the `engine.dir` directory
58
- - In your `config.yml` file, enter the binary name as the `engine.name` field.
59
  - Using this process any engine can be added to the bot.
60
- - **Note: The engine you add has to be running under the USI protocol, then only it will work**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- ## Lishogi Upgrade to Bot Account
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
 
64
  **WARNING: This is irreversible. Read more about [upgrading to bot account](https://lichess.org/api#operation/botAccountUpgrade).**
65
- - run `python lishogi-bot.py -u`
66
- - for more verbrose logs run `python lishogi-bot.py -v`
67
 
68
- ## Tips & Tricks
 
 
 
 
 
 
 
 
 
 
69
 
 
70
  - You can specify a different config file with the `--config` argument.
71
  - Here's an example systemd service definition:
72
  ```python
@@ -87,6 +191,5 @@ Restart=always
87
  WantedBy=multi-user.target
88
  ```
89
 
90
- # Acknowledgements
91
-
92
- 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 and for running an [API](https://lichess.org/api) which is used by lishogi. Thanks to the [Tasuku SUENAGA a.k.a. gunyarakun](https://github.com/gunyarakun) and his [python-shogi](https://github.com/gunyarakun) code which allows engine communication seamlessly. Thanks to [WandererXII](https://github.com/WandererXII) for all his effort and help.
 
1
  # Lishogi Bot
 
2
  [![Lishogi Bot Build](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/lishogi-bot-build.yml/badge.svg)](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/lishogi-bot-build.yml)
3
  [![Python Build](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/python-build.yml/badge.svg)](https://github.com/TheYoBots/Lishogi-Bot/actions/workflows/python-build.yml)
4
  [![Lishogi Bots](https://img.shields.io/badge/Lishogi_Bots-%40Bot-blue.svg)](https://lishogi.org/player/bots)
5
 
6
+ A bridge between [Lishogi's API](https://lichess.org/api#tag/Bot) and Lishogi USI Bots. In case you don't know English, view the [Japanese Translation here (日本語翻訳)](https://github.com/TheYoBots/Lishogi-Bot/wiki/Japanese-Translation).
7
 
8
  ## How to Install
 
9
  ### Mac/Linux:
 
10
  - **NOTE: Only Python 3.7 or later is supported!**
11
  - Download the repo into Lishogi-Bot directory.
12
  - Navigate to the directory in cmd/Terminal: `cd Lishogi-Bot`.
 
15
  - Setup virtualenv: `apt install python3-venv`.
16
  ```python
17
  python3 -m venv venv # if this fails you probably need to add Python3 to your PATH.
18
+ virtualenv venv -p python3 # if this fails you probably need to add Python3 to your PATH.
19
  source ./venv/bin/activate
20
  python3 -m pip install -r requirements.txt
21
  ```
22
  - Copy `config.yml.default` to `config.yml`.
23
+ - Edit the `config.yml` file to your liking by changing the supported [variants](/config.yml.default#L43-L45), [timings](/config.yml.default#L46-L52), [challenge modes](/config.yml.default#L53-L55) and [incoming challenges](/config.yml.default#L32-L42), so that it plays shogi the way you want it to.
24
 
25
  ### Windows:
 
26
  - **NOTE: Only Python 3.7 or later is supported!**
27
  - If you don't have Python, you may download it [here](https://www.python.org/downloads/). When installing it, enable `add Python to PATH`, then go to custom installation (this may be not necessary, but on some computers it won't work otherwise) and enable all options (especially `install for all users`), except the last . It's better to install Python in a path without spaces, like `C:\Python\`.
28
+ - To type commands it's better to use PowerShell. Go to Start menu and type `PowerShell` (you may use "cmd" too, but sometimes it may not work).
29
  - Then you may need to upgrade pip. Execute `python -m pip install --upgrade pip` in PowerShell.
30
  - Download the repo into lishogi-bot directory.
31
+ - Navigate to the directory in PowerShell: `cd [folder's adress]` (example, `cd C:\shogi\lishogi-bot`).
32
  - Install virtualenv: `pip install virtualenv`.
33
  - Setup virtualenv:
 
34
  ```python
35
  python -m venv .venv # if this fails you probably need to add Python to your PATH.
36
+ ./.venv/Scripts/Activate.ps1 # `.\.venv\Scripts\activate.bat` should work in cmd in administator mode. This may not work on Windows, and in this case you need to execute "Set-ExecutionPolicy RemoteSigned" first and choose "Y" there (you may need to run Powershell as administrator). After you executed the script, change execution policy back with "Set-ExecutionPolicy Restricted" and pressing "Y".
37
  pip install -r requirements.txt
38
  ```
39
  - Copy `config.yml.default` to `config.yml`.
40
+ - Edit the `config.yml` file to your liking by changing the supported [variants](/config.yml.default#L43-L45), [timings](/config.yml.default#L46-L52), [challenge modes](/config.yml.default#L53-L55) and [incoming challenges](/config.yml.default#L32-L42), so that it plays shogi the way you want it to.
41
 
42
  ## Lishogi OAuth
 
43
  - Create an account for your bot on [Lishogi.org](https://lishogi.org/signup).
44
  - **NOTE: If you have previously played games on an existing account, you will not be able to use it as a bot account.**
45
+ - Once your account has been created and you are logged in, [create a personal OAuth2 token with the "Play games with the bot API" ('play:bot' scopes)](https://lishogi.org/account/oauth/token/create?scopes[]=bot:play&scopes[]=challenge:read&scopes[]=challenge:write&description=Lishogi+Bot+Token) selected and a description added.
46
+ - A `token` (e.g. `xxxxxxxxxxxxxxxx`) will be displayed. Store this in the `config.yml` file as the `token` field.
47
  - **NOTE: You won't see this token again on Lishogi, so save it or store it somewhere.**
48
 
49
  ## Setup Engine
50
+ - Place your engine(s) in the `engine: dir` directory.
51
+ - In the `config.yml` file, enter the binary name as the `engine: name` field (In Windows you may need to type a name with `.exe`, like `lczero.exe`).
 
52
  - Using this process any engine can be added to the bot.
53
+ - **Note: The engine you add has to be running under the USI protocol, only then it will work.**
54
+
55
+ ### Engine Configuration
56
+ Besides the above, there are many possible options within `config.yml` for configuring the engine for use with lishogi-bot.
57
+ - `protocol`: Specify which protocol your engine uses. `"usi"` for the [Universal Shogi Interface](http://hgm.nubati.net/usi.html) is the only supported protocol.
58
+ - `ponder`: Specify whether your bot will ponder, i.e., think while the bot's opponent is choosing a move.
59
+ - `engine_options`: Command line options to pass to the engine on startup. For example, the `config.yml.default` has the configuration
60
+ ```yml
61
+ engine_options:
62
+ cpuct: 3.1
63
+ ```
64
+ This would create the command-line option `--cpuct=3.1` to be used when starting the engine. Any number of options can be listed here, each getting their own command-line option.
65
+ - `usi_options`: A list of options to pass to a USI engine after startup. Different engines have different options, so treat the options in `config.yml.default` as templates and not suggestions. When USI engines start, they print a list of configurations that can modify their behavior. For example, Fairy Stockfish 13 prints the following when run at the command line:
66
+ ```
67
+ id name Fairy Stockfish 13
68
+ id author Fabian Fichter
69
+
70
+ option name Debug Log File type string default
71
+ option name Contempt type spin default 24 min -100 max 100
72
+ option name Analysis Contempt type combo default Both var Off var White var Black var Both
73
+ option name Threads type spin default 1 min 1 max 512
74
+ option name Hash type spin default 16 min 1 max 33554432
75
+ option name Clear Hash type button
76
+ option name Ponder type check default false
77
+ option name MultiPV type spin default 1 min 1 max 500
78
+ option name Skill Level type spin default 20 min 0 max 20
79
+ option name Move Overhead type spin default 10 min 0 max 5000
80
+ option name Slow Mover type spin default 100 min 10 max 1000
81
+ option name nodestime type spin default 0 min 0 max 10000
82
+ option name UCI_Chess960 type check default false
83
+ option name UCI_AnalyseMode type check default false
84
+ option name UCI_LimitStrength type check default false
85
+ option name UCI_Elo type spin default 1350 min 1350 max 2850
86
+ option name UCI_ShowWDL type check default false
87
+ option name SyzygyPath type string default <empty>
88
+ option name SyzygyProbeDepth type spin default 1 min 1 max 100
89
+ option name Syzygy50MoveRule type check default true
90
+ option name SyzygyProbeLimit type spin default 7 min 0 max 7
91
+ option name Use NNUE type check default true
92
+ option name EvalFile type string default nn-62ef826d1a6d.nnue
93
+ uciok
94
+ ```
95
+ Any of the names following `option name` can be listed in `usi_options` in order to configure the Fairy Stockfish engine.
96
+ ```yml
97
+ usi_options:
98
+ Move Overhead: 100
99
+ Skill Level: 10
100
+ ```
101
+ The exception to this are the options `uci_chess960`, `uci_variant`, `multipv`, and `ponder`. These will be handled by lishogi-bot after a game starts and should not be listed in the `config.yml` file. Also, if an option is listed under `usi_options` that is not in the list printed by the engine, it will cause an error when the engine starts because the engine won't understand the option. The word after `type` indicates the expected type of the options: `string` for a text string, `spin` for a numeric value, `check` for a boolean True/False value.
102
+
103
+ One last option is `go_commands`. Beneath this option, arguments to the USI `go` command can be passed. For example,
104
+ ```yml
105
+ go_commands:
106
+ nodes: 1
107
+ depth: 5
108
+ movetime: 1000
109
+ ```
110
+ will append `nodes 1 depth 5 movetime 1000` to the command to start thinking of a move: `go startpos e2e4 e7e5 ...`.
111
+
112
+ - `abort_time`: How many seconds to wait before aborting a game due to opponent inaction. This only applies during the first six moves of the game.
113
+ - `fake_think_time`: Artificially slow down the engine to simulate a person thinking about a move. The amount of thinking time decreases as the game goes on.
114
+ - `rate_limiting_delay`: For extremely fast games, the [lishogi.org](https://lishogi.org) servers may respond with an error if too many moves are played to quickly. This option avoids this problem by pausing for a specified number of milliseconds after submitting a move before making the next move.
115
+ - `move_overhead`: To prevent losing on time due to network lag, subtract this many milliseconds from the time to think on each move.
116
+
117
+ - `correspondence` These options control how the engine behaves during correspondence games.
118
+ - `move_time`: How many seconds to think for each move.
119
+ - `checkin_period`: How often (in seconds) to reconnect to games to check for new moves after disconnecting.
120
+ - `disconnect_time`: How many seconds to wait after the bot makes a move for an opponent to make a move. If no move is made during the wait, disconnect from the game.
121
+ - `ponder`: Whether the bot should ponder during the above waiting period.
122
+
123
+ - `challenge`: Control what kind of games for which the bot should accept challenges. All of the following options must be satisfied by a challenge to be accepted.
124
+ - `concurrency`: The maximum number of games to play simultaneously.
125
+ - `sort_by`: Whether to start games by the best rated/titled opponent `"best"` or by first-come-first-serve `"first"`.
126
+ - `accept_bot`: Whether to accept challenges from other bots.
127
+ - `only_bot`: Whether to only accept challenges from other bots.
128
+ - `max_increment`: The maximum value of time increment.
129
+ - `min_increment`: The minimum value of time increment.
130
+ - `max_base`: The maximum base time for a game.
131
+ - `min_base`: The minimum base time for a game.
132
+
133
+ - `variants`: An indented list of chess variants that the bot can handle.
134
+ ```yml
135
+ variants:
136
+ - standard
137
+ - fromPosition
138
+ ```
139
 
140
+ - `time_controls`: An indented list of acceptable time control types from `ultraBullet` to `correspondence`.
141
+ ```yml
142
+ time_controls:
143
+ - ultraBullet
144
+ - bullet
145
+ - blitz
146
+ - rapid
147
+ - classical
148
+ - correpondence
149
+ ```
150
+ - `modes`: An indented list of acceptable game modes (`rated` and/or `casual`).
151
+ ```yml
152
+ modes:
153
+ -rated
154
+ -casual
155
+ ```
156
 
157
+ ## Lishogi Upgrade to Bot Account
158
  **WARNING: This is irreversible. Read more about [upgrading to bot account](https://lichess.org/api#operation/botAccountUpgrade).**
159
+ - Run `python lishogi-bot.py -u`.
 
160
 
161
+ ## To Run
162
+ After activating the virtual environment created in the installation steps (the `source` line for Linux and Macs or the `activate` script for Windows), run
163
+ ```python
164
+ python lishogi-bot.py
165
+ ```
166
+ 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.
167
+
168
+ To output more information (including your engine's thinking output and debugging information), the `-v` option can be passed to lishogi-bot:
169
+ ```python
170
+ python lishogi-bot.py -v
171
+ ```
172
 
173
+ ## Tips & Tricks
174
  - You can specify a different config file with the `--config` argument.
175
  - Here's an example systemd service definition:
176
  ```python
 
191
  WantedBy=multi-user.target
192
  ```
193
 
194
+ ## Acknowledgements
195
+ 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.
 
lishogi.py CHANGED
@@ -23,7 +23,7 @@ ENDPOINTS = {
23
  }
24
 
25
 
26
- # docs: https://lichess.org/api
27
  class Lishogi:
28
  def __init__(self, token, url, version):
29
  self.version = version
 
23
  }
24
 
25
 
26
+ # docs: https://lichess.org/api till lishogi API is made
27
  class Lishogi:
28
  def __init__(self, token, url, version):
29
  self.version = version
tests.py CHANGED
@@ -24,7 +24,7 @@ def run_bot(CONFIG, logging_level):
24
  user_profile = li.get_profile()
25
  username = user_profile["username"]
26
  is_bot = user_profile.get("title") == "BOT"
27
- lishogi_bot.logger.info("Welcome {}!".format(username))
28
 
29
  if not is_bot:
30
  is_bot = lishogi_bot.upgrade_account(li)
@@ -81,7 +81,7 @@ def run_bot(CONFIG, logging_level):
81
 
82
 
83
  def test_bot():
84
- logging_level = lishogi_bot.logging.INFO # lichess_bot.logging_level.DEBUG
85
  lishogi_bot.logging.basicConfig(level=logging_level, filename=None, format="%(asctime)-15s: %(message)s")
86
  lishogi_bot.enable_color_logging(debug_lvl=logging_level)
87
  download_fsf()
@@ -95,4 +95,4 @@ def test_bot():
95
 
96
 
97
  if __name__ == '__main__':
98
- test_bot()
 
24
  user_profile = li.get_profile()
25
  username = user_profile["username"]
26
  is_bot = user_profile.get("title") == "BOT"
27
+ lishogi_bot.logger.info("Welcome BOT {}!".format(username))
28
 
29
  if not is_bot:
30
  is_bot = lishogi_bot.upgrade_account(li)
 
81
 
82
 
83
  def test_bot():
84
+ logging_level = lishogi_bot.logging.INFO # lishogi_bot.logging_level.DEBUG
85
  lishogi_bot.logging.basicConfig(level=logging_level, filename=None, format="%(asctime)-15s: %(message)s")
86
  lishogi_bot.enable_color_logging(debug_lvl=logging_level)
87
  download_fsf()
 
95
 
96
 
97
  if __name__ == '__main__':
98
+ test_bot()