<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/Actions/Draw.hpp>
#include <hspp/Models/Player.hpp>

namespace Hearthstonepp::Generic
{
Entity* Draw(Player& player, std::optional<Entity> card)
{
    if (player.GetDeck().IsEmpty())
    {
        const std::size_t fatigueDamage =
            player.GetHero()->fatigue == 0 ? 1 : player.GetHero()->fatigue + 1;
        player.GetHero()->TakeDamage(*player.GetHero(), fatigueDamage);

        return nullptr;
    }

    Entity* entity;

    if (card.has_value())
    {
        entity = &player.GetDeck().RemoveCard(card.value());
    }
    else
    {
        Entity* topCard = player.GetDeck().GetTopCard();
        if (topCard == nullptr)
        {
            return nullptr;
        }

        entity = &player.GetDeck().RemoveCard(*topCard);
    }

    player.GetHand().AddCard(*entity);

    return entity;
}

Entity* DrawCard(Player& player, Card&& card)
{
    Entity* entity = Entity::GetFromCard(player, std::move(card));
    player.GetHand().AddCard(*entity);

    return entity;
}
}  // namespace Hearthstonepp::Generic<commit_msg>[ci skip] refactor: Apply changes of Hand-related functions<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/Actions/Draw.hpp>
#include <hspp/Actions/Generic.hpp>
#include <hspp/Models/Player.hpp>

namespace Hearthstonepp::Generic
{
Entity* Draw(Player& player, std::optional<Entity> card)
{
    if (player.GetDeck().IsEmpty())
    {
        const std::size_t fatigueDamage =
            player.GetHero()->fatigue == 0 ? 1 : player.GetHero()->fatigue + 1;
        player.GetHero()->TakeDamage(*player.GetHero(), fatigueDamage);

        return nullptr;
    }

    Entity* entity;

    if (card.has_value())
    {
        entity = &player.GetDeck().RemoveCard(card.value());
    }
    else
    {
        Entity* topCard = player.GetDeck().GetTopCard();
        if (topCard == nullptr)
        {
            return nullptr;
        }

        entity = &player.GetDeck().RemoveCard(*topCard);
    }

	Generic::AddCardToHand(player, entity);

    return entity;
}

Entity* DrawCard(Player& player, Card&& card)
{
    Entity* entity = Entity::GetFromCard(player, std::move(card));
    Generic::AddCardToHand(player, entity);

    return entity;
}
}  // namespace Hearthstonepp::Generic
{'fraction_non_alphanumeric': 0.14544112218530822, 'fraction_numerical': 0.012550756736803248, 'mean_word_length': 3.1248097412480975, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 22, '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': '7434117', 'n_tokens_mistral': 901, 'n_tokens_neox': 835, 'n_words': 188}