mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-22 03:31:35 +02:00
Shadow casting, now debugged
This commit is contained in:
@ -306,10 +306,12 @@ class BaseFactory(gym.Env):
|
||||
obs = self._obs_cube
|
||||
|
||||
if self.cast_shadows:
|
||||
slices = [l_slice.slice != c.OCCUPIED_CELL.value for l_slice in self._slices if l_slice.is_blocking_light]
|
||||
light_block_map = Map((np.prod(slices, axis=0) != True).astype(int))
|
||||
light_block_map = light_block_map.do_fov(*agent.pos, max(self._level_shape))
|
||||
obs = ((obs * light_block_map)).astype(int)
|
||||
obs_block_light = [obs[idx] != c.OCCUPIED_CELL.value for idx, slice
|
||||
in enumerate(self._slices) if slice.is_blocking_light]
|
||||
light_block_map = Map((np.prod(obs_block_light, axis=0) != True).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:
|
||||
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
|
||||
def clear_temp_sate(self):
|
||||
# for attr in self.__dict__:
|
||||
# if attr.startswith('temp'):
|
||||
self.temp_collisions = []
|
||||
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):
|
||||
self.data = map_array
|
||||
self.width, self.height = map_array.shape
|
||||
self.light = np.zeros_like(self.data)
|
||||
self.flag = 0
|
||||
self.light = np.full_like(self.data, c.FREE_CELL.value)
|
||||
self.flag = c.FREE_CELL.value
|
||||
|
||||
def blocked(self, x, y):
|
||||
return (x < 0 or y < 0
|
||||
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):
|
||||
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,
|
||||
mult_array[0, oct], mult_array[1, oct],
|
||||
mult_array[2, oct], mult_array[3, oct], 0)
|
||||
self.light[x, y] = self.flag
|
||||
return self.light
|
||||
|
Reference in New Issue
Block a user