Exemple #1
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),
                 keep_history=args.raw_text,
                 real_time=not args.debug)

    else:
        # print out help message!
        print("Run step() to step through the game.")
        print("You also have access to the variables: game, viewer")
Exemple #2
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)