Skip to content

Commit

Permalink
Merge pull request #762 from otizonaizit/homezone_only_valid
Browse files Browse the repository at this point in the history
make bot.homezone a sequence of valid positions without walls
  • Loading branch information
Debilski authored Aug 4, 2023
2 parents 0be26ae + da40281 commit 756bd7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pelita/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def _ensure_set_tuples(set):
return {tuple(item) for item in set}


def create_homezones(shape):
def create_homezones(shape, walls):
width, height = shape
return [
{(x, y) for x in range(0, width // 2)
for y in range(0, height)},
for y in range(0, height) if (x, y) not in walls},
{(x, y) for x in range(width // 2, width)
for y in range(0, height)}
for y in range(0, height) if (x, y) not in walls}
]


Expand Down Expand Up @@ -104,7 +104,7 @@ def set_initial(self, team_id, game_state):
self._initial_positions = layout.initial_positions(self._walls, self._shape)

# Cache the homezone so that we don’t have to create it at each step
self._homezone = create_homezones(self._shape)
self._homezone = create_homezones(self._shape, self._walls)

return self.team_name

Expand Down
2 changes: 1 addition & 1 deletion pelita/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def split_food(width, food):
bot = make_bots(walls=layout['walls'].copy(),
shape=layout['shape'],
initial_positions=initial_positions(layout['walls'], layout['shape']),
homezone=create_homezones(layout['shape']),
homezone=create_homezones(layout['shape'], layout['walls']),
team=team,
enemy=enemy,
round=round,
Expand Down
6 changes: 4 additions & 2 deletions test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,12 @@ def test_bot_attributes():
homezones = [[], []]
homezones[0] = [(x, y)
for x in range(0, width // 2)
for y in range(0, height)]
for y in range(0, height)
if (x, y) not in parsed['walls']]
homezones[1] = [(x, y)
for x in range(width // 2, width)
for y in range(0, height)]
for y in range(0, height)
if (x, y) not in parsed['walls']]

assert set(homezones[0]) & set(homezones[1]) == set()

Expand Down

0 comments on commit 756bd7b

Please sign in to comment.