From: W. Trevor King Date: Fri, 26 Mar 2010 04:34:59 +0000 (-0400) Subject: Player.select_territory returns territory name rather than instance. X-Git-Tag: 0.1~35 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=482152eea863c189481db90c37616b2beb5c898e;p=pyrisk.git Player.select_territory returns territory name rather than instance. To keep the Player interface as simple (and tamper-resistant :) as possible, Player methods should return names instead of instances of risk-specific classes. Also fixed a deck -> self.deck typo in Engine. --- diff --git a/risk/base.py b/risk/base.py index 847d48c..6f62c78 100644 --- a/risk/base.py +++ b/risk/base.py @@ -422,7 +422,7 @@ class Player (NameMixin, ID_CmpMixin): """Return the selected territory """ free_territories = [t for t in world.territories() if t.player == None] - return random.sample(free_territories, 1)[0] + return random.sample(free_territories, 1)[0].name def play_cards(self, world, log, play_required=True): """Decide whether or not to turn in a set of cards. @@ -492,7 +492,7 @@ class Engine (ID_CmpMixin): for p in self.players: p.alive = True random.shuffle(self.players) - deck.shuffle() + self.deck.shuffle() self.select_territories() self.place_initial_armies() for p in self.players: @@ -533,7 +533,8 @@ class Engine (ID_CmpMixin): t.player = None for i in range(len(list(self.world.territories()))): p = self.players[i % len(self.players)] - t = p.select_territory(self.world, self.log) + t_name = p.select_territory(self.world, self.log) + t = self.world.territory_by_name(t_name) if t.player != None: raise PlayerError('Cannot select %s owned by %s' % (t, t.player))