Beispiel #1
0
def run_game(dir1, dir2, board_size=16, max_rounds=250, debug=False):
    c1 = CodeContainer.from_directory(dir1)
    c2 = CodeContainer.from_directory(dir2)
    game = Game([c1, c2], board_size=board_size, max_rounds=max_rounds, debug=debug, seed=None)
    while game.running:
        game.turn()
    return game.winner.value
Beispiel #2
0
def run_game(dir1,
             dir2,
             board_size=16,
             max_rounds=250,
             debug=False,
             random_pieces=0):
    c1 = CodeContainer.from_directory(dir1)
    c2 = CodeContainer.from_directory(dir2)
    game = Game([c1, c2],
                board_size=board_size,
                max_rounds=max_rounds,
                debug=debug,
                seed=None,
                random_pieces=random_pieces)
    while game.running:
        game.turn()
    return game.get_score()
Beispiel #3
0
    args.debug = args.debug == 'true'

    # The faulthandler makes certain errors (segfaults) have nicer stacktraces.
    faulthandler.enable()

    # This is where the interesting things start!

    # Every game needs 2 code containers with each team's bot code.
    code_container1 = CodeContainer.from_directory(args.player[0])
    code_container2 = CodeContainer.from_directory(
        args.player[1] if len(args.player) > 1 else args.player[0])

    # This is how you initialize a game,
    game = Game([code_container1, code_container2],
                board_size=args.board_size,
                max_rounds=args.max_rounds,
                seed=args.seed,
                debug=args.debug,
                colored_logs=not args.raw_text)

    # ... and the viewer.
    if args.basic_viewer == True:
        viewer = BasicViewer(args.board_size,
                             game.board_states,
                             colors=not args.raw_text)
    else:
        viewer = FancyViewer(args.board_size, game.board_states)

    # Here we check if the script is run using the -i flag.
    # If it is not, then we simply play the entire game.
    if not sys.flags.interactive:
        play_all(delay=float(args.delay),
Beispiel #4
0
        bot2 = int(bot2)

    with open(f"saved_weights/epoch{epoch1}.json") as f:
        weights1 = json.load(f)[bot1]

    with open(f"saved_weights/epoch{epoch2}.json") as f:
        weights2 = json.load(f)[bot2]

    r1 = Robot("test1", weights1)
    r2 = Robot("test2", weights2)
    c1 = CodeContainer.from_directory(r1.bot_directory)
    c2 = CodeContainer.from_directory(r2.bot_directory)

    game = Game([c1, c2],
                board_size=16,
                max_rounds=MAX_ROUNDS,
                random_pieces=0,
                debug=True,
                seed=None)

    start = time.time()
    while game.running:
        print('.', end='', flush=True)
        game.turn()
    print()
    end = time.time()
    print(f"Winner is {game.winner}")
    print(f"Time taken = {end - start}")
    viewer = FancyViewer(game.board_size, game.board_states, window_size=800)
    viewer.play(delay=0.04)
Beispiel #5
0
    p1 = sys.argv[1]
    p2 = sys.argv[2]

    c1 = CodeContainer.from_directory(p1)
    c2 = CodeContainer.from_directory(p2)

    for i in range(GAMES):
        if random.random() < 0.5:
            code = [c1, c2]
            swap = False
        else:
            code = [c2, c1]
            swap = True
        game = Game(code,
                    board_size=16,
                    max_rounds=MAX_ROUNDS,
                    debug=True,
                    seed=None,
                    random_pieces=2)

        while game.running:
            game.turn()
        if (game.winner == Team.WHITE) ^ swap:
            wins[0] += 1
        else:
            wins[1] += 1

        os.system("cls")
        print(f"{round((i+1)/GAMES*100, 2)}% complete.\nCurrent ratio:")
        print(f"{wins} --> {round(wins[0] / (wins[0] + wins[1]) * 100, 2)}%")
        bot1 = 0
        bot2 = 0
        with open(f"saved_weights/epoch{epoch1}.json") as f:
            weights1 = json.load(f)[bot1]

        with open(f"saved_weights/epoch{epoch2}.json") as f:
            weights2 = json.load(f)[bot2]

        r1 = Robot("test1", weights1)
        r2 = Robot("test2", weights2)
        c1 = CodeContainer.from_directory(r1.bot_directory)
        c2 = CodeContainer.from_directory(r2.bot_directory)

        game = Game([c1, c2],
                    board_size=16,
                    max_rounds=500,
                    debug=False,
                    seed=None)
        while game.running:
            game.turn()
        os.system("cls")
        print(f"{round(t/total*100, 2)}% complete.\nCurrent best:")
        r = 1 if game.winner == Team.WHITE else 0
        e1, e2 = update_elo(elos[x], elos[y], r)
        elos[x] = e1
        elos[y] = e2
        n = 10
        top = sorted(range(len(elos)), key=lambda i: elos[i], reverse=True)[:n]
        for i in range(n):
            print(f"{i+1}. {top[i] + epoch_start} - {round(elos[top[i]], 1)}",
                  flush=True)
Beispiel #7
0
                is_running = False

            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == stepButton:
                        run.step()

            manager.process_events(event)

        manager.update(time_delta)

        window_surface.blit(background, (0, 0))
        manager.draw_ui(window_surface)

        pygame.display.update()
    # run.viewer_thread.stop()
    run.viewer_poison_pill.set()
    sys.exit()
    # run.viewer_thread.join()
    

if __name__ == "__main__":
    args = sys.argv
    print(args)

    code_container1 = CodeContainer.from_directory(args[1])
    code_container2 = CodeContainer.from_directory(args[2])

    run.game = Game([code_container1, code_container2], board_size=GameConstants.BOARD_SIZE, max_rounds=GameConstants.MAX_ROUNDS, 
                seed=GameConstants.DEFAULT_SEED, debug=True, colored_logs=True)
    runGUI()