<commit_before>import random
import constants
from copy import deepcopy, copy

from log import Logger
from demons import DemonPlayer



class Fight():
    def __init__(self, player, opp):
        self.player = player
        self.opp = opp
        self.turn = 1
        self.results = list()
        self.dmg_done = 0
        self.dmg_per_min = 0
        self.cooldown = self._calc_cooldown()
        self.player_on_deck = list()
        self.opp_on_deck = list()
        self.player_in_play = list()
        self.opp_in_play = list()
        self.player_turn = False
        self.card = None
        self.def_card = None
        self.index = 0
        self.player_cemetery = list()
        self.opp_cemetery = list()
        self.player_runes_triggered = list()
        self.opp_runes_triggered = list()
        self.sim_fight()

    def sim_fight(self):
        self._prep_cards()
        while self.player.hp > 0 and self.opp.hp > 0 and \
                (len(self.player.card_order) > 0 or
                 len(self.player_on_deck) > 0 or
                 len(self.player_in_play) > 0):
            self._prep_turn()
            self._handle_runes()
            self._resolve_all_healths()
            self._handle_attack()
            self._resolve_all_healths()
            self._undo_runes()
##            self.log_turn()

            self.turn += 1

        self.fight_summary()

    def log_turn(self):

        demonHealth=0
        if(len(self.opp_in_play) > 0):
            demonHealth=self.opp_in_play[0].hp

        Logger.log('Turn {}'.format(self.turn) +
                   ': Player Health={}'.format(self.player.hp) +
                    ' : Demon Health={}'.format(demonHealth))

        Logger.log("Cards in Deck:")
        for card in self.player_on_deck:
            Logger.log(card.__str__())
        Logger.log("Cards in Play:")
        for card in self.player_in_play:
            Logger.log(card.__str__())
        Logger.log("Cards in Cemetery:")
        for card in self.player_cemetery:
            Logger.log(card.__str__())
        Logger.log("\n")


    def _calc_cooldown(self):
        deck_cost = 0
        for card in self.player.cards:
            deck_cost += card.cost
        return (60 + 2 * deck_cost)/60

    def fight_summary(self):
        if isinstance(self.opp, DemonPlayer):
            self.dmg_done = self.opp_in_play[0].\
                get_base_hp() - self.opp_in_play[0].hp
            for card in self.player.cards:
                if card.merit:
                    self.dmg_done += 100
            self.dmg_per_min = self.dmg_done / self.cooldown

    def _handle_exiting_effects(self, card):
        exit_summary = card.exit_effect()
        for effect in exit_summary:
            self._handle_effect(effect)

    def _put_card_in_cemetery_from_deck(self, card):
        if card in self.player_on_deck:
            self.player_on_deck.remove(card)
            if card.should_res:
                self.player.card_order.append(card)<commit_msg>Add change GitHub missed<commit_after>import random
import constants
from copy import deepcopy, copy

from log import Logger
from demons import DemonPlayer



class Fight():
    def __init__(self, player, opp):
        self.player = player
        self.opp = opp
        self.turn = 1
        self.results = list()
        self.dmg_done = 0
        self.dmg_per_min = 0
        self.cooldown = self._calc_cooldown()
        self.player_on_deck = list()
        self.opp_on_deck = list()
        self.player_in_play = list()
        self.opp_in_play = list()
        self.player_turn = False
        self.card = None
        self.def_card = None
        self.index = 0
        self.player_cemetery = list()
        self.opp_cemetery = list()
        self.player_runes_triggered = list()
        self.opp_runes_triggered = list()
        self.sim_fight()

    def sim_fight(self):
        self._prep_cards()
        while self.player.hp > 0 and self.opp.hp > 0 and \
                (len(self.player.card_order) > 0 or
                 len(self.player_on_deck) > 0 or
                 len(self.player_in_play) > 0):
            self._prep_turn()
            self._handle_runes()
            self._resolve_all_healths()
            self._handle_attack()
            self._resolve_all_healths()
            self._undo_runes()
##            self.log_turn()

            self.turn += 1

        self.fight_summary()

    def log_turn(self):

        demonHealth=0
        if(len(self.opp_in_play) > 0):
            demonHealth=self.opp_in_play[0].hp

        Logger.log('Turn {}'.format(self.turn) +
                   ': Player Health={}'.format(self.player.hp) +
                    ' : Demon Health={}'.format(demonHealth))

        Logger.log("Cards in Deck:")
        for card in self.player_on_deck:
            Logger.log(card.__str__())
        Logger.log("Cards in Play:")
        for card in self.player_in_play:
            Logger.log(card.__str__())
        Logger.log("Cards in Cemetery:")
        for card in self.player_cemetery:
            Logger.log(card.__str__())
        Logger.log("\n")


    def _calc_cooldown(self):
        deck_cost = 0
        for card in self.player.cards:
            deck_cost += card.cost
        return (60 + 2 * deck_cost)/60

    def fight_summary(self):
        if isinstance(self.opp, DemonPlayer):
            self.dmg_done = self.opp_in_play[0].\
                _get_base_hp() - self.opp_in_play[0].hp
            for card in self.player.cards:
                if card.merit:
                    self.dmg_done += 100
            self.dmg_per_min = self.dmg_done / self.cooldown

    def _handle_exiting_effects(self, card):
        exit_summary = card.exit_effect()
        for effect in exit_summary:
            self._handle_effect(effect)

    def _put_card_in_cemetery_from_deck(self, card):
        if card in self.player_on_deck:
            self.player_on_deck.remove(card)
            if card.should_res:
                self.player.card_order.append(card)
{'fraction_non_alphanumeric': 0.1023936170212766, 'fraction_numerical': 0.007978723404255319, 'mean_word_length': 1.8195876288659794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1834812', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1837, 'n_words': 366}