From 2b2f54a36ef8eaa4b9f39fc319a2e7d664be1cc5 Mon Sep 17 00:00:00 2001 From: Peter Ward Date: Sat, 12 Apr 2014 12:35:09 +1000 Subject: Add factories_by_player, handle non-movement actions in expected_position. --- robots/state.py | 18 ++++++++++++++---- 1 file 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 @@ -85,6 +85,14 @@ class GameState: if city == City.FACTORY } + @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.""" @@ -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) -- cgit v1.2.3