<commit_before>/*************************************************************************
> File Name: Console.cpp
> Project Name: Hearthstone++
> Author: <NAME>
> Purpose: Console version of Hearthstone++ game.
> Created Time: 2017/10/08
> Copyright (c) 2017, <NAME>
*************************************************************************/
#include <Agents/GameAgent.h>
#include <Commons/Constants.h>
#include <Enums/EnumsToString.h>
#include <Loaders/CardLoader.h>
#include <Loaders/PlayerLoader.h>
#include <Models/Card.h>
#include <Models/Cards.h>
#include <Programs/Console.h>

#include <filesystem>
#include <fstream>
#include <iostream>

namespace filesystem = std::experimental::filesystem;

namespace Hearthstonepp
{
	template<std::size_t SIZE>
	void Console::ShowMenu(std::array<std::string, SIZE>& menus)
	{
		std::cout << "========================================\n";
		for (auto& menu : menus)
		{
			std::cout << menu.c_str() << '\n';
		}
		std::cout << "========================================\n";
	}

	size_t Console::InputMenuNum(std::string questionStr, size_t menuSize)
	{
		while (true)
		{
			std::cout << questionStr;
			size_t num;
			std::cin >> num;

			if (num < 1 || num > menuSize)
			{
				std::cout << "Invalid number! Try again.\n";
			}
			else
			{
				return num;
			}
		}
	}

	bool Console::InputYesNo(std::string sentence) const
	{
		std::cout << sentence;
		std::cout << "(Please input \"y/yes\" or \"n/no\" (insensitive))\n";
		std::cout << "Input: ";

		std::string str;
		std::cin >> str;
		std::transform(str.begin(), str.end(), str.begin(), ::tolower);

		return (str == "y" || str == "yes") ? true : (str == "n" || str == "no") ? false : InputYesNo(sentence);
	}

	void Console::SignIn()
	{
		std::cout << "Input Player ID to load data.\n";
		std::cout << "If you do not want to load, please input \"STOP\"\n";

		while (true)
		{
			std::cout << "Player ID: ";
			std::string playerID;
			std::cin >> playerID;

			if (playerID == "STOP")
			{
				break;
			}

			if (!filesystem::exists("Datas/" + playerID + ".json"))
			{
				std::cout << playerID << ".json doesn't exist. Try again.\n";
				continue;
			}

			PlayerLoader loader;
			m_player = loader.Load(playerID);

			if (m_player == nullptr)
			{
				std::cout << "An error occurred while loading player data.\n";
				continue;
			}

			std::cout << "You are signed in. Hello, " << playerID << "!\n";

			Main();

			break;
		}
	}

	void Console::SignUp()
	{
		std::cout << "Input Player ID to create data.\n";

		while (true)
		{
			std::cout << "Player ID: ";
			std::string playerID;
			std::cin >> playerID;

			if (filesystem::exists("Datas/" + playerID + ".json"))
			{
				std::cout << playerID << ".json already exists. Try again.\n";
				continue;
			}

			std::cout << "Name: ";
			std::string name;
			std::cin >> name;

			m_player = new Player(std::move(playerID), std::move(name));

			PlayerLoader loader;
			loader.Save(m_player);

			std::cout << "Your account has been created. Please sign in.\n";
			break;
		}
	}

	void Console::SearchCard()
	{

	}

	int Console::ManageDeck()
	{
		std::cout << "========================================\n";
		std::cout << "              Manage Deck!              \n";
		std::cout << "========================================\n";

		ShowMenu(m_manageDeckStr);
		const size_t selectedNum = InputMenuNum("Select: ", MANAGE_DECK_MENU_SIZE);
		bool isFinish = false;
<commit_msg>Update Console - Implement SearchCard method<commit_after>/*************************************************************************
> File Name: Console.cpp
> Project Name: Hearthstone++
> Author: <NAME>
> Purpose: Console version of Hearthstone++ game.
> Created Time: 2017/10/08
> Copyright (c) 2017, <NAME>
*************************************************************************/
#include <Agents/GameAgent.h>
#include <Commons/Constants.h>
#include <Enums/EnumsToString.h>
#include <Loaders/CardLoader.h>
#include <Loaders/PlayerLoader.h>
#include <Models/Card.h>
#include <Models/Cards.h>
#include <Programs/Console.h>

#include <filesystem>
#include <fstream>
#include <iostream>

namespace filesystem = std::experimental::filesystem;

namespace Hearthstonepp
{
	template<std::size_t SIZE>
	void Console::ShowMenu(std::array<std::string, SIZE>& menus)
	{
		std::cout << "========================================\n";
		for (auto& menu : menus)
		{
			std::cout << menu.c_str() << '\n';
		}
		std::cout << "========================================\n";
	}

	size_t Console::InputMenuNum(std::string questionStr, size_t menuSize)
	{
		while (true)
		{
			std::cout << questionStr;
			size_t num;
			std::cin >> num;

			if (num < 1 || num > menuSize)
			{
				std::cout << "Invalid number! Try again.\n";
			}
			else
			{
				return num;
			}
		}
	}

	bool Console::InputYesNo(std::string sentence) const
	{
		std::cout << sentence;
		std::cout << "(Please input \"y/yes\" or \"n/no\" (insensitive))\n";
		std::cout << "Input: ";

		std::string str;
		std::cin >> str;
		std::transform(str.begin(), str.end(), str.begin(), ::tolower);

		return (str == "y" || str == "yes") ? true : (str == "n" || str == "no") ? false : InputYesNo(sentence);
	}

	void Console::SignIn()
	{
		std::cout << "Input Player ID to load data.\n";
		std::cout << "If you do not want to load, please input \"STOP\"\n";

		while (true)
		{
			std::cout << "Player ID: ";
			std::string playerID;
			std::cin >> playerID;

			if (playerID == "STOP")
			{
				break;
			}

			if (!filesystem::exists("Datas/" + playerID + ".json"))
			{
				std::cout << playerID << ".json doesn't exist. Try again.\n";
				continue;
			}

			PlayerLoader loader;
			m_player = loader.Load(playerID);

			if (m_player == nullptr)
			{
				std::cout << "An error occurred while loading player data.\n";
				continue;
			}

			std::cout << "You are signed in. Hello, " << playerID << "!\n";

			Main();

			break;
		}
	}

	void Console::SignUp()
	{
		std::cout << "Input Player ID to create data.\n";

		while (true)
		{
			std::cout << "Player ID: ";
			std::string playerID;
			std::cin >> playerID;

			if (filesystem::exists("Datas/" + playerID + ".json"))
			{
				std::cout << playerID << ".json already exists. Try again.\n";
				continue;
			}

			std::cout << "Name: ";
			std::string name;
			std::cin >> name;

			m_player = new Player(std::move(playerID), std::move(name));

			PlayerLoader loader;
			loader.Save(m_player);

			std::cout << "Your account has been created. Please sign in.\n";
			break;
		}
	}

	void Console::SearchCard()
	{
		std::cout << "========================================\n";
		std::cout << "              Search Card!              \n";
		std::cout << "========================================\n";

		std::cout << "Usage: -c class -n name -mc cost -a attack -h health\n";
	}

	int Console::ManageDeck()
	{
		std::cout << "========================================\n";
		std::cout << "              Manage Deck!              \n";
		std::cout << "========================================\n";

		ShowMenu(m_manageDeckStr);
		const size_t selectedNum = InputMenuNum("Select: ", MANAGE_DECK_MENU_SIZE);
		bool isFinish = false;

{'fraction_non_alphanumeric': 0.263591893780573, 'fraction_numerical': 0.00363382250174703, 'mean_word_length': 3.6019292604501607, 'pattern_counts': {'":': 0, '<': 151, '<?xml version=': 0, '>': 67, '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': '787850', 'n_tokens_mistral': 2731, 'n_tokens_neox': 2319, 'n_words': 568}