Added risk.player.email with EmailPlayer.
[pyrisk.git] / risk / base.py
index 6f62c78aa471ffa14233fb2d5ba2b69a03bb3bcf..d54b52fd3c04d9e86c67f42363506685f5b04ea2 100644 (file)
@@ -419,7 +419,7 @@ class Player (NameMixin, ID_CmpMixin):
         """
         pass
     def select_territory(self, world, log):
-        """Return the selected territory
+        """Return the selected territory's name.
         """
         free_territories = [t for t in world.territories() if t.player == None]
         return random.sample(free_territories, 1)[0].name
@@ -672,12 +672,15 @@ class Engine (ID_CmpMixin):
         source.armies -= remaining_attackers
         target.armies += remaining_attackers
         target.player = source.player
-        support = source.player.support_attack(self.world, self.log, source, target)
-        if support < 0 or support >= source.armies:
-            raise PlayerError('Cannot support from %s to %s with %d armies, only %d available'
-                              % (source, target, support, source.armies-1))
-        source.armies -= support
-        target.armies += support
+        if source.armies > 1:
+            support = source.player.support_attack(
+                self.world, self.log, source, target)
+            if support < 0 or support >= source.armies:
+                raise PlayerError(
+                    'Cannot support from %s to %s with %d armies, only %d available'
+                    % (source, target, support, source.armies-1))
+            source.armies -= support
+            target.armies += support
     def player_killed(self, player, killer):
         player.alive = False
         killer.hand.extend(player.hand)
@@ -769,8 +772,10 @@ def test():
     return failures
 
 def random_game():
+    from player.email import EmailPlayer
     world = generate_earth()
-    players = [Player('Alice'), Player('Bob'), Player('Charlie')]
+    players = [EmailPlayer('Alice', 'alice@example.com', 'server@example.com'),
+               Player('Bob'), Player('Charlie')]
     e = Engine(world, players)
     e.run()