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

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