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

#include <hspp/Tasks/SimpleTasks/ModifyManaTask.hpp>

namespace Hearthstonepp::SimpleTasks
{
ModifyManaTask::ModifyManaTask(ManaOperator numMode, ManaType manaMode,
                               BYTE num)
    : m_numMode(numMode), m_manaMode(manaMode), m_num(num)
{
    // Do nothing
}

TaskID ModifyManaTask::GetTaskID() const
{
    return TaskID::MODIFY_MANA;
}

TaskStatus ModifyManaTask::Impl(Player& player)
{
    const auto getMana = [](Player& p, ManaType mode) -> BYTE {
        if (mode == ManaType::AVAILABLE)
        {
            return p.GetAvailableMana();
        }

        if (mode == ManaType::MAXIMUM)
        {
            return p.GetMaximumMana();
        }

        throw std::runtime_error("ModifyMana: Invalid mana mode");
    };

    BYTE mana = getMana(player, m_manaMode);
    switch (m_numMode)
    {
        case ManaOperator::ADD:
            mana += m_num;
            break;
        case ManaOperator::SUB:
            mana = (mana <= m_num) ? 0 : (mana - m_num);
            break;
        case ManaOperator::SET:
            mana = m_num;
            break;
    }

    // Clamps a mana cost to a given range (min:0 ~ max:10)
    mana = std::clamp(mana, static_cast<BYTE>(0), static_cast<BYTE>(10));

    if (m_manaMode == ManaType::AVAILABLE)
    {
        player.SetAvailableMana(mana);
    }

    if (m_manaMode == ManaType::MAXIMUM)
    {
        player.SetMaximumMana(mana);
    }

    return TaskStatus::MODIFY_MANA_SUCCESS;
}
}  // namespace Hearthstonepp::SimpleTasks<commit_msg>fix: Add missing <algorithm> header for std::clamp<commit_after>// This code is based on Sabberstone project.
// Copyright (c) 2017-2018 SabberStone Team, darkfriend77 & rnilva
// Hearthstone++ is hearthstone simulator using C++ with reinforcement learning.
// Copyright (c) 2018 <NAME>, <NAME>, <NAME>

#include <hspp/Tasks/SimpleTasks/ModifyManaTask.hpp>

#include <algorithm>

namespace Hearthstonepp::SimpleTasks
{
ModifyManaTask::ModifyManaTask(ManaOperator numMode, ManaType manaMode,
                               BYTE num)
    : m_numMode(numMode), m_manaMode(manaMode), m_num(num)
{
    // Do nothing
}

TaskID ModifyManaTask::GetTaskID() const
{
    return TaskID::MODIFY_MANA;
}

TaskStatus ModifyManaTask::Impl(Player& player)
{
    const auto getMana = [](Player& p, ManaType mode) -> BYTE {
        if (mode == ManaType::AVAILABLE)
        {
            return p.GetAvailableMana();
        }

        if (mode == ManaType::MAXIMUM)
        {
            return p.GetMaximumMana();
        }

        throw std::runtime_error("ModifyMana: Invalid mana mode");
    };

    BYTE mana = getMana(player, m_manaMode);
    switch (m_numMode)
    {
        case ManaOperator::ADD:
            mana += m_num;
            break;
        case ManaOperator::SUB:
            mana = (mana <= m_num) ? 0 : (mana - m_num);
            break;
        case ManaOperator::SET:
            mana = m_num;
            break;
    }

    // Clamps a mana cost to a given range (min:0 ~ max:10)
    mana = std::clamp(mana, static_cast<BYTE>(0), static_cast<BYTE>(10));

    if (m_manaMode == ManaType::AVAILABLE)
    {
        player.SetAvailableMana(mana);
    }

    if (m_manaMode == ManaType::MAXIMUM)
    {
        player.SetMaximumMana(mana);
    }

    return TaskStatus::MODIFY_MANA_SUCCESS;
}
}  // namespace Hearthstonepp::SimpleTasks
{'fraction_non_alphanumeric': 0.12012178245225574, 'fraction_numerical': 0.011624688624411846, 'mean_word_length': 2.550098231827112, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5993858', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1207, 'n_words': 261}