<commit_before>// This code is based on Sabberstone project.
// Copyright (c) 2017-2019 SabberStone Team, darkfriend77 & rnilva
// RosettaStone is hearthstone simulator using C++ with reinforcement learning.
// Copyright (c) 2019 <NAME>, <NAME>, <NAME>

#include <Rosetta/Enchants/Effect.hpp>
#include <Rosetta/Models/Character.hpp>

namespace RosettaStone
{
Effect::Effect(GameTag gameTag, EffectOperator effectOperator, int value)
    : m_gameTag(gameTag), m_effectOperator(effectOperator), m_value(value)
{
    // Do nothing
}

void Effect::Apply(Character* character, bool isOneTurnEffect) const
{
    if (isOneTurnEffect)
    {
        // TODO: Process one turn effect
    }

    const int prevValue = character->GetGameTag(m_gameTag);

    switch (m_effectOperator)
    {
        case EffectOperator::ADD:
            character->SetGameTag(m_gameTag, prevValue + m_value);
            break;
        case EffectOperator::SUB:
            character->SetGameTag(m_gameTag, prevValue - m_value);
            break;
        case EffectOperator::MUL:
            character->SetGameTag(m_gameTag, prevValue * m_value);
            break;
        case EffectOperator::SET:
            character->SetGameTag(m_gameTag, m_value);
            break;
        default:
            throw std::invalid_argument("Invalid effect operator!");
    }
}

void Effect::Apply(AuraEffects& auraEffects) const
{
    const int prevValue = auraEffects.GetGameTag(m_gameTag);

    switch (m_effectOperator)
    {
        case EffectOperator::ADD:
            auraEffects.SetGameTag(m_gameTag, prevValue + m_value);
            break;
        case EffectOperator::SUB:
            auraEffects.SetGameTag(m_gameTag, prevValue - m_value);
            break;
        case EffectOperator::SET:
            auraEffects.SetGameTag(m_gameTag, m_value);
            break;
        default:
            throw std::invalid_argument("Invalid effect operator!");
    }
}

void Effect::Remove(AuraEffects& auraEffects) const
{
    if (m_gameTag == GameTag::HEALTH && m_effectOperator == EffectOperator::ADD)
    {
        auto owner = dynamic_cast<Character*>(auraEffects.GetOwner());
        int prevDamage = owner->GetDamage();
        owner->SetDamage(prevDamage - m_value);
    }

    const int prevValue = auraEffects.GetGameTag(m_gameTag);

    switch (m_effectOperator)
    {
        case EffectOperator::ADD:
            auraEffects.SetGameTag(m_gameTag, prevValue - m_value);
            break;
        case EffectOperator::SUB:
            auraEffects.SetGameTag(m_gameTag, prevValue + m_value);
            break;
        case EffectOperator::SET:
            auraEffects.SetGameTag(m_gameTag, prevValue - m_value);
            break;
        default:
            throw std::invalid_argument("Invalid effect operator!");
    }
}
}  // namespace RosettaStone
<commit_msg>fix: Add missing <stdexcept> header file<commit_after>// This code is based on Sabberstone project.
// Copyright (c) 2017-2019 SabberStone Team, darkfriend77 & rnilva
// RosettaStone is hearthstone simulator using C++ with reinforcement learning.
// Copyright (c) 2019 <NAME>, <NAME>, <NAME>

#include <Rosetta/Enchants/Effect.hpp>
#include <Rosetta/Models/Character.hpp>

#include <stdexcept>

namespace RosettaStone
{
Effect::Effect(GameTag gameTag, EffectOperator effectOperator, int value)
    : m_gameTag(gameTag), m_effectOperator(effectOperator), m_value(value)
{
    // Do nothing
}

void Effect::Apply(Character* character, bool isOneTurnEffect) const
{
    if (isOneTurnEffect)
    {
        // TODO: Process one turn effect
    }

    const int prevValue = character->GetGameTag(m_gameTag);

    switch (m_effectOperator)
    {
        case EffectOperator::ADD:
            character->SetGameTag(m_gameTag, prevValue + m_value);
            break;
        case EffectOperator::SUB:
            character->SetGameTag(m_gameTag, prevValue - m_value);
            break;
        case EffectOperator::MUL:
            character->SetGameTag(m_gameTag, prevValue * m_value);
            break;
        case EffectOperator::SET:
            character->SetGameTag(m_gameTag, m_value);
            break;
        default:
            throw std::invalid_argument("Invalid effect operator!");
    }
}

void Effect::Apply(AuraEffects& auraEffects) const
{
    const int prevValue = auraEffects.GetGameTag(m_gameTag);

    switch (m_effectOperator)
    {
        case EffectOperator::ADD:
            auraEffects.SetGameTag(m_gameTag, prevValue + m_value);
            break;
        case EffectOperator::SUB:
            auraEffects.SetGameTag(m_gameTag, prevValue - m_value);
            break;
        case EffectOperator::SET:
            auraEffects.SetGameTag(m_gameTag, m_value);
            break;
        default:
            throw std::invalid_argument("Invalid effect operator!");
    }
}

void Effect::Remove(AuraEffects& auraEffects) const
{
    if (m_gameTag == GameTag::HEALTH && m_effectOperator == EffectOperator::ADD)
    {
        auto owner = dynamic_cast<Character*>(auraEffects.GetOwner());
        int prevDamage = owner->GetDamage();
        owner->SetDamage(prevDamage - m_value);
    }

    const int prevValue = auraEffects.GetGameTag(m_gameTag);

    switch (m_effectOperator)
    {
        case EffectOperator::ADD:
            auraEffects.SetGameTag(m_gameTag, prevValue - m_value);
            break;
        case EffectOperator::SUB:
            auraEffects.SetGameTag(m_gameTag, prevValue + m_value);
            break;
        case EffectOperator::SET:
            auraEffects.SetGameTag(m_gameTag, prevValue - m_value);
            break;
        default:
            throw std::invalid_argument("Invalid effect operator!");
    }
}
}  // namespace RosettaStone

{'fraction_non_alphanumeric': 0.10102769552342797, 'fraction_numerical': 0.004877199094234454, 'mean_word_length': 2.72615184944841, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, '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': '1193334', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1629, 'n_words': 355}