本文整理汇总了Python中chess.uci方法的典型用法代码示例。如果您正苦于以下问题:Python chess.uci方法的具体用法?Python chess.uci怎么用?Python chess.uci使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chess
的用法示例。
在下文中一共展示了chess.uci方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import chess [as 别名]
# 或者: from chess import uci [as 别名]
def __init__(self, board, commands, options, silence_stderr=False):
commands = commands[0] if len(commands) == 1 else commands
self.go_commands = options.get("go_commands", {})
self.engine = chess.uci.popen_engine(commands, stderr = subprocess.DEVNULL if silence_stderr else None)
self.engine.uci()
if options:
self.engine.setoption(options)
self.engine.setoption({
"UCI_Variant": type(board).uci_variant,
"UCI_Chess960": board.chess960
})
self.engine.position(board)
info_handler = chess.uci.InfoHandler()
self.engine.info_handlers.append(info_handler)
示例2: book
# 需要导入模块: import chess [as 别名]
# 或者: from chess import uci [as 别名]
def book(self, bookreader, game_copy: chess.Board):
"""Get a BookMove or None from game position."""
try:
choice = bookreader.weighted_choice(game_copy, self.excludemoves)
except IndexError:
return None
book_move = choice.move()
self.add(book_move)
game_copy.push(book_move)
try:
choice = bookreader.weighted_choice(game_copy)
book_ponder = choice.move()
except IndexError:
book_ponder = None
return chess.uci.BestMove(book_move, book_ponder)
示例3: run_thread
# 需要导入模块: import chess [as 别名]
# 或者: from chess import uci [as 别名]
def run_thread(thread_id, module, example_queue):
selfplay_model = args.model and module.Model(args.model)
engine = chess.uci.popen_engine(STOCKFISH_PATH)
info_handler = chess.uci.InfoHandler()
engine.info_handlers.append(info_handler)
engine.uci()
engine.isready()
start, last = time.time(), 0
for i in range(N_GAMES // THREADS):
# Predicting progress and ETA
if thread_id == 0 and time.time() - last > .5:
pg = i * THREADS / N_GAMES
if i == 0:
pg += 1 / 1000000
etr = (time.time() - start) * (1 / pg - 1)
print('Progress: {:.1f}%. Remaining: {}'
.format(pg * 100, str(timedelta(seconds=int(etr)))),
file=sys.stderr, end='\r')
last = time.time()
# Play a game
for line in play_game(engine, info_handler, module, selfplay_model):
example_queue.put(line)
example_queue.put(None)
if thread_id == 0:
print()
print('Finishing remaining threads...', file=sys.stderr)
示例4: initialize
# 需要导入模块: import chess [as 别名]
# 或者: from chess import uci [as 别名]
def initialize(self, bot_handler: Any) -> None:
self.config_info = bot_handler.get_config_info('chess')
try:
self.engine = chess.uci.popen_engine(
self.config_info['stockfish_location']
)
self.engine.uci()
except FileNotFoundError:
# It is helpful to allow for fake Stockfish locations if the bot
# runner is testing or knows they won't be using an engine.
print('That Stockfish doesn\'t exist. Continuing.')