<commit_before>from random import randint
import re
import hsgame
import hsgame.constants
import hsgame.game_objects
import hsgame.cards
import hsgame.game_objects

__author__ = 'Daniel'


class ReplayException(Exception):
    def __init__(self, message):
        super().__init__(message)


class ProxyCharacter:

    def __init__(self, character_ref, game=None):
        if type(character_ref) is str:
            self.character_ref = character_ref
        elif type(character_ref) is hsgame.game_objects.Hero:
            if character_ref == game.players[0].hero:
                self.character_ref = "p1"
            else:
                self.character_ref = "p2"
        elif type(character_ref) is hsgame.game_objects.Minion:
            if character_ref.player == game.players[0].hero:
                self.character_ref = "p1:" + str(character_ref.index)
            else:
                self.character_ref = "p2:" + str(character_ref.index)

    def resolve(self, game):
        ref = self.character_ref.split(':')
        if ref[0] == "p1":
            char = game.players[0].hero
        else:
            char = game.players[1].hero
        if len(ref) > 1:
            if ref[0] == "p1":
                char = game.players[0].minions[int(ref[1])]
            else:
               char = game.players[1].minions[int(ref[1])]

        return char

    def __str__(self):
        return self.character_ref

    def to_output(self):
        return str(self)


class ProxyCard:

    def __init__(self, card_reference, game=None):
        self.card_ref = -1
        if type(card_reference) is str:
            self.card_ref = card_reference
        else:
            index = 0
            for card in game.current_player.hand:
                if card is card_reference:
                    self.card_ref = index
                    break
                index += 1

        if self.card_ref is -1:
            raise ReplayException("Could not find card in hand")

        self.targetable = False

    def set_option(self, option):
        self.card_ref = ":" + str(option)

    def resolve(self, game):
        ref = self.card_ref.split(':')
        if len(ref) > 1:
            game.current_player.agent.next_option = int(ref[1])
        return game.current_player.hand[int(ref[0])]

    def __str__(self):
        return str(self.card_ref)

    def to_output(self):
        return str(self)


class ReplayAction:
        def play(self, game):
            pass


class SpellAction(ReplayAction):
    def __init__(self, card, target=None, game=None):
        self.card = card
        if target is not None:
            self.target = ProxyCharacter(target, game)
        else:
            self.target = None

    def play(self, game):
        if self.target is not None:
            game.current_player.agent.next_target = self.target.resolve(game)
        game.play_card(self.card.resolve(game))
        game.current_player.agent.next_target = None

    def to_output_string(self):
        if self.target is not None:
            return 'play({0},{1})'.format(self.card.to_output(), self.target.to_output())
        return 'play({0})'.format(self.card.to_output())


class MinionAction(ReplayAction):
    def __init__(self, card, index, target=None, game=None):
        self.card = card
        self.index = index
        if target is not None:
            self.target = ProxyCharacter(target, game)
        else:
            self.target = None

    def to_output_string(self):
        if self.target is not None:
            return 'summon({0},{1},{2})'.format(self.card.to_output(), self.index, self.target.to_output())
        return 'summon({0},{1})'.format(self.card.to_output(), self.index)

    def play(self, game):
        if self.target is not None:
            game.current_player.agent.next_target = self.target.resolve(game)

        game.current_player.agent.next_index = self.index
        game.play_card(self.card.resolve(game))
        game.current_player.agent.nextIndex = -1


class AttackAction(ReplayAction):
    def __init__(self, character, target, game=None):
        self.character = ProxyCharacter(character, game)
        self.target = ProxyCharacter(target, game)

    def to_output_string(self):
            return 'attack({0},{1})'.format(self.character.to_output(), self.target.to_output())

    def play(self, game):
        game.current_player.agent.next_target = self.target.resolve(game)
        self.character.resolve(game).attack()
        game.current_player.agent.next_target = None


class PowerAction(ReplayAction):
    def __init__(self, target=None, game=None):
        self.target = target
        if target is not None:
            self.target = ProxyCharacter(target, game)
        else:
            self.target = None
        self.game = game

    def to_output_string(self):
        if self.target is not None:
            return 'power({0})'.format(self.target.to_output())
        else:
            return 'power()'

    def play(self, game):
        if self.target is not None:
            game.current_player.agent.next_target = self.target.resolve()
        self.target.resolve().attack()
        game.current_player.agent.next_target = None


class TurnEndAction(ReplayAction):
    def __init__(self, game=None):
        pass

    def to_output_string(self):
        return 'end()'

    def play(self, game):
        pass


class ConcedeAction(ReplayAction):
    def __init__(self):
        pass

    def to_output_string(self):
        return "concede()"

    def play(self, game):
        game.current_player.hero.die(None)
        game.current_player.hero.activate_delayed()


class Replay:

    def __init__(self):<commit_msg>Fixed some bugs with replay<commit_after>from random import randint
import re
import hsgame
import hsgame.constants
import hsgame.game_objects
import hsgame.cards
import hsgame.game_objects

__author__ = 'Daniel'


class ReplayException(Exception):
    def __init__(self, message):
        super().__init__(message)


class ProxyCharacter:

    def __init__(self, character_ref, game=None):
        if type(character_ref) is str:
            self.character_ref = character_ref
        elif type(character_ref) is hsgame.game_objects.Hero:
            if character_ref == game.players[0].hero:
                self.character_ref = "p1"
            else:
                self.character_ref = "p2"
        elif type(character_ref) is hsgame.game_objects.Minion:
            if character_ref.player == game.players[0].hero:
                self.character_ref = "p1:" + str(character_ref.index)
            else:
                self.character_ref = "p2:" + str(character_ref.index)

    def resolve(self, game):
        ref = self.character_ref.split(':')
        if ref[0] == "p1":
            char = game.players[0].hero
        else:
            char = game.players[1].hero
        if len(ref) > 1:
            if ref[0] == "p1":
                char = game.players[0].minions[int(ref[1])]
            else:
                char = game.players[1].minions[int(ref[1])]

        return char

    def __str__(self):
        return self.character_ref

    def to_output(self):
        return str(self)


class ProxyCard:

    def __init__(self, card_reference, game=None):
        self.card_ref = -1
        if type(card_reference) is str:
            self.card_ref = card_reference
        else:
            index = 0
            for card in game.current_player.hand:
                if card is card_reference:
                    self.card_ref = index
                    break
                index += 1

        if self.card_ref is -1:
            raise ReplayException("Could not find card in hand")

        self.targetable = False

    def set_option(self, option):
        self.card_ref = ":" + str(option)

    def resolve(self, game):
        ref = self.card_ref.split(':')
        if len(ref) > 1:
            game.current_player.agent.next_option = int(ref[1])
        return game.current_player.hand[int(ref[0])]

    def __str__(self):
        return str(self.card_ref)

    def to_output(self):
        return str(self)


class ReplayAction:
        def play(self, game):
            pass


class SpellAction(ReplayAction):
    def __init__(self, card, target=None, game=None):
        self.card = card
        if target is not None:
            self.target = ProxyCharacter(target, game)
        else:
            self.target = None

    def play(self, game):
        if self.target is not None:
            game.current_player.agent.next_target = self.target.resolve(game)
        game.play_card(self.card.resolve(game))
        game.current_player.agent.next_target = None

    def to_output_string(self):
        if self.target is not None:
            return 'play({0},{1})'.format(self.card.to_output(), self.target.to_output())
        return 'play({0})'.format(self.card.to_output())


class MinionAction(ReplayAction):
    def __init__(self, card, index, target=None, game=None):
        self.card = card
        self.index = index
        if target is not None:
            self.target = ProxyCharacter(target, game)
        else:
            self.target = None

    def to_output_string(self):
        if self.target is not None:
            return 'summon({0},{1},{2})'.format(self.card.to_output(), self.index, self.target.to_output())
        return 'summon({0},{1})'.format(self.card.to_output(), self.index)

    def play(self, game):
        if self.target is not None:
            game.current_player.agent.next_target = self.target.resolve(game)

        game.current_player.agent.next_index = self.index
        game.play_card(self.card.resolve(game))
        game.current_player.agent.nextIndex = -1


class AttackAction(ReplayAction):
    def __init__(self, character, target, game=None):
        self.character = ProxyCharacter(character, game)
        self.target = ProxyCharacter(target, game)

    def to_output_string(self):
            return 'attack({0},{1})'.format(self.character.to_output(), self.target.to_output())

    def play(self, game):
        game.current_player.agent.next_target = self.target.resolve(game)
        self.character.resolve(game).attack()
        game.current_player.agent.next_target = None


class PowerAction(ReplayAction):
    def __init__(self, target=None, game=None):
        self.target = target
        if target is not None:
            self.target = ProxyCharacter(target, game)
        else:
            self.target = None
        self.game = game

    def to_output_string(self):
        if self.target is not None:
            return 'power({0})'.format(self.target.to_output())
        else:
            return 'power()'

    def play(self, game):
        if self.target is not None:
            game.current_player.agent.next_target = self.target.resolve(game)
        game.current_player.hero.power.use()
        game.current_player.agent.next_target = None


class TurnEndAction(ReplayAction):
    def __init__(self, game=None):
        pass

    def to_output_string(self):
        return 'end()'

    def play(self, game):
        pass


class ConcedeAction(ReplayAction):
    def __init__(self):
        pass

    def to_output_string(self):
        return "concede()"

    def play(self, game):
        game.current_player.hero.die(None)
        game.current_player.hero.activate_delayed()


class Replay:

    def __init__(self):
{'fraction_non_alphanumeric': 0.1108385174800666, 'fraction_numerical': 0.006308595461316043, 'mean_word_length': 2.25834998572652, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, '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': '1598741', 'n_tokens_mistral': 3508, 'n_tokens_neox': 3396, 'n_words': 745}