def select_mode(): gui = visulization.GUI("select") pygame.display.update() random_controller = controller.ManualController(gui.get_robot()) while True: random_controller.key_handler() gui.draw() pygame.display.update()
def manual(action): gui = visulization.GUI() pygame.display.update() random_controller = controller.ManualController(gui.get_robot()) gui.draw() pygame.display.update() pygame.time.wait(1000) random_controller.control(action) gui.draw() pygame.display.update() pygame.time.wait(1000)
def random(): gui = visulization.GUI("problems/problem1.txt") pygame.display.update() random_controller = controller.RandomController(gui.get_robot()) nb_moves = 0 while True: nb_moves += 1 gui.draw() random_controller.control() pygame.display.update() pygame.time.wait(10) print "Job done in %d moves" % nb_moves
def value_iteration(): gui = visulization.GUI() pygame.display.update() mdp = controller.MDPController(gui.get_robot(), gui.get_window_size()) mdp.converge_utable() nb_moves = 0 while True: if len(mdp.dirty_tiles) == 0: break nb_moves += 1 gui.draw() mdp.decide_action("value iteration") pygame.display.update() pygame.time.wait(1000) print "Job done in %d moves" % nb_moves
import tensorflow as tf import pygame import visulization import controller import skimage.io import skimage.transform import skimage.exposure import skimage.color import numpy as np import model_tf GAME = visulization.GUI() CONTROLLER = controller.ManualController(GAME.get_robot()) ACTIONS = {"up": 0, "down": 1, "right": 2, "left": 3, "suck": 4} INDICES_TO_ACTIONS = {v: k for k, v in ACTIONS.iteritems()} def get_next_frame(action=None): global GAME, CONTROLLER if action is not None: CONTROLLER.control(action) GAME.draw() _img = pygame.surfarray.array3d(GAME.get_surface()) _img = np.array(_img) _img = skimage.color.rgb2gray(_img) _img = skimage.transform.resize(_img, (84, 84)) _img = skimage.exposure.rescale_intensity(_img, out_range=(0, 255)) s = (CONTROLLER.robot.get_tile_pos()[0], CONTROLLER.robot.get_tile_pos()[1], tuple(CONTROLLER.dirty_tiles)) return _img, CONTROLLER.reward_func(s), CONTROLLER.terminate()