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.py 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import os
  2. import sys
  3. sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
  4. sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/proto")
  5. from PyAPI.Interface import IAI
  6. from PyAPI.AI import AI
  7. from PyAPI.logic import Logic
  8. from typing import List, Callable
  9. import argparse
  10. import platform
  11. import PyAPI.structures as THUAI6
  12. def PrintWelcomeString() -> None:
  13. # Generated by http://www.network-science.de/ascii/ with font "standard"
  14. welcomeString = """
  15. _____ _ _ _ _ _ ___ __
  16. |_ _| | | | | | | / \ |_ _/ /_
  17. | | | |_| | | | |/ _ \ | | '_ \
  18. | | | _ | |_| / ___ \ | | (_) |
  19. |_| |_| |_|\___/_/ \_\___\___/
  20. ____ _ _ ____ _ _ _
  21. / ___|_ __ __ _ __| |_ _ __ _| |_ ___ / ___(_)_ __| |___| |
  22. | | _| '__/ _` |/ _` | | | |/ _` | __/ _ \ | | _| | '__| / __| |
  23. | |_| | | | (_| | (_| | |_| | (_| | || __/_ | |_| | | | | \__ \_|
  24. \____|_| \__,_|\__,_|\__,_|\__,_|\__\___( ) \____|_|_| |_|___(_)
  25. """
  26. print(welcomeString)
  27. def THUAI6Main(argv: List[str], AIBuilder: Callable) -> None:
  28. pID: int = 0
  29. sIP: str = "127.0.0.1"
  30. sPort: str = "8888"
  31. file: bool = True
  32. screen: bool = True
  33. warnOnly: bool = False
  34. parser = argparse.ArgumentParser(
  35. description="THUAI6 Python Interface Commandline Parameter Introduction"
  36. )
  37. parser.add_argument(
  38. "-I",
  39. type=str,
  40. required=True,
  41. help="Server`s IP 127.0.0.1 in default",
  42. dest="sIP",
  43. default="127.0.0.1",
  44. )
  45. parser.add_argument(
  46. "-P",
  47. type=str,
  48. required=True,
  49. help="Server`s Port 8888 in default",
  50. dest="sPort",
  51. default="8888",
  52. )
  53. parser.add_argument(
  54. "-p",
  55. type=int,
  56. required=True,
  57. help="Player`s ID",
  58. dest="pID",
  59. choices=[0, 1, 2, 3, 4],
  60. )
  61. parser.add_argument(
  62. "-d",
  63. action="store_true",
  64. help="Set this flag to save the debug log to ./logs folder",
  65. dest="file",
  66. )
  67. parser.add_argument(
  68. "-o",
  69. action="store_true",
  70. help="Set this flag to print the debug log to the screen",
  71. dest="screen",
  72. )
  73. parser.add_argument(
  74. "-w",
  75. action="store_true",
  76. help="Set this flag to only print warning on the screen",
  77. dest="warnOnly",
  78. )
  79. args = parser.parse_args()
  80. pID = args.pID
  81. sIP = args.sIP
  82. sPort = args.sPort
  83. file = args.file
  84. screen = args.screen
  85. warnOnly = args.warnOnly
  86. playerType = THUAI6.PlayerType.NullPlayerType
  87. if pID == 4:
  88. playerType = THUAI6.PlayerType.TrickerPlayer
  89. else:
  90. playerType = THUAI6.PlayerType.StudentPlayer
  91. if platform.system().lower() == "windows":
  92. PrintWelcomeString()
  93. logic = Logic(pID, playerType)
  94. logic.Main(AIBuilder, sIP, sPort, file, screen, warnOnly)
  95. def CreateAI(pID: int) -> IAI:
  96. return AI(pID)
  97. if __name__ == "__main__":
  98. THUAI6Main(sys.argv, CreateAI)