Broke Engine.end_of_turn_cards out of Engine.play_turn
authorW. Trevor King <wking@drexel.edu>
Fri, 26 Mar 2010 04:23:18 +0000 (00:23 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 26 Mar 2010 04:23:18 +0000 (00:23 -0400)
For easier modification if you decide to change the rules in a
subclass.

risk/base.py

index 9fdda26..847d48c 100644 (file)
@@ -527,8 +527,7 @@ class Engine (ID_CmpMixin):
                              for p in self.players]))
         self.play_cards_and_place_armies(player)
         captures = self.attack_and_fortify(player)
-        if captures > 0 and len(self.deck) > 0 and len(self.living_players()) > 1:
-            self.deal(player, 1)
+        self.end_of_turn_cards(player, captures)
     def select_territories(self):
         for t in self.world.territories():
             t.player = None
@@ -688,6 +687,11 @@ class Engine (ID_CmpMixin):
         if len(self.living_players()) > 1:
             player.report(self.world, self.log)
             # else the game is over, and killed will hear about this then.
+    def end_of_turn_cards(self, player, captures):
+        """Deal end-of-turn reward for any territory captures.
+        """
+        if captures > 0 and len(self.deck) > 0 and len(self.living_players()) > 1:
+            self.deal(player, 1)
     def living_players(self):
         return [p for p in self.players if p.alive == True]