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 3.3 kB

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