def reset(self): x = random.randint(0, self.maze.max_x - 1) y = random.randint(0, self.maze.max_y - 1) self.maze = Maze.build(bounds=(self.maze.max_x, self.maze.max_y)) if self.viewer is not None: self.viewer.set_maze(self.maze) return self.get_state()
def __init__(self, log_name='MazeEnv', maze=None): if maze is None: self.maze = Maze.build(bounds=(50, 50)) else: self.maze = Maze(bounds=(maze.max_x, maze.max_y), target=maze.target) # if MazeEnv.logger is None: # MazeEnv.logger = Logger("MazeEnv") # self.logger = Logger(log_name, show_in_console=False) self.viewer = None
def __init__(self, log_name='MazeEnv', maze=None): if maze is None: self.maze = Maze.build(bounds=(10, 10), block_cnt=20) else: self.maze = Maze( start=(maze.x, maze.y), bounds=(maze.max_x, maze.max_y), door=maze.door, blocks=maze.blocks) # if MazeEnv.logger is None: # MazeEnv.logger = Logger("MazeEnv") # self.logger = Logger(log_name, show_in_console=False) self.viewer = None
total_step) except Exception as e: print(e) if __name__ == "__main__": GLOBAL_NET_SCOPE = 'Global_Net' N_S = MazeEnv.state_space_dim N_A = MazeEnv.action_dim SESS = tf.Session() with tf.device("/cpu:0"): # OPT_A = tf.train.RMSPropOptimizer(LR_A, name='RMSPropA') # OPT_C = tf.train.RMSPropOptimizer(LR_C, name='RMSPropC') global_maze = Maze.build(bounds=(80, 80)) # sess, name, N_S, N_A, globalAC, maze=None GLOBAL_AC = A3CNet(SESS, GLOBAL_NET_SCOPE, N_S, N_A) # we only need its params workers = [] # Create worker for i in range(N_WORKERS): i_name = 'W_%i' % i # worker name workers.append( Worker(SESS, i_name, N_S, N_A, GLOBAL_AC, global_maze)) COORD = tf.train.Coordinator() SESS.run(tf.global_variables_initializer()) worker_threads = []
total_step) except Exception as e: print(e) if __name__ == "__main__": GLOBAL_NET_SCOPE = 'Global_Net' N_S = MazeEnv.state_space_dim N_A = MazeEnv.action_dim SESS = tf.Session() with tf.device("/cpu:0"): # OPT_A = tf.train.RMSPropOptimizer(LR_A, name='RMSPropA') # OPT_C = tf.train.RMSPropOptimizer(LR_C, name='RMSPropC') global_maze = Maze.build(bounds=(30, 30), block_cnt=200) # sess, name, N_S, N_A, globalAC, maze=None GLOBAL_AC = A3CNet(SESS, GLOBAL_NET_SCOPE, N_S, N_A) # we only need its params workers = [] # Create worker for i in range(N_WORKERS): i_name = 'W_%i' % i # worker name workers.append( Worker(SESS, i_name, N_S, N_A, GLOBAL_AC, global_maze)) COORD = tf.train.Coordinator() SESS.run(tf.global_variables_initializer()) worker_threads = []
def _calc_block_size(self): w, h = self.get_size() area_w = w * self._get_occupy() area_h = h * self._get_occupy() block_w = area_w / self.maze.max_x block_h = area_h / self.maze.max_y return (block_w, block_h) def viewer_run(): viewer = MazeViewer(Maze()) while True: viewer.render() if __name__ == '__main__': import time import random import logging maze = Maze.build((10, 10)) viewer = MazeViewer(maze) while True: dx, dy = random.randint(-1, 1), random.randint(-1, 1) print(dx, dy) maze.move(dx, dy) viewer.render() time.sleep(0.1)