Permalink
Browse files

Move most logic in terrain_combat_value from Legion to Creature.

This lets us get rid of Legion.native_fraction
  • Loading branch information...
dripton committed Aug 9, 2012
1 parent 3f45909 commit 38f529b92207095b07893fbb61e5cd3fd2b8a9e5
Showing with 50 additions and 58 deletions.
  1. +44 −0 slugathon/game/Creature.py
  2. +2 −54 slugathon/game/Legion.py
  3. +4 −4 slugathon/test/test_legion.py
View
@@ -139,6 +139,50 @@ def combat_value(self):
+ 0.15 * (self.skill == 2)
+ 0.18 * (self.skill == 4))
+ @property
+ def terrain_combat_value(self):
+ """Return a rough indication of creature combat value, considering its
+ legion's current terrain."""
+ TOWER_BONUS = 0.25
+ BRUSH_BONUS = 0.1
+ JUNGLE_BONUS = 0.1
+ HILLS_BONUS = 0.1
+ SWAMP_BONUS = 0.05
+ MARSH_BONUS = 0.05
+ DESERT_BONUS = 0.1
+ MOUNTAINS_BONUS = 0.1
+ TUNDRA_BONUS = 0.1
+ base_value = self.combat_value
+ if (self.legion is None or self.legion.player is None or
+ self.legion.hexlabel is None):
+ return base_value
+ terrain = self.legion.player.game.board.hexes[
+ self.legion.hexlabel].terrain
+ if terrain == "Tower":
+ return (1 + TOWER_BONUS) * base_value
+ elif terrain == "Brush":
+ return ((1 + (self.is_native("Bramble") * BRUSH_BONUS)) *
+ base_value)
+ elif terrain == "Jungle":
+ return ((1 + (self.is_native("Bramble") * JUNGLE_BONUS)) *
+ base_value)
+ elif terrain == "Hills":
+ return ((1 + (self.is_native("Slope") * HILLS_BONUS)) * base_value)
+ elif terrain == "Swamp":
+ return ((1 + (self.is_native("Bog") * SWAMP_BONUS)) * base_value)
+ elif terrain == "Marsh":
+ return ((1 + (self.is_native("Bog") * MARSH_BONUS)) * base_value)
+ elif terrain == "Desert":
+ return ((1 + (self.is_native("Dune") * DESERT_BONUS)) * base_value)
+ elif terrain == "Mountain":
+ return ((1 + (self.is_native("Slope") * MOUNTAINS_BONUS)) *
+ base_value)
+ elif terrain == "Tundra":
+ return ((1 + (self.is_native("Drift") * TUNDRA_BONUS)) *
+ base_value)
+ else:
+ return base_value
+
@property
def is_titan(self):
return self.name == "Titan"
View
@@ -499,64 +499,12 @@ def combat_value(self):
"""Return a rough indication of legion combat value."""
return sum(creature.combat_value for creature in self.living_creatures)
- def native_fraction(self, hazard):
- """Return the fraction of this legion that's native to hazard."""
- native = 0
- not_native = 0
- for creature in self.creatures:
- if creature.is_native(hazard):
- native += 1
- else:
- not_native += 1
- total = native + not_native
- if total == 0:
- return 0
- else:
- return 1.0 * native / total
-
@property
def terrain_combat_value(self):
"""Return a rough indication of legion combat value, considering its
current terrain."""
- TOWER_BONUS = 0.25
- BRUSH_BONUS = 0.1
- JUNGLE_BONUS = 0.1
- HILLS_BONUS = 0.1
- SWAMP_BONUS = 0.05
- MARSH_BONUS = 0.05
- DESERT_BONUS = 0.1
- MOUNTAINS_BONUS = 0.1
- TUNDRA_BONUS = 0.1
- base_value = self.combat_value
- terrain = self.player.game.board.hexes[self.hexlabel].terrain
- if terrain == "Tower":
- return (1 + TOWER_BONUS) * base_value
- elif terrain == "Brush":
- return ((1 + (self.native_fraction("Bramble") * BRUSH_BONUS)) *
- base_value)
- elif terrain == "Jungle":
- return ((1 + (self.native_fraction("Bramble") * JUNGLE_BONUS)) *
- base_value)
- elif terrain == "Hills":
- return ((1 + (self.native_fraction("Slope") * HILLS_BONUS)) *
- base_value)
- elif terrain == "Swamp":
- return ((1 + (self.native_fraction("Bog") * SWAMP_BONUS)) *
- base_value)
- elif terrain == "Marsh":
- return ((1 + (self.native_fraction("Bog") * MARSH_BONUS)) *
- base_value)
- elif terrain == "Desert":
- return ((1 + (self.native_fraction("Dune") * DESERT_BONUS)) *
- base_value)
- elif terrain == "Mountain":
- return ((1 + (self.native_fraction("Slope") * MOUNTAINS_BONUS)) *
- base_value)
- elif terrain == "Tundra":
- return ((1 + (self.native_fraction("Drift") * TUNDRA_BONUS)) *
- base_value)
- else:
- return base_value
+ return sum(creature.terrain_combat_value for creature in
+ self.living_creatures)
def die(self, scoring_legion, fled, no_points, check_for_victory=True,
kill_all_creatures=False):
@@ -374,11 +374,11 @@ def test_combat_value():
player = Player.Player("p0", game, 0)
legion = Legion.Legion(player, "Rd01", creatures, 1)
- assert legion.native_fraction("Dune") == 0
- assert legion.native_fraction("Bramble") == 0.25
- assert legion.native_fraction("Tundra") == 0
-
+ # No terrain
+ legion.hexlabel = None
+ assert legion.terrain_combat_value == legion.combat_value
# Plains
+ legion.hexlabel = 1
assert legion.terrain_combat_value == legion.combat_value
# Woods
legion.hexlabel = 2

0 comments on commit 38f529b

Please sign in to comment.