fsmosca / combat

A python script to run engine vs engine game matches.
GNU General Public License v3.0
5 stars 2 forks source link

For few rounds played the openings from PGN are always the same - fix proposed #6

Closed jlrdh closed 4 years ago

jlrdh commented 4 years ago

Hello, when using Combat, I figured that the same openings are picked given a opening PGN file.

In function get_game_list, the current code stops adding games from the opening file once it has reached the max_round value and only then the random shuffling takes place :

_if file_suffix == '.pgn': with open(fn) as pgn: while True: game = chess.pgn.read_game(pgn) if game is None: break games.append(game) if len(games) >= max_round: break else: with open(fn) as pos: for lines in pos: line = lines.strip() board = chess.Board(line) game = chess.pgn.Game() game = game.from_board(board) games.append(game) if len(games) >= maxround: break

I've modified it such that the opening file is opened entirely, then the shuffling takes place, and only then the first max_round games are kept:

_if file_suffix == '.pgn':
    with open(fn) as pgn:
        while True:
            game = chess.pgn.read_game(pgn)
            if game is None:
                break
            games.append(game)
else:
    with open(fn) as pos:
        for lines in pos:
            line = lines.strip()
            board = chess.Board(line)
            game = chess.pgn.Game()
            game = game.from_board(board)
            games.append(game)

if randomize_pos:
    random.shuffle(games)

elapse = time.perf_counter()*1000000000 - t1

if len(games) < max_round:
    logger.info('Number of positions in the file {} are below max_round {}!'.format(len(games),max_round ))
logger.info('status: done, games prepared: {}, elapse: {}\n'.format(len(games), get_time_h_mm_ss_ms(elapse)))
logger.info('maxround: {}, len games maxround: {}\n'.format(max_round, len(games[:max_round])))
return games[:max_round]_

Hope this will help improve the Combat script.

fsmosca commented 4 years ago

Thank you, I will revise it.