Exemple #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
Exemple #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()
Exemple #3
0
                        type=int,
                        help="Override the board size for faster games.")
    parser.add_argument('--seed',
                        default=GameConstants.DEFAULT_SEED,
                        type=int,
                        help="Override the seed used for random.")
    args = parser.parse_args()
    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,
Exemple #4
0
        epoch1, bot1 = epoch1.split("/")
        bot1 = int(bot1)

    if "/" in epoch2:
        epoch2, bot2 = epoch2.split("/")
        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()
Exemple #5
0
                seed=None)
    while game.running:
        game.turn()
    return game.winner.value


if __name__ == "__main__":
    MAX_ROUNDS = 250
    GAMES = 20

    wins = [0, 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)
Exemple #6
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()
Exemple #7
0
##    if len(sys.argv) >= 2:
##        epoch = sys.argv[1]
##    else:
##        epoch = 0
##        while os.path.isfile(f"saved_weights/epoch{epoch}.json"):
##            epoch += 1
##        epoch -= 1
##        print(f"Using epoch {epoch}")
##    
##    with open(f"saved_weights/epoch{epoch}.json") as f:
##        weights = json.load(f)[0]
##        
##    r1 = Robot("test1", weights)
##    c1 = CodeContainer.from_directory(r1.bot_directory)
    c1 = CodeContainer.from_directory("testbot")
    c2 = CodeContainer.from_directory("examplefuncsplayer")
    w = 0
    l = 0
    for test in range(10):
        game = Game([c1, c2], board_size=16, max_rounds=250, debug=False, seed=None)
        while game.running:
            game.turn()
        if game.winner == Team.WHITE:
            w += 1
        else:
            l += 1
        print(round(w/(w+l)*100, 2))
    viewer = FancyViewer(game.board_size, game.board_states, window_size=800)
    viewer.play(delay=0.5)