def _init_grid(self):
""" Initializes the grid. Currently works best for multiples of 3 which
are also odd. For now let's only test on 9x9 grids. """
self.grid.fill(OPEN)
w1 = np.maximum((self.length/3), 1)
w2 = np.minimum(2*(self.length/3), self.length)
self.grid[:, w1:w2].fill(WALL)
self.grid[self.length/2, :].fill(OPEN)
sx = np.random.randint(0, self.length)
sy = np.random.randint(0, w1)
gx = np.random.randint(0, self.length)
gy = np.random.randint(w2, self.length)
s_agent = (sx,sy)
s_goal = (gx,gy)
assert s_agent != s_goal
assert self.grid[s_agent] != WALL
assert self.grid[s_goal] != WALL
self.grid[s_agent] = AGENT
self.grid[s_goal] = GOAL
s_start = s_agent
return s_start, s_agent, s_goal
评论列表
文章目录