Permalink
Browse files

Implement Joust() evaluator

  • Loading branch information...
jleclanche committed Aug 5, 2015
1 parent f2500be commit 3e5df389a4d1c4e23cd836cf7ac758c7e1d695d3
Showing with 41 additions and 0 deletions.
  1. +1 −0 fireplace/cards/utils.py
  2. +21 −0 fireplace/dsl/evaluator.py
  3. +19 −0 tests/test_main.py
@@ -20,3 +20,4 @@ def pick(self, source):


HOLDING_DRAGON = Find(CONTROLLER_HAND + DRAGON)
JOUST = Joust(FRIENDLY + MINION + IN_DECK, ENEMY + MINION + IN_DECK)
@@ -1,3 +1,6 @@
import logging


class Evaluator:
"""
Lazily evaluate a condition at runtime.
@@ -59,3 +62,21 @@ def __init__(self, selector, count=1):

def evaluate(self, source):
return len(self.selector.eval(source.game, source)) >= self.count


class Joust(Evaluator):
"""
Compare the sum of the costs of \a selector1 versus \a selector2.
Evaluates to True if the mana cost of \a selector1 is higher.
"""
def __init__(self, selector1, selector2):
super().__init__()
self.selector1 = selector1
self.selector2 = selector2

def evaluate(self, source):
t1 = self.selector1.eval(source.game, source)
t2 = self.selector2.eval(source.game, source)
diff = sum(t.cost for t in t1) - sum(t.cost for t in t2)
logging.info("Jousting %r vs %r -> %i difference", t1, t2, diff)
return diff > 0
@@ -86,6 +86,25 @@ def prepare_empty_game(game_class=BaseTestGame):
return game


def test_joust():
from fireplace.cards.utils import Give, JOUST
game = prepare_empty_game()
wisp = game.player1.give(WISP)
wisp.shuffle_into_deck()
wisp2 = game.player1.give(WISP)
wisp2.shuffle_into_deck()
game.end_turn()

goldshire = game.player2.give(GOLDSHIRE_FOOTMAN)
goldshire.shuffle_into_deck()
game.queue_actions(game.player2, [JOUST & Give(game.player2, TARGET_DUMMY)])
assert game.player2.hand.filter(id=TARGET_DUMMY)
game.end_turn()

game.queue_actions(game.player1, [JOUST & Give(game.player1, TARGET_DUMMY)])
assert not game.player1.hand.filter(id=TARGET_DUMMY)


def test_cheat_destroy_deck():
game = prepare_game()
game.player1.discard_hand()

0 comments on commit 3e5df38

Please sign in to comment.