Spaces:
Sleeping
Sleeping
gbtami commited on
Commit ·
d369768
1
Parent(s): 2c411d9
Fix #84 Why not use weighted_choice instead of random choice in get_book_move?
Browse files- config.yml.default +2 -2
- lichess-bot.py +10 -6
config.yml.default
CHANGED
|
@@ -10,7 +10,7 @@ engine: # engine settings
|
|
| 10 |
book: "engines/book.bin" # book file path
|
| 11 |
max_depth: 8 # half move max depth
|
| 12 |
min_weight: 1 # selects move with highest weight but not below this value
|
| 13 |
-
|
| 14 |
uci_options: # arbitrary UCI options passed to the engine
|
| 15 |
Move Overhead: 100 # increase if your bot flags games too often
|
| 16 |
Threads: 2 # max CPU threads the engine can use
|
|
@@ -32,7 +32,7 @@ engine: # engine settings
|
|
| 32 |
# threads: 1 # max CPU threads the engine can use
|
| 33 |
# gpu: 0 # which GPU to use
|
| 34 |
# tempdecay: 10 # After search is complete, the tempdecay can pick slightly weaker moves to offer variety. 10 is good tradeoff
|
| 35 |
-
# noise: true # Randomness in the search algorithm. This makes sure that even unfavored lines are given a "lucky" shot
|
| 36 |
# log: "./engines/log.txt" # save log of lczero debug output
|
| 37 |
silence_stderr: false # some engines (yes you, leela) are very noisy
|
| 38 |
|
|
|
|
| 10 |
book: "engines/book.bin" # book file path
|
| 11 |
max_depth: 8 # half move max depth
|
| 12 |
min_weight: 1 # selects move with highest weight but not below this value
|
| 13 |
+
selection: "weighted_random" # move slection is one of "weighted_random", "uniform_random" or "best_move" (but not below the min_weight in 2. and 3. case)
|
| 14 |
uci_options: # arbitrary UCI options passed to the engine
|
| 15 |
Move Overhead: 100 # increase if your bot flags games too often
|
| 16 |
Threads: 2 # max CPU threads the engine can use
|
|
|
|
| 32 |
# threads: 1 # max CPU threads the engine can use
|
| 33 |
# gpu: 0 # which GPU to use
|
| 34 |
# tempdecay: 10 # After search is complete, the tempdecay can pick slightly weaker moves to offer variety. 10 is good tradeoff
|
| 35 |
+
# noise: true # Randomness in the search algorithm. This makes sure that even unfavored lines are given a "lucky" shot
|
| 36 |
# log: "./engines/log.txt" # save log of lczero debug output
|
| 37 |
silence_stderr: false # some engines (yes you, leela) are very noisy
|
| 38 |
|
lichess-bot.py
CHANGED
|
@@ -188,13 +188,17 @@ def play_first_book_move(game, engine, board, li, config):
|
|
| 188 |
|
| 189 |
def get_book_move(board, config):
|
| 190 |
with chess.polyglot.open_reader(config["book"]) as reader:
|
| 191 |
-
try:
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
| 195 |
return reader.find(board, config.get("min_weight", 1)).move()
|
| 196 |
-
except:
|
| 197 |
-
|
|
|
|
| 198 |
|
| 199 |
|
| 200 |
def setup_board(game):
|
|
|
|
| 188 |
|
| 189 |
def get_book_move(board, config):
|
| 190 |
with chess.polyglot.open_reader(config["book"]) as reader:
|
| 191 |
+
try:
|
| 192 |
+
selection = config.get("selection", "weighted_random")
|
| 193 |
+
if selection == "weighted_random":
|
| 194 |
+
return reader.weighted_choice(board).move()
|
| 195 |
+
elif selection == "uniform_random":
|
| 196 |
+
return reader.choice(board, config.get("min_weight", 1)).move()
|
| 197 |
+
elif selection == "best_move":
|
| 198 |
return reader.find(board, config.get("min_weight", 1)).move()
|
| 199 |
+
except IndexError:
|
| 200 |
+
# python-chess raises "IndexError" if no entries found
|
| 201 |
+
return None
|
| 202 |
|
| 203 |
|
| 204 |
def setup_board(game):
|