You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "AI.h"
  2. #include "logic.h"
  3. #include "structures.h"
  4. #include <tclap/CmdLine.h>
  5. #include <array>
  6. #include <string_view>
  7. #undef GetMessage
  8. #undef SendMessage
  9. #undef PeekMessage
  10. #ifdef _MSC_VER
  11. #pragma warning(disable : 4996)
  12. #endif
  13. using namespace std::literals::string_view_literals;
  14. // Generated by http://www.network-science.de/ascii/ with font "standard"
  15. static constexpr std::string_view welcomeString = R"welcome(
  16. _____ _ _ _ _ _ ___ __
  17. |_ _| | | | | | | / \ |_ _/ /_
  18. | | | |_| | | | |/ _ \ | | '_ \
  19. | | | _ | |_| / ___ \ | | (_) |
  20. |_| |_| |_|\___/_/ \_\___\___/
  21. ____ _ _ ____ _ _ _
  22. / ___|_ __ __ _ __| |_ _ __ _| |_ ___ / ___(_)_ __| |___| |
  23. | | _| '__/ _` |/ _` | | | |/ _` | __/ _ \ | | _| | '__| / __| |
  24. | |_| | | | (_| | (_| | |_| | (_| | || __/_ | |_| | | | | \__ \_|
  25. \____|_| \__,_|\__,_|\__,_|\__,_|\__\___( ) \____|_|_| |_|___(_)
  26. )welcome"sv;
  27. int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder)
  28. {
  29. int pID = 0;
  30. std::string sIP = "172.22.32.1";
  31. std::string sPort = "8888";
  32. bool file = false;
  33. bool print = false;
  34. bool warnOnly = false;
  35. extern const THUAI6::TrickerType trickerType;
  36. extern const std::array<THUAI6::StudentType, 4> studentType;
  37. // {
  38. // file = true;
  39. // print = true;
  40. // Logic logic(playerType, pID, trickerType, studentType);
  41. // logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly);
  42. // return 0;
  43. // }
  44. // 使用cmdline的正式版本
  45. try
  46. {
  47. TCLAP::CmdLine cmd("THUAI6 C++ interface commandline parameter introduction");
  48. TCLAP::ValueArg<std::string> serverIP("I", "serverIP", "Server`s IP 127.0.0.1 in default", false, "127.0.0.1", "string");
  49. cmd.add(serverIP);
  50. TCLAP::ValueArg<std::string> serverPort("P", "serverPort", "Port the server listens to 7777 in default", false, "7777", "USORT");
  51. cmd.add(serverPort);
  52. std::vector<int> validPlayerIDs{0, 1, 2, 3, 4};
  53. TCLAP::ValuesConstraint<int> playerIdConstraint(validPlayerIDs);
  54. TCLAP::ValueArg<int> playerID("p", "playerID", "Player ID 0,1,2,3 valid only", true, -1, &playerIdConstraint);
  55. cmd.add(playerID);
  56. std::string DebugDesc = "Set this flag to save the debug log to ./logs folder.\n";
  57. TCLAP::SwitchArg debug("d", "debug", DebugDesc);
  58. cmd.add(debug);
  59. std::string OutputDesc = "Set this flag to print the debug log to the screen.\n";
  60. TCLAP::SwitchArg output("o", "output", OutputDesc);
  61. cmd.add(output);
  62. TCLAP::SwitchArg warning("w", "warning", "Set this flag to only print warning on the screen.\n"
  63. "This flag will be ignored if the output flag is not set\n");
  64. cmd.add(warning);
  65. cmd.parse(argc, argv);
  66. pID = playerID.getValue();
  67. sIP = serverIP.getValue();
  68. sPort = serverPort.getValue();
  69. file = debug.getValue();
  70. print = output.getValue();
  71. if (print)
  72. warnOnly = warning.getValue();
  73. }
  74. catch (TCLAP::ArgException& e)
  75. {
  76. std::cerr << "Parsing error: " << e.error() << " for arg " << e.argId() << std::endl;
  77. return 1;
  78. }
  79. try
  80. {
  81. THUAI6::PlayerType playerType;
  82. THUAI6::StudentType stuType = THUAI6::StudentType::NullStudentType;
  83. if (pID == 4)
  84. playerType = THUAI6::PlayerType::TrickerPlayer;
  85. else
  86. {
  87. playerType = THUAI6::PlayerType::StudentPlayer;
  88. stuType = studentType[pID];
  89. }
  90. #ifdef _MSC_VER
  91. std::cout << welcomeString << std::endl;
  92. #endif
  93. Logic logic(playerType, pID, trickerType, stuType);
  94. logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly);
  95. }
  96. catch (const std::exception& e)
  97. {
  98. std::cerr << "C++ Exception: " << e.what() << '\n';
  99. }
  100. catch (...)
  101. {
  102. std::cerr << "Unknown Exception\n";
  103. }
  104. return 0;
  105. }
  106. std::unique_ptr<IAI> CreateAI(int64_t pID)
  107. {
  108. return std::make_unique<AI>(pID);
  109. }
  110. int main(int argc, char* argv[])
  111. {
  112. return THUAI6Main(argc, argv, CreateAI);
  113. }