Commits

Arne Babenhauserheide  committed 8c76cbb

asciibattle: cleanup: nicer to read.

  • Participants
  • Parent commits 236743d

Comments (0)

Files changed (1)

File asciibattle.py

 
 """
 
+# Dimensions of the battle field
 X, Y = 160, 60
 rows = 30
 
       wound threshold: hardened
 """
 
-#: The default profile for all fighters
+#: The default profile for all fighters. This provides the template for improving them.
 _profile = """
 attributes:
    swift: 1
 team0 = []
 team1 = []
 
+#: The different types of fighters: (source, letter, weapon, armor)
 fighters = [(_swordmaster, "S", 4, 2), (_armored, "A", 4, 14), (_killer, "K", 16, 2)]
-#fighters = [(_swordmaster, "S", 4, 2), (_killer, "K", 16, 2)]
 
 for i in range(Y-20):
     for j in range(rows): # 3 rows
-        # left side
+        # create the fighters for the left side
         source, letter, weapon, armor = choice(fighters)
         c = Char(source)
         team0.append(c)
         c.team = 0
         c.enemy = None
 
-        # right side
+        # and the right side
         source, letter, weapon, armor = choice(fighters)
         c = Char(source)
         team1.append(c)
         c.team = 1
         c.enemy = None
 
-# setup
-for i in team0 + team1:
-    battlefield[i.pos] = i
+# put all fighters onto the battlefield
+fighters = team0 + team1
+for fighter in fighters:
+    battlefield[fighter.pos] = fighter
 
-fighters = team0 + team1
+# let them act in random order
 shuffle(fighters)
 
+
+## Prepare movement of fighters
 def distancesquared(me, other):
     return (me[0]-other[0])**2 + (me[1]-other[1])**2
 
         else: return me.pos
 
 def oddstep(me):
+    """step into a random direction"""
     return choice(adjadent(me.pos))
 
 def adjadent(pos):
     down = pos[0], pos[1] + 1
     return left, right, up, down
 
+
 def draw():
     text = ""
     for y in range(Y+1):
     else:
         enemy.improve(1)
 
-def fighterstep(me):
+def fighteraction(me):
     """One Round for One Fighter."""
     if me.wounds[1]:
         return
 
 def battleround():
     """a single round of battle"""
-    [i for i in map(fighterstep, fighters)]
+    # we need the list comprehension, else nothing happens.
+    [i for i in map(fighteraction, fighters)]
+
 
 def meancost(team):
     return int(sum((c.cost for c in team))/max(1, len(team)))