<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/Cards/Cards.hpp>
#include <Rosetta/Games/Game.hpp>
#include <Rosetta/Models/Enchantment.hpp>
#include <Rosetta/Tasks/SimpleTasks/AddEnchantmentTask.hpp>
#include <Rosetta/Tasks/SimpleTasks/IncludeTask.hpp>

namespace RosettaStone::SimpleTasks
{
AddEnchantmentTask::AddEnchantmentTask(std::string&& cardID,
                                       EntityType entityType)
    : ITask(entityType), m_cardID(cardID)
{
    // Do nothing
}

TaskID AddEnchantmentTask::GetTaskID() const
{
    return TaskID::ADD_ENCHANTMENT;
}

TaskStatus AddEnchantmentTask::Impl(Player& player)
{
    Card enchantmentCard = Cards::FindCardByID(m_cardID);
    if (enchantmentCard.id.empty())
    {
        return TaskStatus::STOP;
    }

    auto entities =
        IncludeTask::GetEntities(m_entityType, player, m_source, m_target);
    Power power = Cards::FindCardByID(m_cardID).power;

    for (auto& entity : entities)
    {
        const auto enchantment =
            Enchantment::GetInstance(player, enchantmentCard, entity);

        if (power.GetAura().has_value())
        {
            power.GetAura().value().Activate(*enchantment);
        }

        if (power.GetTrigger().has_value())
        {
            power.GetTrigger().value().Activate(*enchantment);
        }

        if (power.GetEnchant().has_value())
        {
            const auto& taskStack = player.GetGame()->taskStack;
            power.GetEnchant().value().ActivateTo(entity, taskStack.num,
                                                  taskStack.num1);
        }
    }

    return TaskStatus::COMPLETE;
}
}  // namespace RosettaStone::SimpleTasks
<commit_msg>refactor: Change 'Cards::FindCardByID(m_cardID)' to 'enchantmentCard'<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/Cards/Cards.hpp>
#include <Rosetta/Games/Game.hpp>
#include <Rosetta/Models/Enchantment.hpp>
#include <Rosetta/Tasks/SimpleTasks/AddEnchantmentTask.hpp>
#include <Rosetta/Tasks/SimpleTasks/IncludeTask.hpp>

namespace RosettaStone::SimpleTasks
{
AddEnchantmentTask::AddEnchantmentTask(std::string&& cardID,
                                       EntityType entityType)
    : ITask(entityType), m_cardID(cardID)
{
    // Do nothing
}

TaskID AddEnchantmentTask::GetTaskID() const
{
    return TaskID::ADD_ENCHANTMENT;
}

TaskStatus AddEnchantmentTask::Impl(Player& player)
{
    Card enchantmentCard = Cards::FindCardByID(m_cardID);
    if (enchantmentCard.id.empty())
    {
        return TaskStatus::STOP;
    }

    auto entities =
        IncludeTask::GetEntities(m_entityType, player, m_source, m_target);
    Power power = enchantmentCard.power;

    for (auto& entity : entities)
    {
        const auto enchantment =
            Enchantment::GetInstance(player, enchantmentCard, entity);

        if (power.GetAura().has_value())
        {
            power.GetAura().value().Activate(*enchantment);
        }

        if (power.GetTrigger().has_value())
        {
            power.GetTrigger().value().Activate(*enchantment);
        }

        if (power.GetEnchant().has_value())
        {
            const auto& taskStack = player.GetGame()->taskStack;
            power.GetEnchant().value().ActivateTo(entity, taskStack.num,
                                                  taskStack.num1);
        }
    }

    return TaskStatus::COMPLETE;
}
}  // namespace RosettaStone::SimpleTasks

{'fraction_non_alphanumeric': 0.12069864442127216, 'fraction_numerical': 0.007820646506777894, 'mean_word_length': 2.8485456369107323, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5213722', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1149, 'n_words': 210}