<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/Games/Game.hpp>
#include <Rosetta/Tasks/SimpleTasks/FilterStackTask.hpp>
#include <Rosetta/Tasks/SimpleTasks/IncludeTask.hpp>

#include <utility>

namespace RosettaStone::SimpleTasks
{
FilterStackTask::FilterStackTask(EntityType entityType,
                                 SelfCondition selfCondition)
    : ITask(entityType),
      m_selfCondition(new SelfCondition(std::move(selfCondition)))
{
    // Do nothing
}

TaskID FilterStackTask::GetTaskID() const
{
    return TaskID::FILTER_STACK;
}

TaskStatus FilterStackTask::Impl(Player& player)
{
    std::vector<Entity*> result;

    auto entities =
        IncludeTask::GetEntities(m_entityType, player, m_source, m_target);

    for (auto& entity : entities)
    {
        if (m_selfCondition != nullptr)
        {
            if (m_selfCondition->Evaluate(entity))
            {
                result.emplace_back(entity);
            }
        }
    }

    player.GetGame()->taskStack.entities = result;

    return TaskStatus::COMPLETE;
}
}  // namespace RosettaStone::SimpleTasks<commit_msg>fix: Correct task process logic<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/Games/Game.hpp>
#include <Rosetta/Tasks/SimpleTasks/FilterStackTask.hpp>
#include <Rosetta/Tasks/SimpleTasks/IncludeTask.hpp>

#include <utility>

namespace RosettaStone::SimpleTasks
{
FilterStackTask::FilterStackTask(EntityType entityType,
                                 SelfCondition selfCondition)
    : ITask(entityType),
      m_selfCondition(new SelfCondition(std::move(selfCondition)))
{
    // Do nothing
}

TaskID FilterStackTask::GetTaskID() const
{
    return TaskID::FILTER_STACK;
}

TaskStatus FilterStackTask::Impl(Player& player)
{
    if (m_selfCondition != nullptr)
    {
        std::vector<Entity*> filtered;
        filtered.reserve(player.GetGame()->taskStack.entities.size());

        for (auto& entity : player.GetGame()->taskStack.entities)
        {
            if (m_selfCondition->Evaluate(entity))
            {
                filtered.emplace_back(entity);
            }
        }

        player.GetGame()->taskStack.entities = filtered;
    }

    return TaskStatus::COMPLETE;
}
}  // namespace RosettaStone::SimpleTasks
{'fraction_non_alphanumeric': 0.11455223880597015, 'fraction_numerical': 0.010447761194029851, 'mean_word_length': 3.2691082802547773, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2398270', 'n_tokens_mistral': 822, 'n_tokens_neox': 773, 'n_words': 160}