Skip to content

Commit

Permalink
add flame life + bomb movement direction
Browse files Browse the repository at this point in the history
  • Loading branch information
fschlatt committed Jun 8, 2019
1 parent b6fd592 commit c77a202
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ It has the following format:
* Enemies: A list of three Ints, each in [9, 13]. Which agents are this agent's enemies. There are three here to be amenable to all variants of the game. When there are only two enemies like in the team competitions, the last Int will be the AgentDummy to reflect the fact that there are only two enemies.
* Bomb Blast Strength: An 11x11 numpy int array representing the bombs' blast strengths in the agent's view. Everything outside of its view will be fogged out.
* Bomb Life: An 11x11 numpy int array representing the bombs' life in the agent's view. Everything outside of its view will be fogged out.
* Bomb Movement Direction: An 11x11 numpy int array representing the bombs' movement direction (in terms of an agent's action space: 1 -> up, 2-> down etc...) in the agent's view. Everything outside of its view will be fogged out.
* Flame Life: An 11x11 numpy int array represnting the flames' life in the agent's view. Everything outside of its view will be fogged out.
* Message: (Team Radio only) A list of two Ints, each in [0, 8]. The message being relayed from the teammate. Both ints are zero when a teammate is dead or it's the first step. Otherwise they are in [1, 8].
8 changes: 4 additions & 4 deletions pommerman/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ class Flame(object):

def __init__(self, position, life=2):
self.position = position
self._life = life
self.life = life

def tick(self):
self._life -= 1
self.life -= 1

def is_dead(self):
return self._life == 0
return self.life == 0

def to_json(self):
return {"position": self.position, "life": self._life}
return {"position": self.position, "life": self.life}
2 changes: 1 addition & 1 deletion pommerman/envs/v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def act(self, obs):

def get_observations(self):
self.observations = self.model.get_observations(
self._board, self._agents, self._bombs,
self._board, self._agents, self._bombs, self._flames,
self._is_partially_observable, self._agent_view_size,
self._game_type, self._env)
for obs in self.observations:
Expand Down
25 changes: 22 additions & 3 deletions pommerman/forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def crossing(current, desired):

return curr_board, curr_agents, curr_bombs, curr_items, curr_flames

def get_observations(self, curr_board, agents, bombs,
def get_observations(self, curr_board, agents, bombs, flames,
is_partially_observable, agent_view_size,
game_type, game_env):
"""Gets the observations as an np.array of the visible squares.
Expand All @@ -499,14 +499,30 @@ def make_bomb_maps(position):
''' Makes an array of an agents bombs and the bombs attributes '''
blast_strengths = np.zeros((board_size, board_size))
life = np.zeros((board_size, board_size))
moving_direction = np.zeros((board_size, board_size))

for bomb in bombs:
x, y = bomb.position
if not is_partially_observable \
or in_view_range(position, x, y):
blast_strengths[(x, y)] = bomb.blast_strength
life[(x, y)] = bomb.life
return blast_strengths, life
if bomb.moving_direction is not None:
moving_direction[(x, y)] = bomb.moving_direction.value
else:
moving_direction[(x, y)] = 0
return blast_strengths, life, moving_direction

def make_flame_map(position):
''' Makes an array of an agents flame life'''
life = np.zeros((board_size, board_size))

for flame in flames:
x, y = flame.position
if not is_partially_observable \
or in_view_range(position, x, y):
life[(x, y)] = flame.life + 1
return life

def in_view_range(position, v_row, v_col):
'''Checks to see if a tile is in an agents viewing area'''
Expand Down Expand Up @@ -537,9 +553,12 @@ def in_view_range(position, v_row, v_col):
if not in_view_range(agent.position, row, col):
board[row, col] = constants.Item.Fog.value
agent_obs['board'] = board
bomb_blast_strengths, bomb_life = make_bomb_maps(agent.position)
bomb_blast_strengths, bomb_life, bomb_moving_direction = make_bomb_maps(agent.position)
agent_obs['bomb_blast_strength'] = bomb_blast_strengths
agent_obs['bomb_life'] = bomb_life
agent_obs['bomb_moving_direction'] = bomb_moving_direction
flame_life = make_flame_map(agent.position)
agent_obs['flame_life'] = flame_life
agent_obs['game_type'] = game_type.value
agent_obs['game_env'] = game_env

Expand Down

0 comments on commit c77a202

Please sign in to comment.