Shadow casting, now debugged
This commit is contained in:
@ -306,10 +306,12 @@ class BaseFactory(gym.Env):
|
|||||||
obs = self._obs_cube
|
obs = self._obs_cube
|
||||||
|
|
||||||
if self.cast_shadows:
|
if self.cast_shadows:
|
||||||
slices = [l_slice.slice != c.OCCUPIED_CELL.value for l_slice in self._slices if l_slice.is_blocking_light]
|
obs_block_light = [obs[idx] != c.OCCUPIED_CELL.value for idx, slice
|
||||||
light_block_map = Map((np.prod(slices, axis=0) != True).astype(int))
|
in enumerate(self._slices) if slice.is_blocking_light]
|
||||||
light_block_map = light_block_map.do_fov(*agent.pos, max(self._level_shape))
|
light_block_map = Map((np.prod(obs_block_light, axis=0) != True).astype(int))
|
||||||
obs = ((obs * light_block_map)).astype(int)
|
light_block_map = light_block_map.do_fov(self.pomdp_radius, self.pomdp_radius, max(self._level_shape))
|
||||||
|
agent.temp_light_map = light_block_map
|
||||||
|
obs = (obs * light_block_map) - ((1 - light_block_map) * obs[self._slices.get_idx_by_name(c.LEVEL.name)])
|
||||||
|
|
||||||
if self.combin_agent_slices_in_obs and self.n_agents > 1:
|
if self.combin_agent_slices_in_obs and self.n_agents > 1:
|
||||||
agent_obs = np.sum(obs[[key for key, l_slice in self._slices.items() if c.AGENT.name in l_slice.name and
|
agent_obs = np.sum(obs[[key for key, l_slice in self._slices.items() if c.AGENT.name in l_slice.name and
|
||||||
|
@ -263,6 +263,9 @@ class Agent(MoveableEntity):
|
|||||||
|
|
||||||
# noinspection PyAttributeOutsideInit
|
# noinspection PyAttributeOutsideInit
|
||||||
def clear_temp_sate(self):
|
def clear_temp_sate(self):
|
||||||
|
# for attr in self.__dict__:
|
||||||
|
# if attr.startswith('temp'):
|
||||||
self.temp_collisions = []
|
self.temp_collisions = []
|
||||||
self.temp_valid = None
|
self.temp_valid = None
|
||||||
self.temp_action = -1
|
self.temp_action = -1
|
||||||
|
self.temp_light_map = None
|
||||||
|
@ -17,13 +17,13 @@ class Map(object):
|
|||||||
def __init__(self, map_array: np.ndarray):
|
def __init__(self, map_array: np.ndarray):
|
||||||
self.data = map_array
|
self.data = map_array
|
||||||
self.width, self.height = map_array.shape
|
self.width, self.height = map_array.shape
|
||||||
self.light = np.zeros_like(self.data)
|
self.light = np.full_like(self.data, c.FREE_CELL.value)
|
||||||
self.flag = 0
|
self.flag = c.FREE_CELL.value
|
||||||
|
|
||||||
def blocked(self, x, y):
|
def blocked(self, x, y):
|
||||||
return (x < 0 or y < 0
|
return (x < 0 or y < 0
|
||||||
or x >= self.width or y >= self.height
|
or x >= self.width or y >= self.height
|
||||||
or self.data[x, y] == c.OCCUPIED_CELL)
|
or self.data[x, y] == c.OCCUPIED_CELL.value)
|
||||||
|
|
||||||
def lit(self, x, y):
|
def lit(self, x, y):
|
||||||
return self.light[x, y] == self.flag
|
return self.light[x, y] == self.flag
|
||||||
@ -82,4 +82,5 @@ class Map(object):
|
|||||||
self._cast_light(x, y, 1, 1.0, 0.0, radius,
|
self._cast_light(x, y, 1, 1.0, 0.0, radius,
|
||||||
mult_array[0, oct], mult_array[1, oct],
|
mult_array[0, oct], mult_array[1, oct],
|
||||||
mult_array[2, oct], mult_array[3, oct], 0)
|
mult_array[2, oct], mult_array[3, oct], 0)
|
||||||
|
self.light[x, y] = self.flag
|
||||||
return self.light
|
return self.light
|
||||||
|
2
main.py
2
main.py
@ -106,7 +106,7 @@ if __name__ == '__main__':
|
|||||||
for modeL_type in [A2C, PPO, RegDQN, DQN]: # , QRDQN]:
|
for modeL_type in [A2C, PPO, RegDQN, DQN]: # , QRDQN]:
|
||||||
for seed in range(3):
|
for seed in range(3):
|
||||||
|
|
||||||
with SimpleFactory(n_agents=1, dirt_properties=dirt_props, pomdp_radius=4, max_steps=400, parse_doors=False,
|
with SimpleFactory(n_agents=1, dirt_properties=dirt_props, pomdp_radius=2, max_steps=400, parse_doors=True,
|
||||||
movement_properties=move_props, level_name='rooms', frames_to_stack=0,
|
movement_properties=move_props, level_name='rooms', frames_to_stack=0,
|
||||||
omit_agent_slice_in_obs=True, combin_agent_slices_in_obs=True, record_episodes=False,
|
omit_agent_slice_in_obs=True, combin_agent_slices_in_obs=True, record_episodes=False,
|
||||||
cast_shadows=True,
|
cast_shadows=True,
|
||||||
|
@ -14,7 +14,7 @@ warnings.filterwarnings('ignore', category=UserWarning)
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
model_name = 'PPO_1626384768'
|
model_name = 'A2C_1627392692'
|
||||||
run_id = 0
|
run_id = 0
|
||||||
out_path = Path(__file__).parent / 'debug_out'
|
out_path = Path(__file__).parent / 'debug_out'
|
||||||
model_path = out_path / model_name
|
model_path = out_path / model_name
|
||||||
@ -33,5 +33,5 @@ if __name__ == '__main__':
|
|||||||
this_model = model_files[0]
|
this_model = model_files[0]
|
||||||
|
|
||||||
model = PPO.load(this_model)
|
model = PPO.load(this_model)
|
||||||
evaluation_result = evaluate_policy(model, env, n_eval_episodes=100, deterministic=True, render=True)
|
evaluation_result = evaluate_policy(model, env, n_eval_episodes=100, deterministic=False, render=True)
|
||||||
print(evaluation_result)
|
print(evaluation_result)
|
||||||
|
Reference in New Issue
Block a user