Permalink
Browse files

Add effects for more terrain types to Legion.terrain_combat_value.

The actual values are total guesswork, and should really move into
the AI for tuning.
  • Loading branch information...
1 parent ec8362d commit bdafd0177dab7158ac4d74446892f113d52950d6 @dripton committed Feb 19, 2012
Showing with 94 additions and 3 deletions.
  1. +49 −3 slugathon/game/Legion.py
  2. +45 −0 slugathon/test/test_legion.py
View
@@ -496,16 +496,62 @@ def combat_value(self):
"""Return a rough indication of legion combat value."""
return sum(creature.combat_value for creature in self.living_creatures)
- # TODO Add for other terrains if enough native 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_MULTIPLIER = 1.25
+ 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 TOWER_MULTIPLIER * base_value
+ 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
@@ -365,3 +365,48 @@ def test_reveal_creatures():
"Unknown", "Unknown", "Unknown"]), 1)
legion.reveal_creatures(["Centaur", "Centaur", "Lion"])
assert legion.creature_names == ["Centaur", "Centaur", "Lion", "Unknown"]
+
+
+def test_combat_value():
+ now = time.time()
+ game = Game.Game("g1", "p0", now, now, 2, 6)
+ creatures = Creature.n2c(creaturedata.starting_creature_names)
+ 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
+
+ # Plains
+ assert legion.terrain_combat_value == legion.combat_value
+ # Woods
+ legion.hexlabel = 2
+ assert legion.terrain_combat_value == legion.combat_value
+ # Brush
+ legion.hexlabel = 3
+ assert legion.terrain_combat_value > legion.combat_value
+ # Hills
+ legion.hexlabel = 4
+ assert legion.terrain_combat_value > legion.combat_value
+ # Jungle
+ legion.hexlabel = 5
+ assert legion.terrain_combat_value > legion.combat_value
+ # Desert
+ legion.hexlabel = 7
+ assert legion.terrain_combat_value == legion.combat_value
+ # Marsh
+ legion.hexlabel = 8
+ assert legion.terrain_combat_value > legion.combat_value
+ # Swamp
+ legion.hexlabel = 14
+ assert legion.terrain_combat_value > legion.combat_value
+ # Tower
+ legion.hexlabel = 100
+ assert legion.terrain_combat_value > legion.combat_value
+ # Mountains
+ legion.hexlabel = 1000
+ assert legion.terrain_combat_value == legion.combat_value
+ # Tundra
+ legion.hexlabel = 2000
+ assert legion.terrain_combat_value == legion.combat_value

0 comments on commit bdafd01

Please sign in to comment.