Player.select_territory returns territory name rather than instance.
authorW. Trevor King <wking@drexel.edu>
Fri, 26 Mar 2010 04:34:59 +0000 (00:34 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 26 Mar 2010 04:36:36 +0000 (00:36 -0400)
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.

risk/base.py

index 847d48c6c6cd47cc90ec42ddb47e87cac903ca95..6f62c78aa471ffa14233fb2d5ba2b69a03bb3bcf 100644 (file)
@@ -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))