Added adjacency checking to Engine.attack_and_fortify.
authorW. Trevor King <wking@drexel.edu>
Fri, 26 Mar 2010 04:19:41 +0000 (00:19 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 26 Mar 2010 04:19:41 +0000 (00:19 -0400)
risk/base.py

index e1ea622..9fdda26 100644 (file)
@@ -620,6 +620,9 @@ class Engine (ID_CmpMixin):
                 source_name,target_name,armies = action
                 source = self.world.territory_by_name(source_name)
                 target = self.world.territory_by_name(target_name)
+                if not source.borders(target):
+                    raise PlayerError('Cannot reach %s from %s to %s'
+                                      % (target, source, mode))
                 if mode == 'attack':
                     tplayer = target.player
                     capture = self.attack(source, target, armies)