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.

API.py 7.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import PyAPI.structures as THUAI6
  2. from PyAPI.Interface import ILogic, IStudentAPI, ITrickerAPI, IGameTimer, IAI
  3. from math import pi
  4. from concurrent.futures import ThreadPoolExecutor, Future
  5. from typing import List, Union
  6. class StudentAPI(IStudentAPI, IGameTimer):
  7. def __init__(self, logic: ILogic) -> None:
  8. self.__logic = logic
  9. self.__pool = ThreadPoolExecutor(20)
  10. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  11. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  12. return self.__pool.submit(self.__logic.Move, timeInMilliseconds, angle)
  13. # 向特定方向移动
  14. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  15. return self.Move(timeInMilliseconds, pi * 0.5)
  16. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  17. return self.Move(timeInMilliseconds, pi * 1.5)
  18. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  19. return self.Move(timeInMilliseconds, 0)
  20. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  21. return self.Move(timeInMilliseconds, pi)
  22. # 道具和技能相关
  23. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  24. return self.__pool.submit(self.__logic.PickProp, propType)
  25. def UseProp(self) -> Future[bool]:
  26. return self.__pool.submit(self.__logic.UseProp)
  27. def UseSkill(self) -> Future[bool]:
  28. return self.__pool.submit(self.__logic.UseSkill)
  29. # 消息相关,接收消息时无消息则返回(-1, '')
  30. def SendMessage(self, toID: int, message: str) -> Future[bool]:
  31. return self.__pool.submit(self.__logic.SendMessage, toID, message)
  32. def HaveMessage(self) -> Future[bool]:
  33. return self.__pool.submit(self.__logic.HaveMessage)
  34. def GetMessage(self) -> Future[tuple[int, str]]:
  35. return self.__pool.submit(self.__logic.GetMessage)
  36. # 等待下一帧
  37. def Wait(self) -> Future[bool]:
  38. if self.__logic.GetCounter() == -1:
  39. return self.__pool.submit(lambda: False)
  40. else:
  41. return self.__pool.submit(self.__logic.WaitThread)
  42. # 获取各类游戏中的消息
  43. def GetFrameCount(self) -> int:
  44. return self.__logic.GetCounter()
  45. def GetPlayerGUIDs(self) -> List[int]:
  46. return self.__logic.GetPlayerGUIDs()
  47. def GetTrickers(self) -> List[THUAI6.Tricker]:
  48. return self.__logic.GetTrickers()
  49. def GetStudents(self) -> List[THUAI6.Student]:
  50. return self.__logic.GetStudents()
  51. def GetProps(self) -> List[THUAI6.Prop]:
  52. return self.__logic.GetProps()
  53. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  54. return self.__logic.GetSelfInfo()
  55. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  56. return self.__logic.GetFullMap()
  57. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  58. return self.__logic.GetPlaceType(cellX, cellY)
  59. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  60. def PrintStudent(self) -> None:
  61. pass
  62. def PrintTricker(self) -> None:
  63. pass
  64. def PrintProp(self) -> None:
  65. pass
  66. def PrintSelfInfo(self) -> None:
  67. pass
  68. # 人类阵营的特殊函数
  69. def Graduate(self) -> Future[bool]:
  70. return self.__pool.submit(self.__logic.Graduate)
  71. def StartLearning(self) -> Future[bool]:
  72. return self.__pool.submit(self.__logic.StartLearning)
  73. def EndLearning(self) -> Future[bool]:
  74. return self.__pool.submit(self.__logic.EndLearning)
  75. def StartHelpMate(self) -> Future[bool]:
  76. return self.__pool.submit(self.__logic.StartHelpMate)
  77. def EndHelpMate(self) -> Future[bool]:
  78. return self.__pool.submit(self.__logic.EndHelpMate)
  79. # Timer用
  80. def StartTimer(self) -> None:
  81. pass
  82. def EndTimer(self) -> None:
  83. pass
  84. def Play(self, ai: IAI) -> None:
  85. pass
  86. class TrickerAPI(ITrickerAPI, IGameTimer):
  87. def __init__(self, logic: ILogic) -> None:
  88. self.__logic = logic
  89. self.__pool = ThreadPoolExecutor(20)
  90. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  91. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  92. return self.__pool.submit(self.__logic.Move, timeInMilliseconds, angle)
  93. # 向特定方向移动
  94. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  95. return self.Move(timeInMilliseconds, pi * 0.5)
  96. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  97. return self.Move(timeInMilliseconds, pi * 1.5)
  98. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  99. return self.Move(timeInMilliseconds, 0)
  100. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  101. return self.Move(timeInMilliseconds, pi)
  102. # 道具和技能相关
  103. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  104. return self.__pool.submit(self.__logic.PickProp, propType)
  105. def UseProp(self) -> Future[bool]:
  106. return self.__pool.submit(self.__logic.UseProp)
  107. def UseSkill(self) -> Future[bool]:
  108. return self.__pool.submit(self.__logic.UseSkill)
  109. # 消息相关,接收消息时无消息则返回(-1, '')
  110. def SendMessage(self, toID: int, message: str) -> Future[bool]:
  111. return self.__pool.submit(self.__logic.SendMessage, toID, message)
  112. def HaveMessage(self) -> Future[bool]:
  113. return self.__pool.submit(self.__logic.HaveMessage)
  114. def GetMessage(self) -> Future[tuple[int, str]]:
  115. return self.__pool.submit(self.__logic.GetMessage)
  116. # 等待下一帧
  117. def Wait(self) -> Future[bool]:
  118. if self.__logic.GetCounter() == -1:
  119. return self.__pool.submit(lambda: False)
  120. else:
  121. return self.__pool.submit(self.__logic.WaitThread)
  122. # 获取各类游戏中的消息
  123. def GetFrameCount(self) -> int:
  124. return self.__logic.GetCounter()
  125. def GetPlayerGUIDs(self) -> List[int]:
  126. return self.__logic.GetPlayerGUIDs()
  127. def GetTrickers(self) -> List[THUAI6.Tricker]:
  128. return self.__logic.GetTrickers()
  129. def GetStudents(self) -> List[THUAI6.Student]:
  130. return self.__logic.GetStudents()
  131. def GetProps(self) -> List[THUAI6.Prop]:
  132. return self.__logic.GetProps()
  133. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  134. return self.__logic.GetSelfInfo()
  135. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  136. return self.__logic.GetFullMap()
  137. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  138. return self.__logic.GetPlaceType(cellX, cellY)
  139. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  140. def PrintStudent(self) -> None:
  141. pass
  142. def PrintTricker(self) -> None:
  143. pass
  144. def PrintProp(self) -> None:
  145. pass
  146. def PrintSelfInfo(self) -> None:
  147. pass
  148. # 屠夫阵营的特殊函数
  149. def Trick(self, angle: float) -> Future[bool]:
  150. return self.__pool.submit(self.__logic.Trick, angle)
  151. def StartExam(self) -> Future[bool]:
  152. return self.__pool.submit(self.__logic.StartExam)
  153. def EndExam(self) -> Future[bool]:
  154. return self.__pool.submit(self.__logic.EndExam)
  155. def MakeFail(self) -> Future[bool]:
  156. return self.__pool.submit(self.__logic.MakeFail)
  157. # Timer用
  158. def StartTimer(self) -> None:
  159. pass
  160. def EndTimer(self) -> None:
  161. pass
  162. def Play(self, ai: IAI) -> None:
  163. pass