Пример #1
0
def check_control(human_control=True):
    from PIL import Image
    from pathlib import Path
    from os.path import isdir
    home = str(Path.home())
    full_path = home + '/Desktop/Images/'
    print(full_path)
    count = 0

    game = MilkFactory(render=True,
                       speed=10,
                       human_control=human_control,
                       number_of_milk_robots=2,
                       number_of_fix_robots=1,
                       error_freq=0.01,
                       number_of_milks=2,
                       milk_speed=3,
                       number_of_exits=2,
                       human_control_robot=0,
                       debug=True,
                       action_combined_mode=False,
                       show_status=True)
    game.reset()
    num_of_agents = game.get_num_of_agents()

    while True:
        if not human_control:
            num_of_actions = game.get_num_of_actions()
            actions = []
            for i in range(num_of_agents):
                random_action = np.random.randint(0, num_of_actions)
                actions.append(random_action)

            print(actions)
            reward = game.step(actions)
            print(reward)
        else:
            game.render()

        next_state = Utils.process_state(game.get_state())
        next_map = Utils.process_state(game.get_map())

        # save state and map
        count = count + 1
        if isdir(full_path):
            img = Image.fromarray(next_state, 'L')
            img.save(full_path + str(count) + '_state.png')
            img = Image.fromarray(next_map, 'L')
            img.save(full_path + str(count) + '_map.png')

        is_terminal = game.is_terminal()

        if is_terminal:
            print("Total Score", game.total_score)
            break
Пример #2
0
def check_map():
    from PIL import Image
    from pathlib import Path
    home = str(Path.home())
    game = FoodCollector(render=True,
                         speed=60,
                         max_frames=10000,
                         frame_skip=1,
                         seed=None,
                         num_of_apples=1,
                         human_control=False,
                         debug=True)
    num_of_actions = game.get_num_of_actions()
    game.reset()
    full_path = home + '/Desktop/Images/'
    count = 0

    while True:
        random_action = np.random.randint(0, num_of_actions)
        reward = game.step(random_action)
        print(reward)
        next_state = Utils.process_state(game.get_state())
        is_terminal = game.is_terminal()

        # save state and map
        count = count + 1
        img = Image.fromarray(next_state, 'L')
        img.save(full_path + str(count) + '.png')

        if is_terminal:
            print("Total Score", game.total_score)
            game.reset()
Пример #3
0
def check_map():
    from PIL import Image
    from pathlib import Path
    home = str(Path.home())
    game = MountainCar(render=False, graphical_state=True)
    num_of_actions = game.get_num_of_actions()
    game.reset()
    full_path = home + '/Desktop/Images/'
    count = 0

    while True:
        random_action = np.random.randint(0, num_of_actions)
        reward = game.step(random_action)
        print(reward)
        next_state = Utils.process_state(game.get_state())
        is_terminal = game.is_terminal()

        # save state and map
        count = count + 1
        img = Image.fromarray(next_state, 'L')
        img.save(full_path + str(count) +'.png')

        if is_terminal:
            print("Total Score", game.total_score)
            game.reset()
            break