Skip to content

Commit

Permalink
Changed the grid a bit and added baddie to occupy center row
Browse files Browse the repository at this point in the history
  • Loading branch information
rusu24edward committed Apr 29, 2024
1 parent 34550ae commit 1386e2c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 63 deletions.
120 changes: 63 additions & 57 deletions abmarl/examples/sim/pacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ def step(self, action_dict, **kwargs):
self.rewards['pacman'] += self.reward_scheme['entropy']
if np.array_equal(self.pacman.position, np.array([9, 0])):
self.grid.remove(self.pacman, (9, 0))
self.grid.place(self.pacman, (9, 20))
elif np.array_equal(self.pacman.position, np.array([9, 20])):
self.grid.remove(self.pacman, (9, 20))
self.grid.place(self.pacman, (9, 18))
elif np.array_equal(self.pacman.position, np.array([9, 18])):
self.grid.remove(self.pacman, (9, 18))
self.grid.place(self.pacman, (9, 0))

# Compute overlaps with pacman
Expand All @@ -264,6 +264,7 @@ def step(self, action_dict, **kwargs):
'baddie_1': {'move': 0},
'baddie_2': {'move': 0},
'baddie_3': {'move': 0},
'baddie_4': {'move': 0},
}
if self.step_count % 10 == 0:
action_dict['baddie_0']['move'] = 3
Expand All @@ -278,33 +279,38 @@ def step(self, action_dict, **kwargs):
action_dict['baddie_0']['move'] = 4
action_dict['baddie_1']['move'] = 4
if self.step_count % 14 == 0:
action_dict['baddie_2']['move'] = 3
action_dict['baddie_3']['move'] = 1
action_dict['baddie_3']['move'] = 3
action_dict['baddie_4']['move'] = 1
elif self.step_count % 14 == 3:
action_dict['baddie_2']['move'] = 2
action_dict['baddie_3']['move'] = 2
action_dict['baddie_4']['move'] = 2
elif self.step_count % 14 == 7:
action_dict['baddie_2']['move'] = 1
action_dict['baddie_3']['move'] = 3
action_dict['baddie_3']['move'] = 1
action_dict['baddie_4']['move'] = 3
elif self.step_count % 14 == 9:
action_dict['baddie_2']['move'] = 4
action_dict['baddie_3']['move'] = 4
action_dict['baddie_4']['move'] = 4
elif self.step_count % 14 == 11:
action_dict['baddie_2']['move'] = 1
action_dict['baddie_3']['move'] = 3
action_dict['baddie_3']['move'] = 1
action_dict['baddie_4']['move'] = 3
elif self.step_count % 14 == 12:
action_dict['baddie_2']['move'] = 4
action_dict['baddie_3']['move'] = 4
action_dict['baddie_4']['move'] = 4
if self.step_count % 13 == 0:
if self.agents['baddie_2'].orientation == 3:
action_dict['baddie_2']['move'] = 1
else:
action_dict['baddie_2']['move'] = 3

# Now move the baddies and compute overlaps with pacman
for agent_id, action in action_dict.items():
agent = self.agents[agent_id]
move_result = self.move_actor.process_action(agent, action, **kwargs)
if np.array_equal(agent.position, np.array([9, 0])):
self.grid.remove(agent, (9, 0))
self.grid.place(agent, (9, 20))
elif np.array_equal(agent.position, np.array([9, 20])):
self.grid.remove(agent, (9, 20))
self.grid.place(agent, (9, 18))
elif np.array_equal(agent.position, np.array([9, 18])):
self.grid.remove(agent, (9, 18))
self.grid.place(agent, (9, 0))

# Compute overlaps with pacman
Expand All @@ -326,46 +332,46 @@ def example_grid(self):
An example grid for playing the pacman game.
"""
return np.array([
['_', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W',
'W', 'W', 'W', 'W', 'W', 'W', '_'],
['_', 'W', 'B', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'B', 'W', '_'],
['_', 'W', 'F', 'W', 'W', 'F', 'W', 'W', 'W', 'F', 'W', 'F', 'W', 'W',
'W', 'F', 'W', 'W', 'F', 'W', '_'],
['_', 'W', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'F', 'W', '_'],
['_', 'W', 'F', 'W', 'W', 'F', 'W', 'F', 'W', 'W', 'W', 'W', 'W', 'F',
'W', 'F', 'W', 'W', 'F', 'W', '_'],
['_', 'W', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'W', 'F', 'F', 'F', 'F', 'W', '_'],
['_', 'W', 'W', 'W', 'W', 'F', 'W', 'W', 'W', '_', 'W', '_', 'W', 'W',
'W', 'F', 'W', 'W', 'W', 'W', '_'],
['_', '_', '_', '_', 'W', 'F', 'W', '_', '_', '_', '_', '_', '_', '_',
'W', 'F', 'W', '_', '_', '_', '_'],
['W', 'W', 'W', 'W', 'W', 'F', 'W', '_', 'W', 'W', 'F', 'W', 'W', '_',
'W', 'F', 'W', 'W', 'W', 'W', 'W'],
['_', '_', '_', '_', '_', 'F', '_', '_', '_', 'F', 'F', 'F', '_', '_',
'_', 'F', '_', '_', '_', '_', '_'],
['W', 'W', 'W', 'W', 'W', 'F', 'W', '_', 'W', 'W', 'F', 'W', 'W', '_',
'W', 'F', 'W', 'W', 'W', 'W', 'W'],
['_', '_', '_', '_', 'W', 'F', 'W', '_', '_', '_', '_', '_', '_', '_',
'W', 'F', 'W', '_', '_', '_', '_'],
['_', 'W', 'W', 'W', 'W', 'F', 'W', '_', 'W', 'W', 'W', 'W', 'W', '_',
'W', 'F', 'W', 'W', 'W', 'W', '_'],
['_', 'W', 'B', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'B', 'W', '_'],
['_', 'W', 'F', 'W', 'W', 'F', 'W', 'W', 'W', 'F', 'W', 'F', 'W', 'W',
'W', 'F', 'W', 'W', 'F', 'W', '_'],
['_', 'W', 'F', 'F', 'W', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F',
'F', 'F', 'W', 'F', 'F', 'W', '_'],
['_', 'W', 'W', 'F', 'W', 'F', 'W', 'F', 'W', 'W', 'W', 'W', 'W', 'F',
'W', 'F', 'W', 'F', 'W', 'W', '_'],
['_', 'W', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'W', 'F', 'F', 'F', 'F', 'W', '_'],
['_', 'W', 'F', 'W', 'W', 'W', 'W', 'W', 'W', 'F', 'W', 'F', 'W', 'W',
'W', 'W', 'W', 'W', 'F', 'W', '_'],
['_', 'W', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'F', 'W', '_'],
['_', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W',
'W', 'W', 'W', 'W', 'W', 'W', '_'],
['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W',
'W', 'W', 'W', 'W', 'W', 'W'],
['W', 'B', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'B', 'W'],
['W', 'F', 'W', 'W', 'F', 'W', 'W', 'W', 'F', 'W', 'F', 'W', 'W',
'W', 'F', 'W', 'W', 'F', 'W'],
['W', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'F', 'W'],
['W', 'F', 'W', 'W', 'F', 'W', 'F', 'W', 'W', 'W', 'W', 'W', 'F',
'W', 'F', 'W', 'W', 'F', 'W'],
['W', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'W', 'F', 'F', 'F', 'F', 'W'],
['W', 'W', 'W', 'W', 'F', 'W', 'W', 'W', '_', 'W', '_', 'W', 'W',
'W', 'F', 'W', 'W', 'W', 'W'],
['W', 'F', 'F', 'W', 'F', 'W', '_', '_', '_', '_', '_', '_', '_',
'W', 'F', 'W', 'F', 'F', 'W'],
['W', 'F', 'F', 'W', 'F', 'W', '_', 'W', 'W', 'F', 'W', 'W', '_',
'W', 'F', 'W', 'F', 'F', 'W'],
['_', '_', '_', '_', 'F', '_', '_', 'W', 'F', 'F', 'F', 'W', 'B',
'_', 'F', '_', '_', '_', '_'],
['W', 'F', 'F', 'W', 'F', 'W', '_', 'W', 'W', 'W', 'W', 'W', '_',
'W', 'F', 'W', 'F', 'F', 'W'],
['W', 'F', 'F', 'W', 'F', 'W', '_', '_', '_', '_', '_', '_', '_',
'W', 'F', 'W', 'F', 'F', 'W'],
['W', 'W', 'W', 'W', 'F', 'W', '_', 'W', 'W', 'W', 'W', 'W', '_',
'W', 'F', 'W', 'W', 'W', 'W'],
['W', 'B', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'B', 'W'],
['W', 'F', 'W', 'W', 'F', 'W', 'W', 'W', 'F', 'W', 'F', 'W', 'W',
'W', 'F', 'W', 'W', 'F', 'W'],
['W', 'F', 'F', 'W', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F',
'F', 'F', 'W', 'F', 'F', 'W'],
['W', 'W', 'F', 'W', 'F', 'W', 'F', 'W', 'W', 'W', 'W', 'W', 'F',
'W', 'F', 'W', 'F', 'W', 'W'],
['W', 'F', 'F', 'F', 'F', 'W', 'F', 'F', 'F', 'W', 'F', 'F', 'F',
'W', 'F', 'F', 'F', 'F', 'W'],
['W', 'F', 'W', 'W', 'W', 'W', 'W', 'W', 'F', 'W', 'F', 'W', 'W',
'W', 'W', 'W', 'W', 'F', 'W'],
['W', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F',
'F', 'F', 'F', 'F', 'F', 'W'],
['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W',
'W', 'W', 'W', 'W', 'W', 'W'],
])
12 changes: 6 additions & 6 deletions examples/rllib_pacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


object_registry = {
# 'P': lambda n: PacmanAgent(
# id='pacman',
# encoding=1,
# view_range=2,
# render_color='yellow',
# ),
'P': lambda n: PacmanAgent(
id='pacman',
encoding=1,
view_range=2,
render_color='yellow',
),
'W': lambda n: WallAgent(
id=f'wall_{n}',
encoding=2,
Expand Down

0 comments on commit 1386e2c

Please sign in to comment.