main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "../global.h"
  2. #include <boost/thread.hpp>
  3. #include <boost/bind.hpp>
  4. #include <boost/program_options.hpp>
  5. namespace po = boost::program_options;
  6. void prog_help()
  7. {
  8. throw std::string("The method or operation is not implemented.");
  9. }
  10. int main(int argc, char **argv)
  11. {
  12. std::cout << "VCMI Odpalarka\nMy path: " << argv[0] << std::endl;
  13. po::options_description opts("Allowed options");
  14. opts.add_options()
  15. ("help,h", "display help and exit")
  16. ("aiLeft,l", po::value<std::string>(), "Left AI path")
  17. ("aiRight,r", po::value<std::string>(), "Right AI path")
  18. ("battle,b", po::value<std::string>(), "Duel file path")
  19. ("visualization,v", "Runs a client to display a visualization of battle");
  20. std::string leftAI = "StupidAI",
  21. rightAI = "StupidAI",
  22. battle = "b1.json";
  23. po::variables_map vm;
  24. if(argc > 1)
  25. {
  26. try
  27. {
  28. po::store(po::parse_command_line(argc, argv, opts), vm);
  29. po::notify(vm);
  30. leftAI = vm["aiLeft"].as<std::string>();
  31. rightAI = vm["aiRight"].as<std::string>();
  32. battle = vm["battle"].as<std::string>();
  33. }
  34. catch(std::exception &e)
  35. {
  36. std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
  37. exit(1);
  38. }
  39. }
  40. else
  41. {
  42. std::cout << "Default AIs will be used." << std::endl;
  43. }
  44. if(vm.count("help"))
  45. {
  46. prog_help();
  47. return 0;
  48. }
  49. std::string runnername =
  50. #ifdef _WIN32
  51. "VCMI_BattleAiHost.exe"
  52. #else
  53. "./vcmirunner"
  54. #endif
  55. ;
  56. std::string servername =
  57. #ifdef _WIN32
  58. "VCMI_server.exe"
  59. #else
  60. "./vcmiserver"
  61. #endif
  62. ;
  63. bool withVisualization = vm.count("visualization");
  64. std::string serverCommand = servername + " " + battle + " " + leftAI + " " + rightAI + (withVisualization ? " v" : "");
  65. std::string runnerCommand = runnername;
  66. boost::thread t(boost::bind(std::system, serverCommand.c_str()));
  67. boost::thread tt(boost::bind(std::system, runnerCommand.c_str()));
  68. boost::thread ttt(boost::bind(std::system, runnerCommand.c_str()));
  69. boost::thread tttt(boost::bind(std::system, runnername.c_str()));
  70. if(withVisualization)
  71. {
  72. //boost::this_thread::sleep(boost::posix_time::millisec(500)); //FIXME
  73. boost::thread tttt(boost::bind(std::system, "VCMI_Client.exe -battle"));
  74. }
  75. //boost::this_thread::sleep(boost::posix_time::seconds(5));
  76. t.join();
  77. return EXIT_SUCCESS;
  78. }