Beispiel #1
0
def test_deal_damage_spell_minion(game):
    game.NUMBERS_OF_START_CARDS = (1, 0)
    deck = Deck([
        MinionCard(name='minon 1', cost=0, attack=50, health=2),
        MinionCard(name='minon 2', cost=0, attack=50, health=12),
        MinionCard(name='minion with ability',
                   cost=1,
                   attack=50,
                   health=2,
                   ability=DealDamage(10, allow_target=True)),
    ])
    g = game(player_decks=[deck, deck])

    first_player, second_player = g.players
    g.start()
    first_player_card, first_player_card_2 = first_player.hand
    g.play(first_player.id, first_player_card.id)
    g.play(first_player.id, first_player_card_2.id)
    g.endturn(g.current_player.id)

    assert len(g.board.played_cards(first_player)) == 2
    assert first_player_card_2.health == 12
    g.play(second_player.id, second_player.hand[0].id, first_player_card_2.id)
    assert first_player_card_2.health == 2
    assert first_player_card.health == 2
Beispiel #2
0
def test_attack_action_generator_no_board_enemies(game):
    cards = [
        MinionCard('test minion', health=1, attack=1, cost=0),
        MinionCard('test minion 2', health=1, attack=1, cost=0),
        MinionCard('test charge minion',
                   health=1,
                   attack=1,
                   cost=0,
                   ability=ChargeAbility()),
    ]
    deck = Deck(cards)
    game.NUMBERS_OF_START_CARDS = (2, 0)
    g = game(player_decks=[deck, deck])
    player, _ = g.players
    g.start()
    for card in cards:
        g.play(player.id, card.id)
    gen = ActionGenerator(g)

    assert len(player.hand) == 0
    assert len(list(
        gen.attack_actions())) == 1  # only charge minion can attack
    assert len(list(gen.play_actions())) == 0
    assert len(list(gen.endturn_action())) == 1
    assert len(list(gen.random_actions())) == 2
    assert player.health == 20
Beispiel #3
0
def test_attack_action_generator_with_enemies(game):
    cards = [
        MinionCard('test minion', health=1, attack=1, cost=0),
        MinionCard('test minion 2', health=1, attack=1, cost=0),
        MinionCard('test charge minion',
                   health=1,
                   attack=1,
                   cost=0,
                   ability=ChargeAbility()),
    ]
    deck = Deck(cards)
    game.NUMBERS_OF_START_CARDS = (0, 0)
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    g.play(first_player.id, first_player.hand[0].id)
    g.endturn(g.current_player.id)
    g.play(second_player.id, second_player.hand[0].id)
    g.endturn(g.current_player.id)
    g.play(first_player.id, first_player.hand[0].id)

    gen = ActionGenerator(g)

    assert len(g.board) == 3
    assert len(g.board.played_cards(first_player)) == 2
    assert len(g.board.played_cards(second_player)) == 1
    # two minions (played in previous turn and having charge ability) can attack minion and second player
    assert len(list(gen.attack_actions())) == 4
    assert len(list(gen.play_actions())) == 0
    assert len(list(gen.endturn_action())) == 1
    assert len(list(gen.random_actions())) == 5
    assert first_player.health == second_player.health == 20
    assert len(g.board) == 3
Beispiel #4
0
def test_random_action_generator(game):
    cards = [
        MinionCard('test minion', health=1, attack=1, cost=0),
        MinionCard('test minion 2', health=1, attack=1, cost=0),
        MinionCard('test charge minion',
                   health=1,
                   attack=1,
                   cost=0,
                   ability=ChargeAbility()),
    ]
    deck = Deck(cards)
    game.NUMBERS_OF_START_CARDS = (0, 0)
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    g.play(first_player.id, first_player.hand[0].id)
    g.endturn(g.current_player.id)
    g.play(second_player.id, second_player.hand[0].id)
    g.endturn(g.current_player.id)

    gen = ActionGenerator(g)

    assert len(list(gen.attack_actions())) == 2
    assert len(list(gen.play_actions())) == 1
    assert len(list(gen.endturn_action())) == 1
    assert len(list(gen.random_actions())) == 4
Beispiel #5
0
def test_play_action_generator(game):
    deck = Deck([
        MinionCard('test minion', health=1, attack=1, cost=1),
        MinionCard('test minion 2', health=1, attack=1, cost=1),
        MinionCard('test costly minion', health=1, attack=1, cost=100),
    ])
    game.NUMBERS_OF_START_CARDS = (2, )
    g = game(player_decks=[deck])
    player, = g.players
    g.start()
    gen = ActionGenerator(g)

    assert len(player.hand) == 3
    assert len(list(gen.attack_actions())) == 0
    assert len(list(gen.play_actions())) == 2
    assert len(list(gen.endturn_action())) == 1
    assert len(list(gen.random_actions())) == 3
Beispiel #6
0
def test_play_action_with_ability_cards(game):
    cards = [
        MinionCard(name='Animated Statue', cost=0, attack=10, health=10),
        MinionCard(name='Aberration',
                   cost=0,
                   attack=1,
                   health=1,
                   ability=ChargeAbility()),
        AbilityCard(name='Flamestrike', cost=0, ability=DealDamage(4)),
    ]
    deck = Deck(cards)
    game.NUMBERS_OF_START_CARDS = (2, 0)
    g = game(player_decks=[deck, deck])
    player, _ = g.players
    g.start()
    g.play(player.id, player.hand[0].id)

    gen = ActionGenerator(g)
    assert len(list(gen.play_actions())) == 2
Beispiel #7
0
    def attack(self, attacker: MinionCard, victim: Union[str, Player]):
        try:
            victim = self._cards[victim]
        except KeyError:
            if not hasattr(victim, 'id'):
                raise MissingCardError(
                    '{0} cannot attack not played {1} card'.format(
                        attacker, victim))

        for dead_card in attacker.attack(victim):
            self._remove_card(dead_card)
Beispiel #8
0
def test_increase_health_and_damage_spell_no_target(game):
    deck = Deck([
        MinionCard(name='minon 1', cost=0, attack=50, health=2),
        MinionCard(name='minon 2', cost=0, attack=50, health=2),
        AbilityCard(name='spell', cost=1, ability=SetMinonHealthAndDamage(10)),
    ])
    g = game(player_decks=[deck])

    first_player, = g.players
    g.start()
    first_player_card, first_player_card_2, first_player_card_3 = first_player.hand
    g.play(first_player.id, first_player_card.id)
    g.play(first_player.id, first_player_card_2.id)

    assert len(g.board.played_cards()) == 2
    assert len(first_player.hand) == 1
    with pytest.raises(TargetNotDefinedError):
        g.play(first_player.id, first_player_card_3.id)
    assert len(g.board.played_cards()) == 2
    assert len(first_player.hand) == 1
Beispiel #9
0
def test_increase_minions_health_spell(game):
    deck = Deck([
        MinionCard(name='minon 1', cost=0, attack=50, health=2),
        MinionCard(name='minon 2', cost=0, attack=50, health=2),
        AbilityCard(name='spell',
                    cost=1,
                    ability=IncreaseMinonsHealthAbility(10)),
    ])
    g = game(player_decks=[deck])

    first_player, = g.players
    g.start()
    first_player_card, first_player_card_2, first_player_card_3 = first_player.hand
    g.play(first_player.id, first_player_card.id)
    g.play(first_player.id, first_player_card_2.id)

    assert first_player_card.health == 2
    assert first_player_card_2.health == 2
    g.play(first_player.id, first_player_card_3.id)
    assert first_player_card.health == 12
    assert first_player_card_2.health == 12
Beispiel #10
0
def test_card_played_but_not_in_hand(game):
    card = MinionCard('test', cost=1, attack=1, health=1)
    g = game()
    player, _ = g.players
    player.hand = []
    g.start()

    with pytest.raises(MissingCardError):
        g.play(player.id, card.id)

    assert len(g.board) == 0
    assert card not in g.board.played_cards(player)
Beispiel #11
0
def test_deal_damage_to_self_minions(game):
    game.NUMBERS_OF_START_CARDS = (2, 0)
    deck = Deck([
        MinionCard(name='minon 1', cost=0, attack=50, health=2),
        MinionCard(name='minon 2', cost=0, attack=50, health=12),
        MinionCard(name='minion with ability',
                   cost=1,
                   attack=50,
                   health=2,
                   ability=DealDamage(10, allow_target=True)),
    ])
    g = game(player_decks=[deck, deck])

    first_player, second_player = g.players
    g.start()
    first_player_card, first_player_card_2, first_player_card_3 = first_player.hand
    g.play(first_player.id, first_player_card.id)
    g.play(first_player.id, first_player_card_2.id)

    with pytest.raises(InvalidTargetError):
        g.play(first_player.id, first_player_card_3.id, first_player_card_2.id)
Beispiel #12
0
def test_play_card_to_board(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=1, health=1) for _ in range(10))
    g = game(player_decks=[deck])
    player, = g.players
    card = player.hand[0]

    g.start()
    assert player.mana == 1
    g.play(player.id, card.id)
    assert len(g.board) == 1
    assert card in g.board.played_cards(player)
    assert card not in player.hand
    assert player.mana == 0
Beispiel #13
0
def test_increase_health_and_damage_spell(game):
    deck = Deck([
        MinionCard(name='minon 1', cost=0, attack=50, health=2),
        MinionCard(name='minon 2', cost=0, attack=50, health=2),
        AbilityCard(name='spell', cost=1, ability=SetMinonHealthAndDamage(10)),
    ])
    g = game(player_decks=[deck])

    first_player, = g.players
    g.start()
    first_player_card, first_player_card_2, first_player_card_3 = first_player.hand
    g.play(first_player.id, first_player_card.id)
    g.play(first_player.id, first_player_card_2.id)

    assert first_player_card.health == 2
    assert first_player_card.damage == 50
    assert first_player_card_2.health == 2
    assert first_player_card_2.damage == 50
    g.play(first_player.id, first_player_card_3.id, first_player_card.id)
    assert first_player_card.health == 10
    assert first_player_card.damage == 10
    assert first_player_card_2.health == 2
    assert first_player_card_2.damage == 50
Beispiel #14
0
def test_only_played_minion_can_attack(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=1, health=2) for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()

    first_player_card = first_player.hand[0]
    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    second_player_card = second_player.hand[0]
    with pytest.raises(MissingCardError):
        g.attack(second_player.id, second_player_card.id, first_player_card.id)
Beispiel #15
0
def test_not_enough_mana_to_play_card(game):
    deck = Deck(
        MinionCard('test', cost=1000, attack=1, health=1) for _ in range(10))
    g = game(player_decks=[deck])
    player, = g.players
    card = player.hand[0]
    g.start()

    with pytest.raises(NotEnoughManaError):
        g.play(player.id, card.id)

    assert len(g.board) == 0
    assert card not in g.board.played_cards(player)
    assert card in player.hand
Beispiel #16
0
def test_minion_card_increase_attack_ability(game):
    deck = Deck(
        MinionCard(name='test',
                   cost=1,
                   attack=1,
                   health=2,
                   ability=IncreaseDamageAbility(10)) for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, _ = g.players
    g.start()
    first_player_card = first_player.hand[0]

    assert first_player_card.damage == 1
    g.play(first_player.id, first_player_card.id)
    assert first_player_card.damage == 11
Beispiel #17
0
def test_player_cannot_attack_without_turn(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=1, health=2) for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()

    first_player_card = first_player.hand[0]
    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    second_player_card = second_player.hand[0]
    g.play(second_player.id, second_player_card.id)

    with pytest.raises(InvalidPlayerTurnError):
        g.attack(first_player.id, first_player_card.id, second_player_card.id)
Beispiel #18
0
def test_simple_minion_cannot_attack_in_played_turn(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=10, health=2)
        for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    first_player_card = first_player.hand[0]
    second_player_card = second_player.hand[0]

    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    g.play(second_player.id, second_player_card.id)
    with pytest.raises(CardCannotAttackError):
        g.attack(second_player.id, second_player_card.id, first_player_card.id)
Beispiel #19
0
def test_minion_card_charge_ability_attack_player(game):
    deck = Deck(
        MinionCard(
            name='test', cost=1, attack=10, health=2, ability=ChargeAbility())
        for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    first_player_card = first_player.hand[0]
    second_player_card = second_player.hand[0]

    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    g.play(second_player.id, second_player_card.id)
    g.attack(second_player.id, second_player_card.id, first_player.id)
Beispiel #20
0
def test_to_many_minions_on_board(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=1, health=2) for _ in range(10))
    game.NUMBERS_OF_START_CARDS = (7, 0)
    g = game(player_decks=[deck])
    player, = g.players
    player.mana = 200
    g.start()

    assert len(player.hand) == 8
    assert len(g.board.played_cards(player)) == 0

    last_card, *rest_cards = player.hand
    for card in rest_cards:
        g.play(player.id, card.id)

    assert len(g.board.played_cards(player)) == 7
    with pytest.raises(TooManyCardsError):
        g.play(player.id, last_card.id)
Beispiel #21
0
def test_minion_removed_from_board_after_die(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=10, health=2)
        for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    first_player_card = first_player.hand[0]
    second_player_card = second_player.hand[0]

    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    g.play(second_player.id, second_player_card.id)
    g.endturn(g.current_player.id)

    assert len(g.board) == 2
    g.attack(first_player.id, first_player_card.id, second_player_card.id)
    assert len(g.board) == 0
Beispiel #22
0
def test_kill_player(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=50, health=2)
        for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    first_player_card = first_player.hand[0]
    second_player_card = second_player.hand[0]

    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    g.play(second_player.id, second_player_card.id)
    g.endturn(g.current_player.id)

    assert second_player.health == 20
    with pytest.raises(DeadPlayerError):
        g.attack(first_player.id, first_player_card.id, second_player.id)
Beispiel #23
0
def test_simple_minion_attack(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=1, health=2) for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players

    g.start()

    first_player_card = first_player.hand[0]
    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    second_player_card = second_player.hand[0]
    g.play(second_player.id, second_player_card.id)
    g.endturn(g.current_player.id)

    g.attack(first_player.id, first_player_card.id, second_player_card.id)

    assert first_player_card.health == 1
    assert second_player_card.health == 1
    assert len(g.board) == 2
Beispiel #24
0
def test_attack_player_twice_with_same_card(game):
    deck = Deck(
        MinionCard(name='test', cost=1, attack=10, health=2)
        for _ in range(10))
    g = game(player_decks=[deck, deck])
    first_player, second_player = g.players
    g.start()
    first_player_card = first_player.hand[0]
    second_player_card = second_player.hand[0]

    g.play(first_player.id, first_player_card.id)
    g.endturn(g.current_player.id)

    g.play(second_player.id, second_player_card.id)
    g.endturn(g.current_player.id)

    assert second_player.health == 20
    g.attack(first_player.id, first_player_card.id, second_player.id)
    assert second_player.health == 10

    with pytest.raises(CardCannotAttackError):
        g.attack(first_player.id, first_player_card.id, second_player.id)

    assert second_player.health == 10