diff options
Diffstat (limited to 'robots/state.py')
-rw-r--r-- | robots/state.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/robots/state.py b/robots/state.py index 5a1450d..8a47139 100644 --- a/robots/state.py +++ b/robots/state.py @@ -1,7 +1,7 @@ from collections import defaultdict, Counter -from robots.constants import City -from robots.utils import ceil_div +from robots.constants import City, DIRECTIONS +from robots.utils import ceil_div#, immutable class GameState: """The state of a game at a point in time. @@ -18,7 +18,8 @@ class GameState: self.robots_by_player = {} def __hash__(self): - return hash(self._authorative_state) + return id(self) +# return hash(immutable(self._authorative_state)) def __eq__(self, other): if isinstance(other, GameState): @@ -112,3 +113,20 @@ class GameState: def n_cities_to_win(self): """How many cities you need to pledge allegiance to you to win.""" return ceil_div(self.n_allegiable_cities, self.n_alive_players) + + def expected_position(self, x, y, action): + """ + Return the expected position for a robot at (x, y) if it performs the + given action. + Of course, combat (and possibly other factors in the future) may + influence whether it actually ends up at the returned position. + """ + 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 + + return (x, y) |