PkmnLibAI/test_runner/main.cpp

70 lines
2.5 KiB
C++

#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptResolver.hpp>
#include <filesystem>
#include <iostream>
#include "../extern/args.hpp"
#include "AIResolver.hpp"
#include "BuildData/BuildItems.hpp"
#include "BuildData/BuildLibrary.hpp"
#include "BuildData/BuildMoves.hpp"
#include "BuildData/BuildNatures.hpp"
#include "BuildData/BuildSpecies.hpp"
#include "BuildData/BuildTypes.hpp"
#include "BuildData/GrowthRatesBuilder.hpp"
#include "Runner.hpp"
int main(int argc, char** argv) {
args::ArgumentParser parser("PkmnLib AI Runner.", "");
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
std::string workingDirectory;
args::HelpFlag helpFlag(parser, "help", "Display this help menu", {'h', "help"});
args::ValueFlag<std::string> workingDirFlag(parser, "Working Directory", "Which work directory to use.",
{"workdir"});
args::ValueFlag<size_t> runsFlag(parser, "Runs", "How many battle to runs.", {"runs", 'r'}, 1000);
args::ValueFlag<std::string> ai1Flag(parser, "AI 1", "What AI to use for side 1.", {"ai1", '1'}, "depthsearch");
args::ValueFlag<std::string> ai2Flag(parser, "AI 2", "What AI to use for side 2.", {"ai2", '2'}, "naive");
try {
parser.ParseCLI(argc, argv);
} catch (args::Help) {
std::cout << parser;
return 0;
} catch (args::ParseError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
} catch (args::ValidationError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
}
if (workingDirFlag) {
workingDirectory = args::get(workingDirFlag);
}
if (!workingDirectory.empty()) {
chdir(std::filesystem::path(workingDirectory).c_str());
}
auto battleLib = BuildLibrary::Build("");
if (battleLib == nullptr) {
return 1;
}
auto ai1 = AIResolver::Resolve(ArbUt::StringView(ai1Flag.Get().c_str(), ai1Flag.Get().size()));
auto ai2 = AIResolver::Resolve(ArbUt::StringView(ai2Flag.Get().c_str(), ai1Flag.Get().size()));
try {
Runner::Run(battleLib, ai1, ai2, runsFlag.Get());
} catch (ArbUt::Exception& e) {
std::cout << std::endl;
std::cout << "Exception with message: " << std::endl
<< e.what() << std::endl
<< e.GetStacktrace(10) << std::endl;
return 1;
}
delete battleLib;
delete ai1;
delete ai2;
return 0;
}