Permalink
Browse files

Revert "Merge summon_during/summon_after and reinforce_during/reinfor…

…ce_after"

This reverts commit ec63bee.

This led to a strange bug during battle where turn 1 kept repeating.  I
can't find the bug so I'll just redo this.
  • Loading branch information...
1 parent 0b961e5 commit ab78595736765e8e49e34db5502f610a3904224f @dripton committed Sep 6, 2012
Showing with 66 additions and 35 deletions.
  1. +16 −11 slugathon/ai/AIClient.py
  2. +10 −4 slugathon/ai/Bot.py
  3. +40 −20 slugathon/ai/CleverBot.py
View
@@ -461,10 +461,11 @@ def update(self, observed, action, names):
if legion:
if legion.player.name == self.playername:
if legion == game.defender_legion:
- reactor.callLater(self.delay, self.ai.reinforce, game)
- else:
- reactor.callLater(self.delay, self.ai.summon_angel,
+ reactor.callLater(self.delay, self.ai.reinforce_during,
game)
+ else:
+ reactor.callLater(self.delay,
+ self.ai.summon_angel_during, game)
else:
logging.info("game.battle_active_legion not found")
@@ -490,7 +491,8 @@ def update(self, observed, action, names):
reactor.callLater(self.delay, self.ai.recruit, game)
elif game.phase == Phase.FIGHT:
if game.battle_phase == Phase.REINFORCE:
- reactor.callLater(self.delay, self.ai.reinforce, game)
+ reactor.callLater(self.delay, self.ai.reinforce_during,
+ game)
else:
reactor.callLater(self.delay,
self.ai.choose_engagement, game)
@@ -536,7 +538,8 @@ def update(self, observed, action, names):
self.update_creatures(game)
if action.playername == self.playername:
if game.battle_phase == Phase.REINFORCE:
- reactor.callLater(self.delay, self.ai.summon_angel, game)
+ reactor.callLater(self.delay, self.ai.summon_angel_during,
+ game)
else:
reactor.callLater(self.delay, self.ai.choose_engagement,
game)
@@ -552,7 +555,8 @@ def update(self, observed, action, names):
self.update_creatures(game)
if action.playername == self.playername:
if game.battle_phase == Phase.REINFORCE:
- reactor.callLater(self.delay, self.ai.summon_angel, game)
+ reactor.callLater(self.delay, self.ai.summon_angel_during,
+ game)
else:
reactor.callLater(self.delay, self.ai.choose_engagement,
game)
@@ -561,7 +565,8 @@ def update(self, observed, action, names):
game = self.name_to_game(action.game_name)
if action.playername == self.playername:
if game.battle_phase == Phase.REINFORCE:
- reactor.callLater(self.delay, self.ai.summon_angel, game)
+ reactor.callLater(self.delay, self.ai.summon_angel_during,
+ game)
else:
reactor.callLater(self.delay, self.ai.choose_engagement,
game)
@@ -582,17 +587,17 @@ def update(self, observed, action, names):
legion = game.attacker_legion
if (legion.markerid == action.winner_markerid and
legion.can_summon):
- reactor.callLater(self.delay, self.ai.summon_angel,
- game)
+ reactor.callLater(self.delay,
+ self.ai.summon_angel_after, game)
return
else:
if game.defender_legion:
legion = game.defender_legion
if legion.player.name == self.playername:
if (legion.markerid == action.winner_markerid and
legion.can_recruit):
- reactor.callLater(self.delay, self.ai.reinforce,
- game)
+ reactor.callLater(self.delay,
+ self.ai.reinforce_after, game)
return
if game.active_player.name == self.playername:
reactor.callLater(self.delay, self.ai.choose_engagement, game)
View
@@ -46,11 +46,17 @@ def carry(game, striker_name, striker_hexlabel, target_name,
def recruit(game):
"""Recruit during the Muster phase."""
- def reinforce(game):
- """Muster a reinforcement during or after battle."""
+ def reinforce_during(game):
+ """Muster a reinforcement during battle."""
- def summon_angel(game):
- """Summon an angel, during or after battle."""
+ def reinforce_after(game):
+ """Muster a reinforcement after battle."""
+
+ def summon_angel_during(game):
+ """Summon angel, during battle."""
+
+ def summon_angel_after(game):
+ """Summon angel, after battle."""
def acquire_angels(game, markerid, num_angels, num_archangels):
"""Acquire angels."""
View
@@ -236,39 +236,48 @@ def recruit(self, game):
def1 = self.user.callRemote("done_with_recruits", game.name)
def1.addErrback(self.failure)
- def reinforce(self, game):
- """Reinforce, during the REINFORCE battle phase or after the battle."""
+ def reinforce_during(self, game):
+ """Reinforce, during the REINFORCE battle phase"""
logging.info("")
- during_battle = (game.battle_phase == Phase.REINFORCE)
- if during_battle:
- assert game.battle_active_player.name == self.playername
+ assert game.battle_active_player.name == self.playername
+ assert game.battle_phase == Phase.REINFORCE
legion = game.defender_legion
assert legion.player.name == self.playername
- if (not during_battle or game.battle_turn == 4) and legion.can_recruit:
+ if game.battle_turn == 4 and legion.can_recruit:
recruit, recruiters = self._pick_recruit_and_recruiters(legion)
if recruit is not None:
logging.info("CleverBot calling recruit_creature %s", recruit)
def1 = self.user.callRemote("recruit_creature", game.name,
legion.markerid, recruit, recruiters)
def1.addErrback(self.failure)
return
- if during_battle:
- logging.info("CleverBot calling done_with_reinforcements")
- def1 = self.user.callRemote("done_with_reinforcements", game.name)
- def1.addErrback(self.failure)
- else:
- logging.info("CleverBot calling do_not_reinforce %s", recruit)
- def1 = self.user.callRemote("do_not_reinforce", game.name,
- legion.markerid)
- def1.addErrback(self.failure)
+ logging.info("CleverBot calling done_with_reinforcements")
+ def1 = self.user.callRemote("done_with_reinforcements", game.name)
+ def1.addErrback(self.failure)
- # TODO Consider value of this legion and donor legion before deciding
- # whether to summon. But we may want to summon from a greater legion
- # if it's 7 high and summoning lets it recruit.
- def summon_angel(self, game):
+ def reinforce_after(self, game):
+ """Reinforce, after the battle"""
+ logging.info("")
+ legion = game.defender_legion
+ assert legion.player.name == self.playername
+ if legion.can_recruit:
+ recruit, recruiters = self._pick_recruit_and_recruiters(legion)
+ if recruit is not None:
+ logging.info("CleverBot calling recruit_creature %s", recruit)
+ def1 = self.user.callRemote("recruit_creature", game.name,
+ legion.markerid, recruit, recruiters)
+ def1.addErrback(self.failure)
+ return
+ logging.info("CleverBot calling do_not_reinforce %s", recruit)
+ def1 = self.user.callRemote("do_not_reinforce", game.name,
+ legion.markerid)
+ def1.addErrback(self.failure)
+
+ def _summon_angel(self, game, during_battle):
logging.info("")
assert game.active_player.name == self.playername
- during_battle = (game.battle_phase == Phase.REINFORCE)
+ if during_battle and game.battle_phase != Phase.REINFORCE:
+ return
legion = game.attacker_legion
assert legion.player.name == self.playername
if (legion.can_summon and (not during_battle or
@@ -312,6 +321,17 @@ def summon_angel(self, game):
def1 = self.user.callRemote("done_with_reinforcements", game.name)
def1.addErrback(self.failure)
+ def summon_angel_during(self, game):
+ """Summon, during the REINFORCE battle phase"""
+ self._summon_angel(game, True)
+
+ # TODO Consider value of this legion and donor legion before deciding
+ # whether to summon. But we may want to summon from a greater legion
+ # if it's 7 high and doing this lets it recruit.
+ def summon_angel_after(self, game):
+ """Summon, after the battle is over."""
+ self._summon_angel(game, False)
+
def acquire_angels(self, game, markerid, num_angels, num_archangels):
logging.info("CleverBot.acquire_angels %s %s %s", markerid, num_angels,
num_archangels)

0 comments on commit ab78595

Please sign in to comment.