def main(): white_bot_name, black_bot_name = 'TroutBot', 'StrangeFish' game = LocalGame() try: winner_color, win_reason, history = play_local_game( TroutBot(), StrangeFish(*multiprocessing_strategies.create_strategy()), game=game) winner = 'Draw' if winner_color is None else chess.COLOR_NAMES[ winner_color] except: traceback.print_exc() game.end() winner = 'ERROR' history = game.get_game_history() print('Game Over!') print('Winner: {}!'.format(winner)) timestamp = datetime.now().strftime('%Y_%m_%d-%H_%M_%S') replay_path = '{}-{}-{}-{}.json'.format(white_bot_name, black_bot_name, winner, timestamp) print('Saving replay to {}...'.format(replay_path)) history.save(replay_path)
def bot_match(white_path, black_path): game = reconchess.LocalGame(900) _, white = reconchess.load_player(white_path) _, black = reconchess.load_player(black_path) winner_color, win_reason, history = reconchess.play_local_game(white(), black(), game=game) winner = "Draw" if winner_color is None else chess.COLOR_NAMES[winner_color] print("Game Over!") print(f"Winner: {winner}! ({win_reason})") Replay.from_history(history).play_sync()
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('white_bot_path', help='path to white bot source file') parser.add_argument('black_bot_path', help='path to black bot source file') parser.add_argument( '--seconds_per_player', default=900, type=float, help='number of seconds each player has to play the entire game.') args = parser.parse_args() white_bot_name, white_player_cls = load_player(args.white_bot_path) black_bot_name, black_player_cls = load_player(args.black_bot_path) game = LocalGame(args.seconds_per_player) try: winner_color, win_reason, history = play_local_game(white_player_cls(), black_player_cls(), game=game) winner = 'Draw' if winner_color is None else chess.COLOR_NAMES[ winner_color] except: traceback.print_exc() game.end() winner = 'ERROR' history = game.get_game_history() print('Game Over!') print('Winner: {}!'.format(winner)) timestamp = datetime.datetime.now().strftime('%Y_%m_%d-%H_%M_%S') replay_path = '{}-{}-{}-{}.json'.format(white_bot_name, black_bot_name, winner, timestamp) print('Saving replay to {}...'.format(replay_path)) history.save(replay_path)
import chess from reconchess import load_player, play_local_game white_win = 0 black_win = 0 parser = argparse.ArgumentParser() parser.add_argument('white_bot_path', help='path to white bot source file') parser.add_argument('black_bot_path', help='path to black bot source file') args = parser.parse_args() for i in range(100): white_bot_name, white_player_cls = load_player(args.white_bot_path) black_bot_name, black_player_cls = load_player(args.black_bot_path) winner_color, win_reason, history = play_local_game( white_player_cls(), black_player_cls()) print('Game Over!') if winner_color is not None: print('{} won because of {}!'.format( white_bot_name if winner_color else black_bot_name, win_reason)) else: print('Draw!') winner = 'Draw' if winner_color is None else chess.COLOR_NAMES[winner_color] if winner_color == chess.WHITE: white_win += 1 elif winner_color == chess.BLACK: black_win += 1
def play(p1, p2): winner_color, win_reason, history = reconchess.play_local_game(p1(), p2()) winner = "Draw" if winner_color is None else chess.COLOR_NAMES[winner_color] print("Game Over!") print(f"Winner: {winner}! ({win_reason})")