Ejemplo n.º 1
0
def _run_game(black_player, white_player, referee, game_num):
    gamefile, logfile = get_log_file_name(black_player, white_player, game_num, referee)
    with GomokuGameHandler(black_player, white_player, log_file=logfile, game_file=gamefile,
                           board_size=(7, 7)) as (black_round, white_round, board):
        for _ in range(11 * 11 // 2):
            try:
                white_round()
                # time.sleep(0.3)
                black_round()
                # time.sleep(0.3)
            except Win as e:
                log('[end game] %s' % e)
                # time.sleep(10)
                if e.winner == black_round.player:
                    return (referee.palyerName(black_round.player), referee.palyerName(white_round.player),
                            black_round.time_remaining, white_round.time_remaining)
                else:
                    return (referee.palyerName(white_round.player), referee.palyerName(black_round.player),
                            black_round.time_remaining, white_round.time_remaining)

            except Lose as e:
                log('[end game] %s' % e)
                # time.sleep(10)
                if e.loser == black_round.player:
                    return (referee.palyerName(white_round.player), referee.palyerName(black_round.player),
                            black_round.time_remaining, white_round.time_remaining)
                else:
                    return (referee.palyerName(black_round.player), referee.palyerName(white_round.player),
                            black_round.time_remaining, white_round.time_remaining)
Ejemplo n.º 2
0
        player1 = globals()[player1].Ai
        player2 = globals()[player2].Ai

        h = Bo4Handler(player1, player2, board_size=(7, 7))  # change board_size to 13,13

        for black_player, white_player in h.get_player_instance():
            print(black_player.color)
            print(type(black_player), type(white_player))


            with GomokuGameHandler(black_player, white_player, board_size=(7, 7)) as (
                black_round, white_round, board):
                try:
                    for _ in range(11 * 11 // 2):
                        black_round()
                        time.sleep(0.1)
                        white_round()
                        time.sleep(0.1)

                except Win as e:
                    h.handle_win_lose(e)
                    h.handle_time(black_round.get_run_time(),white_round.get_run_time())
                    log('[end game] %s' % e)
                except Lose as e:
                    h.handle_win_lose(e)
                    h.handle_time(black_round.get_run_time(),white_round.get_run_time())
                    log('[end game] %s' % e)

        h.print_state()
Ejemplo n.º 3
0
white_player = MCTsAi("white", board_size=(13, 13))
# black_player = FakeAi("black", board_size=(13, 13))
black_player = NormalAi("black", board_size=(13, 13))
=======
black_player = MCTsAi("black", board_size=(13, 13))
white_player = NormalAi("white", board_size=(13, 13))
>>>>>>> 6aeca25084a81bb0cbe3b878b7240f6e0de7d1a1

with GomokuGameHandler(black_player, white_player, board_size=(13, 13), game_file='ai1_vs_ai2.json',
                       log_file='ai1_vs_ai2.txt') as (black_round, white_round, board):
    try:
        for _ in range(13 * 13 // 2):
            black_round()
            time.sleep(0.3)
            white_round()
            time.sleep(0.3)

    except Win as e:
        time.sleep(5)
        log('[end game] %s' % e)

    except Lose as e:
        time.sleep(5)
        log('[end game] %s' % e)

    except KeyboardInterrupt as e:
        log('[end game] KeyboardInterrupt!! , stop by user')

    except Exception as e:
        log('[end game] Terminated by unexpected exception!! %s' % e)