<commit_before>// Copyright (c) 2018 <NAME>, <NAME>, <NAME>

// We are making my contributions/submissions to this project solely in our
// personal capacity and are not conveying any rights to any intellectual
// property of any third parties.

#include <hspp/Cards/Cards.hpp>
#include <hspp/Managers/GameAgent.hpp>
#include <hspp/Tasks/MetaData.hpp>
#include <hspp/Tasks/PlayerTasks/BriefTask.hpp>
#include <hspp/Tasks/PlayerTasks/CombatTask.hpp>
#include <hspp/Tasks/PlayerTasks/GameEndTask.hpp>
#include <hspp/Tasks/PlayerTasks/MulliganTask.hpp>
#include <hspp/Tasks/PlayerTasks/PlayCardTask.hpp>
#include <hspp/Tasks/PlayerTasks/PlayerSettingTask.hpp>
#include <hspp/Tasks/Requirement.hpp>
#include <hspp/Tasks/SimpleTasks/DrawTask.hpp>
#include <hspp/Tasks/SimpleTasks/InitAttackCountTask.hpp>
#include <hspp/Tasks/SimpleTasks/ModifyManaTask.hpp>
#include <hspp/Tasks/SimpleTasks/ShuffleTask.hpp>
#include <hspp/Tasks/TaskWrapper.hpp>

#include <random>

using namespace Hearthstonepp::PlayerTasks;
using namespace Hearthstonepp::SimpleTasks;

namespace Hearthstonepp
{
GameAgent::GameAgent(CardClass p1Class, CardClass p2Class,
                     PlayerType firstPlayer)
    : m_firstPlayer(firstPlayer), m_currentPlayer(firstPlayer)
{
    m_player1.AddHeroAndPower(
        Cards::GetInstance().GetHeroCard(p1Class),
        Cards::GetInstance().GetDefaultHeroPower(p1Class));
    m_player2.AddHeroAndPower(
        Cards::GetInstance().GetHeroCard(p2Class),
        Cards::GetInstance().GetDefaultHeroPower(p2Class));

    m_player1.SetGameAgent(this);
    m_player2.SetGameAgent(this);

    m_player1.SetOpponent(&m_player2);
    m_player2.SetOpponent(&m_player1);
}

std::thread GameAgent::Start()
{
    auto flow = [this]() {
        BeginPhase();

        while (true)
        {
            const bool isGameEnd = MainPhase();
            if (isGameEnd)
            {
                break;
            }
        }

        FinalPhase();
    };

    return std::thread(std::move(flow));
}

void GameAgent::GetTaskMeta(TaskMeta& meta)
{
    m_taskAgent.Read(meta);
}

void GameAgent::WriteSyncBuffer(TaskMeta&& data, bool isUseSideChannel)
{
    m_taskAgent.Notify(std::move(data), isUseSideChannel);
}

Player& GameAgent::GetPlayer1()
{
    return m_player1;
}

Player& GameAgent::GetPlayer2()
{
    return m_player2;
}

Player& GameAgent::GetFirstPlayer()
{
    return m_firstPlayer == PlayerType::PLAYER1 ? m_player1 : m_player2;
}

void GameAgent::SetFirstPlayer(PlayerType playerType)
{
    m_firstPlayer = playerType;
}

Player& GameAgent::GetCurrentPlayer()
{
    return m_currentPlayer == PlayerType::PLAYER1 ? m_player1 : m_player2;
}

void GameAgent::SetCurrentPlayer(PlayerType playerType)
{
    m_currentPlayer = playerType;
}

Player& GameAgent::GetOpponentPlayer()
{
    return m_currentPlayer == PlayerType::PLAYER1 ? m_player2 : m_player1;
}

MetaData GameAgent::RunTask(Player& player, ITask& task)
{
    return task.Run(player);
}

MetaData GameAgent::RunTask(Player& player, ITask&& task)
{
    return task.Run(player);
}

void GameAgent::NotifyToTaskAgent(TaskMeta& meta, bool sideChannel)
{
    m_taskAgent.Notify(meta, sideChannel);
}

void GameAgent::NotifyToTaskAgent(TaskMeta&& meta, bool sideChannel)
{
    m_taskAgent.Notify(std::move(meta), sideChannel);
}

void GameAgent::KillMinion(Minion& minion) const
{
    auto& field = minion.GetOwner().GetField();
    field.erase(std::find(field.begin(), field.end(), &minion));
}

TaskAgent& GameAgent::GetTaskAgent()
{
    return m_taskAgent;
}

void GameAgent::BeginPhase()
{
    std::random_device rd;
    std::default_random_engine gen(rd());

    // Get random number: zero or one.
    std::uniform_int_distribution<int> bin(0, 1);

    SetFirstPlayer(PlayerType::PLAYER1);
    SetCurrentPlayer(PlayerType::PLAYER1);

    // Swap user with 50% probability
    if (bin(gen) == 1)
    {<commit_msg>[ci skip] refactor: Change logic to call Destroy() method<commit_after>// Copyright (c) 2018 <NAME>, <NAME>, <NAME>

// We are making my contributions/submissions to this project solely in our
// personal capacity and are not conveying any rights to any intellectual
// property of any third parties.

#include <hspp/Cards/Cards.hpp>
#include <hspp/Managers/GameAgent.hpp>
#include <hspp/Tasks/MetaData.hpp>
#include <hspp/Tasks/PlayerTasks/BriefTask.hpp>
#include <hspp/Tasks/PlayerTasks/CombatTask.hpp>
#include <hspp/Tasks/PlayerTasks/GameEndTask.hpp>
#include <hspp/Tasks/PlayerTasks/MulliganTask.hpp>
#include <hspp/Tasks/PlayerTasks/PlayCardTask.hpp>
#include <hspp/Tasks/PlayerTasks/PlayerSettingTask.hpp>
#include <hspp/Tasks/Requirement.hpp>
#include <hspp/Tasks/SimpleTasks/DrawTask.hpp>
#include <hspp/Tasks/SimpleTasks/InitAttackCountTask.hpp>
#include <hspp/Tasks/SimpleTasks/ModifyManaTask.hpp>
#include <hspp/Tasks/SimpleTasks/ShuffleTask.hpp>
#include <hspp/Tasks/TaskWrapper.hpp>

#include <random>

using namespace Hearthstonepp::PlayerTasks;
using namespace Hearthstonepp::SimpleTasks;

namespace Hearthstonepp
{
GameAgent::GameAgent(CardClass p1Class, CardClass p2Class,
                     PlayerType firstPlayer)
    : m_firstPlayer(firstPlayer), m_currentPlayer(firstPlayer)
{
    m_player1.AddHeroAndPower(
        Cards::GetInstance().GetHeroCard(p1Class),
        Cards::GetInstance().GetDefaultHeroPower(p1Class));
    m_player2.AddHeroAndPower(
        Cards::GetInstance().GetHeroCard(p2Class),
        Cards::GetInstance().GetDefaultHeroPower(p2Class));

    m_player1.SetGameAgent(this);
    m_player2.SetGameAgent(this);

    m_player1.SetOpponent(&m_player2);
    m_player2.SetOpponent(&m_player1);
}

std::thread GameAgent::Start()
{
    auto flow = [this]() {
        BeginPhase();

        while (true)
        {
            const bool isGameEnd = MainPhase();
            if (isGameEnd)
            {
                break;
            }
        }

        FinalPhase();
    };

    return std::thread(std::move(flow));
}

void GameAgent::GetTaskMeta(TaskMeta& meta)
{
    m_taskAgent.Read(meta);
}

void GameAgent::WriteSyncBuffer(TaskMeta&& data, bool isUseSideChannel)
{
    m_taskAgent.Notify(std::move(data), isUseSideChannel);
}

Player& GameAgent::GetPlayer1()
{
    return m_player1;
}

Player& GameAgent::GetPlayer2()
{
    return m_player2;
}

Player& GameAgent::GetFirstPlayer()
{
    return m_firstPlayer == PlayerType::PLAYER1 ? m_player1 : m_player2;
}

void GameAgent::SetFirstPlayer(PlayerType playerType)
{
    m_firstPlayer = playerType;
}

Player& GameAgent::GetCurrentPlayer()
{
    return m_currentPlayer == PlayerType::PLAYER1 ? m_player1 : m_player2;
}

void GameAgent::SetCurrentPlayer(PlayerType playerType)
{
    m_currentPlayer = playerType;
}

Player& GameAgent::GetOpponentPlayer()
{
    return m_currentPlayer == PlayerType::PLAYER1 ? m_player2 : m_player1;
}

MetaData GameAgent::RunTask(Player& player, ITask& task)
{
    return task.Run(player);
}

MetaData GameAgent::RunTask(Player& player, ITask&& task)
{
    return task.Run(player);
}

void GameAgent::NotifyToTaskAgent(TaskMeta& meta, bool sideChannel)
{
    m_taskAgent.Notify(meta, sideChannel);
}

void GameAgent::NotifyToTaskAgent(TaskMeta&& meta, bool sideChannel)
{
    m_taskAgent.Notify(std::move(meta), sideChannel);
}

void GameAgent::KillMinion(Minion& minion) const
{
    minion.Destroy();
}

TaskAgent& GameAgent::GetTaskAgent()
{
    return m_taskAgent;
}

void GameAgent::BeginPhase()
{
    std::random_device rd;
    std::default_random_engine gen(rd());

    // Get random number: zero or one.
    std::uniform_int_distribution<int> bin(0, 1);

    SetFirstPlayer(PlayerType::PLAYER1);
    SetCurrentPlayer(PlayerType::PLAYER1);

    // Swap user with 50% probability
    if (bin(gen) == 1)
    {
{'fraction_non_alphanumeric': 0.1261809240326129, 'fraction_numerical': 0.00983564125792675, 'mean_word_length': 4.476966690290574, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '4209833', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2562, 'n_words': 457}