Exemple #1
0
selfplay = args.selfplay

"""
SOME INITS
"""
env_args = ((22,10), app)
game = Tetris(*env_args)

if selfplay:
    _agent_module = import_module('agents.'+agent_type)
    Agent = getattr(_agent_module,agent_type)
    agent = Agent(mcts_const, mcts_sims, tau=mcts_tau, env=Tetris, env_args=env_args, n_actions = 7)
    agent.set_root(game)

if save:
    saver = DataSaver(save_dir, save_file, cycle)

tracker = ScoreTracker()

"""
MAIN GAME LOOP
"""
while True:
    if interactive:
        game.printState()
        print('Current score:%d'%game.getScore())
        action = int(input('Play:'))

    elif selfplay:

        if printboard:
Exemple #2
0
if endless:
    ngames = 0

if selfplay:
    _agent_module = import_module('agents.' + agent_type)
    Agent = getattr(_agent_module, agent_type)
    agent = Agent(mcts_const,
                  mcts_sims,
                  tau=mcts_tau,
                  env=Tetris,
                  env_args=env_args,
                  n_actions=7)
    agent.update_root(game, ngames)

if save:
    saver = DataSaver(save_dir, save_file, cycle)
    saver_all = DataSaver(save_dir, 'tree', cycle)
    agent.saver = saver_all

tracker = ScoreTracker()
"""
MAIN GAME LOOP
"""
while True:
    if interactive:
        game.printState()
        print('Current score:%d' % game.getScore())
        action = int(input('Play:'))

    elif selfplay:
Exemple #3
0
    _agent_module = import_module('agents.' + args.agent_type)
    Agent = getattr(_agent_module, args.agent_type)
    agent_args = dict(
            sims=args.mcts_sims,
            env=Tetris,
            env_args=env_args,
            benchmark=args.benchmark,
            online=args.online,
            min_visit=args.min_visit)
    agent = Agent(**agent_args)
    agent.update_root(game)
else:
    agent = None

if args.save:
    saver = DataSaver(args.save_dir, args.save_file, args.cycle)

if args.save_tree:
    agent.saver = DataSaver(args.save_dir, 'tree', args.cycle)

tracker = ScoreTracker()

if args.gui:
    G = GUI()

if args.print_board_to_file:
    board_output = open('board_output', 'wb')

if args.realtime_status:
    _board = np.memmap('./tmp/board', dtype=np.int8, mode='w+', shape=(20, 10))
    _combo = np.memmap('./tmp/combo', dtype=np.int32, mode='w+', shape=(1, ))