TheYoBots commited on
Commit
5fba045
·
1 Parent(s): 784e528

Review https://github.com/TheYoBots/Lishogi-Bot/commit/f01cd90a7f5959d17ca10840519cd48bfa882399 and add Tips

Browse files
Files changed (3) hide show
  1. README.md +29 -1
  2. config.yml.default +4 -4
  3. engine_wrapper.py +2 -2
README.md CHANGED
@@ -8,6 +8,7 @@ A bridge between [Lichess API](https://lichess.org/api#tag/Bot) and Lishogi USI
8
  ## How to Install
9
 
10
  ### Mac/Linux:
 
11
  - **NOTE:** Only Python 3.7 or later is supported!
12
  - Download the repo into Lishogi-Bot directory.
13
  - Navigate to the directory in cmd/Terminal: `cd Lishogi-Bot`.
@@ -24,6 +25,7 @@ python3 -m pip install -r requirements.txt
24
  - Edit the `config.yml` file to your liking by changing the supported [variants](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L36-L38), [timings](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L39-L45), [challenge modes](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L46-L48) and [incoming challenges](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L25-L35), so that it plays shogi the way you want it to.
25
 
26
  ### Windows:
 
27
  - **NOTE:** Only Python 3.7 or later is supported!
28
  - 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\`.
29
  - To type commands it's better to use PowerShell. Go to Start menu and type `PowerShell`.
@@ -42,13 +44,15 @@ python3 -m pip install -r requirements.txt
42
  - Edit the `config.yml` file to your liking by changing the supported [variants](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L36-L38), [timings](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L39-L45), [challenge modes](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L46-L48) and [incoming challenges](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L25-35), so that it plays shogi the way you want it to.
43
 
44
  ## Lishogi OAuth
 
45
  - Create an account for your bot on [Lishogi.org](https://lishogi.org/signup).
46
  - **NOTE:** If you have previously played games on an existing account, you will not be able to use it as a bot account.
47
- - Once your account has been created and you are logged in, [create a personal OAuth2 token](https://lishogi.org/account/oauth/token/create) with the "Play as a bot" selected and add a description.
48
  - A `token` e.g. `xxxxxxxxxxxxxxxx` will be displayed. Store this in `config.yml` as the `token` field.
49
  - **NOTE:** You won't see this token again on Lishogi, so save it or store it somewhere.
50
 
51
  ## Setup Engine
 
52
  - Place your engine(s) in the `engine.dir` directory
53
  - In your `config.yml` file, enter the binary name as the `engine.name` field.
54
  - Using this process any engine can be added to the bot.
@@ -56,9 +60,33 @@ python3 -m pip install -r requirements.txt
56
 
57
 
58
  ## Lishogi Upgrade to Bot Account
 
59
  **WARNING** This is irreversible. Read more about [upgrading to bot account](https://lichess.org/api#operation/botAccountUpgrade).
60
  - run `python lishogi-bot.py -u`
61
  - for more verbrose logs run `python lishogi-bot.py -v`
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  # Acknowledgements
 
64
  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 [allthatglittersisgold](https://github.com/allthatglittersisgold) for creating a Windows executable for `lishogi-bot.py` and Thanks to [WandererXII](https://github.com/WandererXII) for all his effort and help.
 
8
  ## How to Install
9
 
10
  ### Mac/Linux:
11
+
12
  - **NOTE:** Only Python 3.7 or later is supported!
13
  - Download the repo into Lishogi-Bot directory.
14
  - Navigate to the directory in cmd/Terminal: `cd Lishogi-Bot`.
 
25
  - Edit the `config.yml` file to your liking by changing the supported [variants](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L36-L38), [timings](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L39-L45), [challenge modes](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L46-L48) and [incoming challenges](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L25-L35), so that it plays shogi the way you want it to.
26
 
27
  ### Windows:
28
+
29
  - **NOTE:** Only Python 3.7 or later is supported!
30
  - 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\`.
31
  - To type commands it's better to use PowerShell. Go to Start menu and type `PowerShell`.
 
44
  - Edit the `config.yml` file to your liking by changing the supported [variants](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L36-L38), [timings](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L39-L45), [challenge modes](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L46-L48) and [incoming challenges](https://github.com/TheYoBots/Lishogi-Bot/blob/c746023ce8bc95ab7c0f3810921675a8b96610e8/config.yml#L25-35), so that it plays shogi the way you want it to.
45
 
46
  ## Lishogi OAuth
47
+
48
  - Create an account for your bot on [Lishogi.org](https://lishogi.org/signup).
49
  - **NOTE:** If you have previously played games on an existing account, you will not be able to use it as a bot account.
50
+ - Once your account has been created and you are logged in, [create a personal OAuth2 token](https://lishogi.org/account/oauth/token/create) with the ["Play games with the bot API" (play:bot scopes)](https://lishogi.org/account/oauth/token/create?scopes[]=bot:play) selected and a description added.
51
  - A `token` e.g. `xxxxxxxxxxxxxxxx` will be displayed. Store this in `config.yml` as the `token` field.
52
  - **NOTE:** You won't see this token again on Lishogi, so save it or store it somewhere.
53
 
54
  ## Setup Engine
55
+
56
  - Place your engine(s) in the `engine.dir` directory
57
  - In your `config.yml` file, enter the binary name as the `engine.name` field.
58
  - Using this process any engine can be added to the bot.
 
60
 
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
+ ```
73
+ [Unit]
74
+ Description=Lishogi-Bot
75
+ After=network-online.target
76
+ Wants=network-online.target
77
+
78
+ [Service]
79
+ Environment="PYTHONUNBUFFERED=1"
80
+ ExecStart=/usr/bin/python3/home/User/Lishogi-Bot/Lishogi-Bot.py
81
+ WorkingDirectory=/home/thibault/lichess-bot/
82
+ User=UserName
83
+ Group=GroupName
84
+ Restart=always
85
+
86
+ [Install]
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 [allthatglittersisgold](https://github.com/allthatglittersisgold) for creating a Windows executable for `lishogi-bot.py` and Thanks to [WandererXII](https://github.com/WandererXII) for all his effort and help.
config.yml.default CHANGED
@@ -1,10 +1,10 @@
1
- token: "xxxxxxxxxxxxxxxx" # Lishogi OAuth Token with 'play as a bot' enabled.
2
  url: "https://lishogi.org/" # Lishogi base URL. Do not change this unless locally hosted to an external URL.
3
 
4
  engine: # Engine Settings.
5
  dir: "./engines/" # dir containing engines, relative to this project.
6
  name: "engine_name" # Binary name of the engine to use. Make sure the engine you use is running under the USI protocol.
7
- protocol: "usi" # "usi" protocol. No other options will be accepted here.
8
  ponder: false # Not supported. Setting it to 'true' will not work.
9
  # engine_options: # Any custom command line params to pass to the engine.
10
  # cpuct: 3.1
@@ -22,9 +22,9 @@ abort_time: 30 # Time in seconds after which the engine will abort
22
  fake_think_time: false # Artificially slow down the bot to pretend like it's thinking.
23
  move_overhead: 5000 # Increase if your bot flags games too often.
24
 
25
- challenge: # Incoming challenges
26
  concurrency: 1 # Number of games to play simultaneously.
27
- sort_by: "best" # Possible values here are "best", "first"
28
  accept_bot: true # Accepts challenges coming from other bots. Setting this to 'true' will allow games from both human and bot, but setting it to false will allow games only from human.
29
  only_bot: false # Enable this to accept challenges only from bots. This will disable accepting challenges from human.
30
  max_increment: 180 # Maximum amount of increment to accaept a challenge. The max is 180. Set to 0 for no increment.
 
1
+ token: "xxxxxxxxxxxxxxxx" # Lishogi OAuth Token (which can be taken from https://lishogi.org/account/oauth/token/create?scopes[]=bot:play) with 'Play games with the bot API' (bot:play scopes) enabled.
2
  url: "https://lishogi.org/" # Lishogi base URL. Do not change this unless locally hosted to an external URL.
3
 
4
  engine: # Engine Settings.
5
  dir: "./engines/" # dir containing engines, relative to this project.
6
  name: "engine_name" # Binary name of the engine to use. Make sure the engine you use is running under the USI protocol.
7
+ protocol: "usi" # Protocol that engine is run under. Only "usi" is supported currently.
8
  ponder: false # Not supported. Setting it to 'true' will not work.
9
  # engine_options: # Any custom command line params to pass to the engine.
10
  # cpuct: 3.1
 
22
  fake_think_time: false # Artificially slow down the bot to pretend like it's thinking.
23
  move_overhead: 5000 # Increase if your bot flags games too often.
24
 
25
+ challenge: # Incoming challenges.
26
  concurrency: 1 # Number of games to play simultaneously.
27
+ sort_by: "best" # Possible values here are "best" and "first".
28
  accept_bot: true # Accepts challenges coming from other bots. Setting this to 'true' will allow games from both human and bot, but setting it to false will allow games only from human.
29
  only_bot: false # Enable this to accept challenges only from bots. This will disable accepting challenges from human.
30
  max_increment: 180 # Maximum amount of increment to accaept a challenge. The max is 180. Set to 0 for no increment.
engine_wrapper.py CHANGED
@@ -140,6 +140,6 @@ class USIEngine(EngineWrapper):
140
  rating = game.opponent.rating if game.opponent.rating is not None else "none"
141
  title = game.opponent.title if game.opponent.title else "none"
142
  player_type = "computer" if title == "BOT" else "human"
 
143
  def report_game_result(self, game, board):
144
- self.engine.protocol._position(board)
145
-
 
140
  rating = game.opponent.rating if game.opponent.rating is not None else "none"
141
  title = game.opponent.title if game.opponent.title else "none"
142
  player_type = "computer" if title == "BOT" else "human"
143
+
144
  def report_game_result(self, game, board):
145
+ self.engine.protocol._position(board)