diff options
author | Peter Ward <peteraward@gmail.com> | 2014-04-12 12:35:09 +1000 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2014-04-12 12:35:09 +1000 |
commit | 2b2f54a36ef8eaa4b9f39fc319a2e7d664be1cc5 (patch) | |
tree | 839e2dbe24add65584c5b8868262908d6bf54083 | |
parent | 32163e6691e1da7b6adfde97314be40ae57120ec (diff) |
Add factories_by_player, handle non-movement actions in expected_position.
-rw-r--r-- | robots/state.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/robots/state.py b/robots/state.py index 8a47139..453cb7b 100644 --- a/robots/state.py +++ b/robots/state.py @@ -86,6 +86,14 @@ class GameState: } @property + def factories_by_player(self): + result = defaultdict(list) + for p in self.factories: + player = self.allegiances.get(p) + result[player].append(p) + return result + + @property def n_alive_players(self): """How many players are still alive.""" return sum( @@ -121,12 +129,14 @@ class GameState: Of course, combat (and possibly other factors in the future) may influence whether it actually ends up at the returned position. """ + if action not in DIRECTIONS: + return (x, y) + dx, dy = DIRECTIONS[action] nx = (x + dx) % self.width ny = (y + dy) % self.height - if self.cities[ny][nx] in City.traversable: - x = nx - y = ny + if self.cities[ny][nx] not in City.traversable: + return (x, y) - return (x, y) + return (nx, ny) |