Example #1
0
    def test_guard(self):
        slimer = Constants.CARDS[1]
        scuttler = Constants.CARDS[2]
        prowler = Constants.CARDS[49]
        decks = [[slimer] * 8 + [prowler], [scuttler] * 9]
        draft = fix_draft(*decks)

        state = GameState(draft)
        first_player = state.get_first_player()
        second_player = state.get_second_player()
        for i in range(5):
            state.open_next_turn()

        state.perform_action(Summon(first_player.from_hand(prowler)))
        state.perform_action(Summon(first_player.from_hand(slimer)))
        state.open_next_turn()
        state.perform_action(Summon(second_player.from_hand(scuttler)))
        state.perform_action(Summon(second_player.from_hand(scuttler)))
        state.open_next_turn()
        state.open_next_turn()
        self.assertEqual(
            first_player.get_creature_by_index(0).name(), prowler.name())
        # must attack creature with guard first
        with self.assertRaises(IllegalAttackException):
            state.perform_action(
                Attack(second_player.get_creature_by_index(0),
                       first_player.get_creature_by_index(1)))

        state.perform_action(
            Attack(second_player.get_creature_by_index(0),
                   first_player.get_creature_by_index(0)))
        # now we can attack the other creature without guard
        state.perform_action(
            Attack(second_player.get_creature_by_index(0),
                   first_player.get_creature_by_index(0)))
Example #2
0
    def _advance_state_attack(self, action: Attack):
        current_player_obj = self.current_player()
        attacker, indexatt = current_player_obj.get_creature_and_index(
            action.attacker())

        # attacking ai
        if action.attacking_player():
            result = self.resolve_attack_player(attacker)
        else:
            defender, indexdef = self.non_current_player(
            ).get_creature_and_index(action.defender())

            result = self.resolve_attack(attacker, defender)

            if result.defender_died():
                self.non_current_player().remove_from_board(defender)
            else:
                self.non_current_player().update_board(indexdef,
                                                       result.defender())

            if result.attacker_died():
                current_player_obj.remove_from_board(attacker)
            else:
                current_player_obj.update_board(indexatt, result.attacker())
        return result
Example #3
0
    def test_charge(self):
        slimer = Constants.CARDS[1]
        wings = Constants.CARDS[140]
        scuttler = Constants.CARDS[2]
        decks = [[wings] + [slimer] * 6, [scuttler] * 7]
        draft = fix_draft(*decks)

        state = GameState(draft)
        first_player = state.get_first_player()
        second_player = state.get_second_player()
        for i in range(5):
            state.open_next_turn()

        self.assertEqual(first_player.current_mana(), 3)
        state.perform_action(Summon(first_player.from_hand(slimer)))
        slimer_creature = first_player.get_creature_by_index(0)
        self.assertEqual(first_player.get_creature_by_index(0),
                         slimer_creature)
        state.perform_action(
            Use(first_player.from_hand(wings), slimer_creature))

        # update as a result of item change
        slimer_creature = first_player.get_creature_by_index(0)
        self.assertTrue(slimer_creature.can_attack())
        self.assertEqual(first_player.num_board_creatures(), 1)

        self.assertTrue(slimer_creature.has_abil(Ability.CHARGE))
        self.assertEqual(
            first_player.get_creature_by_index(0).name(),
            slimer_creature.name())
        state.perform_action(Attack(slimer_creature, None))

        self.assertEqual(first_player.health(), Constants.INITIAL_HEALTH + 1)
        self.assertEqual(second_player.health(), Constants.INITIAL_HEALTH - 2)
Example #4
0
    def test_breakthrough(self):
        slimer = Constants.CARDS[1]
        protein = Constants.CARDS[117]
        scuttler = Constants.CARDS[2]
        decks = [[slimer] * 8 + [protein], [scuttler] * 9]
        draft = fix_draft(*decks)

        state = GameState(draft)
        first_player = state.get_first_player()
        second_player = state.get_second_player()
        for i in range(5):
            state.open_next_turn()

        state.perform_action(Summon(first_player.from_hand(slimer)))
        state.perform_action(
            Use(first_player.from_hand(protein),
                first_player.get_creature_by_index(0)))
        self.assertTrue(
            first_player.get_creature_by_index(0).has_abil(
                Ability.BREAKTHROUGH))
        state.open_next_turn()
        state.perform_action(Summon(second_player.from_hand(scuttler)))
        state.open_next_turn()
        state.perform_action(
            Attack(first_player.get_creature_by_index(0),
                   second_player.get_creature_by_index(0)))
        self.assertEqual(second_player.health(), Constants.INITIAL_HEALTH - 1)
Example #5
0
    def test_attack(self):
        slimer = Constants.CARDS[1]
        scuttler = Constants.CARDS[2]
        decks = [[slimer] * 6, [scuttler] * 6]
        draft = fix_draft(*decks)

        state = GameState(draft)
        state.open_next_turn()
        first_player = state.get_first_player()
        second_player = state.get_second_player()

        state.perform_action(Summon(first_player.from_hand(slimer)))
        with self.assertRaises(IllegalAttackException):
            state.perform_action(
                Attack(first_player.get_creature_by_index(0), None))

        with self.assertRaises(InsufficientManaException):
            # not enough mana for this
            state.perform_action(Summon(first_player.from_hand(slimer)))

        self.assertEqual(first_player.health(), Constants.INITIAL_HEALTH + 1)

        # second ai turn
        state.open_next_turn()
        for i in range(2):
            state.perform_action(Summon(second_player.from_hand(scuttler)))

        # does damage to opp
        self.assertEqual(first_player.health(), Constants.INITIAL_HEALTH - 1)

        with self.assertRaises(InsufficientManaException):
            # not enough mana for this
            state.perform_action(Summon(second_player.from_hand(scuttler)))

        state.open_next_turn()
        a_slimer = first_player.get_creature_by_index(0)
        a_target = second_player.get_creature_by_index(0)
        state.perform_action(Attack(a_slimer, a_target))

        # they should kill each other
        self.assertEqual(first_player.num_board_creatures(), 0)
        self.assertEqual(second_player.num_board_creatures(), 1)
Example #6
0
    def play(self, state: GameState):
        # copy to make decisions
        state = deepcopy(state)
        my_player = state.current_player()
        opp_player = state.non_current_player()
        actions = []

        for card in my_player.get_hand():
            if my_player.current_mana() >= card.cost():
                if card.is_creature() and my_player.num_board_creatures(
                ) < Constants.MAX_CREATURES_IN_LINE:
                    actions.append(Summon(card))
                    state.perform_action(actions[-1])
                elif card.is_item():
                    if card.is_green_item():
                        for target in my_player.board():
                            actions.append(Use(card, target))
                            state.perform_action(actions[-1])
                            break
                    elif card.is_blue_item():
                        actions.append(Use(card, None))
                        state.perform_action(actions[-1])
                    elif card.is_red_item():
                        for target in opp_player.board():
                            actions.append(Use(card, target))
                            state.perform_action(actions[-1])
                            break
        for creature in my_player.board():
            if creature.can_attack():
                targets = opp_player.board()
                if len(targets) > 0:
                    actions.append(Attack(creature, targets[0]))
                else:
                    actions.append(Attack(creature, None))
                state.perform_action(actions[-1])

        return actions
Example #7
0
    def test_drain(self):
        slimer = Constants.CARDS[1]
        scuttler = Constants.CARDS[2]
        imp = Constants.CARDS[38]
        decks = [[slimer] * 8 + [imp], [scuttler] * 9]
        draft = fix_draft(*decks)

        state = GameState(draft)
        first_player = state.get_first_player()
        second_player = state.get_second_player()
        for i in range(5):
            state.open_next_turn()

        state.perform_action(Summon(first_player.from_hand(imp)))
        state.open_next_turn()
        state.open_next_turn()
        state.perform_action(
            Attack(first_player.get_creature_by_index(0), None))
        self.assertEqual(first_player.health(), Constants.INITIAL_HEALTH + 1)
Example #8
0
    def test_ward(self):
        slimer = Constants.CARDS[1]
        scuttler = Constants.CARDS[2]
        sapling = Constants.CARDS[7]
        decks = [[slimer] * 8 + [sapling], [scuttler] * 9]
        draft = fix_draft(*decks)

        state = GameState(draft)
        first_player = state.get_first_player()
        second_player = state.get_second_player()
        for i in range(5):
            state.open_next_turn()

        state.perform_action(Summon(first_player.from_hand(sapling)))
        state.open_next_turn()
        state.perform_action(Summon(second_player.from_hand(scuttler)))
        state.open_next_turn()
        state.open_next_turn()
        self.assertEqual(first_player.get_creature_by_index(0).defense(), 2)
        state.perform_action(
            Attack(second_player.get_creature_by_index(0),
                   first_player.get_creature_by_index(0)))
        # check for annulled ward
        self.assertEqual(first_player.get_creature_by_index(0).defense(), 2)