|
@@ -1,9 +1,14 @@
|
|
|
//#include "../global.h"
|
|
|
-#include <boost/thread.hpp>
|
|
|
-#include <boost/bind.hpp>
|
|
|
-#include <boost/program_options.hpp>
|
|
|
+#include "StdInc.h"
|
|
|
+#include "../lib/VCMI_Lib.h"
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
+std::string leftAI, rightAI, battle, results, logsDir;
|
|
|
+bool withVisualization = false;
|
|
|
+std::string servername;
|
|
|
+std::string runnername;
|
|
|
+extern DLL_EXPORT LibClasses * VLC;
|
|
|
+
|
|
|
std::string addQuotesIfNeeded(const std::string &s)
|
|
|
{
|
|
|
if(s.find_first_of(' ') != std::string::npos)
|
|
@@ -33,6 +38,84 @@ void runCommand(const std::string &command, const std::string &name, const std::
|
|
|
boost::thread tt(boost::bind(std::system, cmd.c_str()));
|
|
|
}
|
|
|
|
|
|
+double playBattle(const DuelParameters &dp)
|
|
|
+{
|
|
|
+ {
|
|
|
+ CSaveFile out("pliczek.ssnb");
|
|
|
+ out << dp;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ std::string serverCommand = servername + " " + addQuotesIfNeeded(battle) + " " + addQuotesIfNeeded(leftAI) + " " + addQuotesIfNeeded(rightAI) + " " + addQuotesIfNeeded(results) + " " + addQuotesIfNeeded(logsDir) + " " + (withVisualization ? " v" : "");
|
|
|
+ std::string runnerCommand = runnername + " " + addQuotesIfNeeded(logsDir);
|
|
|
+ std::cout <<"Server command: " << serverCommand << std::endl << "Runner command: " << runnerCommand << std::endl;
|
|
|
+
|
|
|
+ int code = 0;
|
|
|
+ boost::thread t([&]
|
|
|
+ {
|
|
|
+ code = std::system(serverCommand.c_str());
|
|
|
+ });
|
|
|
+
|
|
|
+ runCommand(runnerCommand, "first_runner", logsDir);
|
|
|
+ runCommand(runnerCommand, "second_runner", logsDir);
|
|
|
+ runCommand(runnerCommand, "third_runner", logsDir);
|
|
|
+ if(withVisualization)
|
|
|
+ {
|
|
|
+ //boost::this_thread::sleep(boost::posix_time::millisec(500)); //FIXME
|
|
|
+ boost::thread tttt(boost::bind(std::system, "VCMI_Client.exe -battle"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //boost::this_thread::sleep(boost::posix_time::seconds(5));
|
|
|
+ t.join();
|
|
|
+ return code / 1000000.0;
|
|
|
+}
|
|
|
+
|
|
|
+void SSNRun()
|
|
|
+{
|
|
|
+ CArtifact *nowy = new CArtifact();
|
|
|
+ nowy->description = "Cudowny miecz Towa gwarantuje zwyciestwo";
|
|
|
+ nowy->name = "Cudowny miecz";
|
|
|
+ nowy->constituentOf = nowy->constituents = NULL;
|
|
|
+ nowy->possibleSlots.push_back(Arts::LEFT_HAND);
|
|
|
+
|
|
|
+ CArtifactInstance *artinst = new CArtifactInstance(nowy);
|
|
|
+ auto &arts = VLC->arth->artifacts;
|
|
|
+ CArtifactInstance *inny = new CArtifactInstance(VLC->arth->artifacts[15]);
|
|
|
+
|
|
|
+ artinst->addNewBonus(new Bonus(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::ARTIFACT_INSTANCE, +25, nowy->id, PrimarySkill::ATTACK));
|
|
|
+ artinst->addNewBonus(new Bonus(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::ARTIFACT_INSTANCE, +25, nowy->id, PrimarySkill::DEFENSE));
|
|
|
+
|
|
|
+ DuelParameters dp;
|
|
|
+ dp.bfieldType = 1;
|
|
|
+ dp.terType = 1;
|
|
|
+
|
|
|
+ for(int i = 0; i < 2 ; i++)
|
|
|
+ {
|
|
|
+ auto &side = dp.sides[i];
|
|
|
+ side.heroId = i;
|
|
|
+ side.heroPrimSkills.resize(4,0);
|
|
|
+ side.stacks[0] = DuelParameters::SideSettings::StackSettings(10+i, 40+i);
|
|
|
+ }
|
|
|
+
|
|
|
+ auto bonuses = artinst->getBonuses([](const Bonus *){ return true; });
|
|
|
+ BOOST_FOREACH(Bonus *b, *bonuses)
|
|
|
+ {
|
|
|
+ std::cout << format("%s (%d) value:%d, description: %s\n") % bonusTypeToString(b->type) % b->subtype % b->val % b->Description();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //lewa strona z art 0.9
|
|
|
+ //bez artefaktow -0.41
|
|
|
+ //prawa strona z art. -0.926
|
|
|
+
|
|
|
+ dp.sides[0].artifacts[Arts::LEFT_HAND] = artinst;
|
|
|
+
|
|
|
+ auto battleOutcome = playBattle(dp);
|
|
|
+ int g = 4;
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char **argv)
|
|
|
{
|
|
|
std::cout << "VCMI Odpalarka\nMy path: " << argv[0] << std::endl;
|
|
@@ -42,13 +125,11 @@ int main(int argc, char **argv)
|
|
|
("help,h", "Display help and exit")
|
|
|
("aiLeft,l", po::value<std::string>()->default_value("StupidAI"), "Left AI path")
|
|
|
("aiRight,r", po::value<std::string>()->default_value("StupidAI"), "Right AI path")
|
|
|
- ("battle,b", po::value<std::string>()->default_value("b1.json"), "Duel file path")
|
|
|
+ ("battle,b", po::value<std::string>()->default_value("pliczek.ssnb"), "Duel file path")
|
|
|
("resultsOut,o", po::value<std::string>()->default_value("./results.txt"), "Output file when results will be appended")
|
|
|
("logsDir,d", po::value<std::string>()->default_value("."), "Directory where log files will be created")
|
|
|
("visualization,v", "Runs a client to display a visualization of battle");
|
|
|
|
|
|
- std::string leftAI, rightAI, battle, results, logsDir;
|
|
|
- bool withVisualization = false;
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -86,14 +167,14 @@ int main(int argc, char **argv)
|
|
|
|
|
|
|
|
|
|
|
|
- std::string runnername =
|
|
|
+ runnername =
|
|
|
#ifdef _WIN32
|
|
|
"VCMI_BattleAiHost.exe"
|
|
|
#else
|
|
|
"./vcmirunner"
|
|
|
#endif
|
|
|
;
|
|
|
- std::string servername =
|
|
|
+ servername =
|
|
|
#ifdef _WIN32
|
|
|
"VCMI_server.exe"
|
|
|
#else
|
|
@@ -101,22 +182,11 @@ int main(int argc, char **argv)
|
|
|
#endif
|
|
|
;
|
|
|
|
|
|
- std::string serverCommand = servername + " " + addQuotesIfNeeded(battle) + " " + addQuotesIfNeeded(leftAI) + " " + addQuotesIfNeeded(rightAI) + " " + addQuotesIfNeeded(results) + " " + addQuotesIfNeeded(logsDir) + " " + (withVisualization ? " v" : "");
|
|
|
- std::string runnerCommand = runnername + " " + addQuotesIfNeeded(logsDir);
|
|
|
- std::cout <<"Server command: " << serverCommand << std::endl << "Runner command: " << runnerCommand << std::endl;
|
|
|
+
|
|
|
+ VLC = new LibClasses();
|
|
|
+ VLC->init();
|
|
|
|
|
|
- boost::thread t(boost::bind(std::system, serverCommand.c_str()));
|
|
|
- runCommand(runnerCommand, "first_runner", logsDir);
|
|
|
- runCommand(runnerCommand, "second_runner", logsDir);
|
|
|
- runCommand(runnerCommand, "third_runner", logsDir);
|
|
|
- if(withVisualization)
|
|
|
- {
|
|
|
- //boost::this_thread::sleep(boost::posix_time::millisec(500)); //FIXME
|
|
|
- boost::thread tttt(boost::bind(std::system, "VCMI_Client.exe -battle"));
|
|
|
- }
|
|
|
+ SSNRun();
|
|
|
|
|
|
- //boost::this_thread::sleep(boost::posix_time::seconds(5));
|
|
|
-
|
|
|
- t.join();
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|