def _init_random_maze(self):
# init goal position
goal = np.zeros_like(self._level)
while True:
row_idx = np.random.randint(0, self._level.shape[0])
col_idx = np.random.randint(0, self._level.shape[1])
if self._level[row_idx, col_idx] == 0:
goal[row_idx, col_idx] = 1
self._goal_pos = np.array([row_idx, col_idx])
break
# init player position
player = np.zeros_like(self._level)
while True:
row_idx = np.random.randint(0, self._level.shape[0])
col_idx = np.random.randint(0, self._level.shape[1])
if self._level[row_idx, col_idx] == 0 and goal[row_idx, col_idx] == 0:
player[row_idx, col_idx] = 1
self._player_pos = np.array([row_idx, col_idx])
break
# stack all together in depth (along third axis)
self._maze = np.dstack((self._level, goal, player))
评论列表
文章目录