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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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, cast, Tuple
  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, pi)
  20. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  21. return self.Move(timeInMilliseconds, 0)
  22. def Attack(self, angle: float) -> Future[bool]:
  23. return self.__pool.submit(self.__logic.Attack, angle)
  24. # 道具和技能相关
  25. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  26. return self.__pool.submit(self.__logic.PickProp, propType)
  27. def UseProp(self, propType: THUAI6.PropType) -> Future[bool]:
  28. return self.__pool.submit(self.__logic.UseProp, propType)
  29. def ThrowProp(self, propType: THUAI6.PropType) -> Future[bool]:
  30. return self.__pool.submit(self.__logic.ThrowProp, propType)
  31. def UseSkill(self, skillID: int) -> Future[bool]:
  32. return self.__pool.submit(self.__logic.UseSkill, skillID)
  33. # 与地图交互相关
  34. def OpenDoor(self) -> Future[bool]:
  35. return self.__pool.submit(self.__logic.OpenDoor)
  36. def CloseDoor(self) -> Future[bool]:
  37. return self.__pool.submit(self.__logic.CloseDoor)
  38. def SkipWindow(self) -> Future[bool]:
  39. return self.__pool.submit(self.__logic.SkipWindow)
  40. def StartOpenGate(self) -> Future[bool]:
  41. return self.__pool.submit(self.__logic.StartOpenGate)
  42. def StartOpenChest(self) -> Future[bool]:
  43. return self.__pool.submit(self.__logic.StartOpenChest)
  44. def EndAllAction(self) -> Future[bool]:
  45. return self.__pool.submit(self.__logic.EndAllAction)
  46. # 消息相关,接收消息时无消息则返回(-1, '')
  47. def SendMessage(self, toID: int, message: str) -> Future[bool]:
  48. return self.__pool.submit(self.__logic.SendMessage, toID, message)
  49. def HaveMessage(self) -> bool:
  50. return self.__logic.HaveMessage()
  51. def GetMessage(self) -> Tuple[int, str]:
  52. return self.__logic.GetMessage()
  53. # 等待下一帧
  54. def Wait(self) -> Future[bool]:
  55. if self.__logic.GetCounter() == -1:
  56. return self.__pool.submit(lambda: False)
  57. else:
  58. return self.__pool.submit(self.__logic.WaitThread)
  59. # 获取各类游戏中的消息
  60. def GetFrameCount(self) -> int:
  61. return self.__logic.GetCounter()
  62. def GetPlayerGUIDs(self) -> List[int]:
  63. return self.__logic.GetPlayerGUIDs()
  64. def GetTrickers(self) -> List[THUAI6.Tricker]:
  65. return self.__logic.GetTrickers()
  66. def GetStudents(self) -> List[THUAI6.Student]:
  67. return self.__logic.GetStudents()
  68. def GetProps(self) -> List[THUAI6.Prop]:
  69. return self.__logic.GetProps()
  70. def GetBullets(self) -> List[THUAI6.Bullet]:
  71. return self.__logic.GetBullets()
  72. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  73. return self.__logic.GetFullMap()
  74. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  75. return self.__logic.GetPlaceType(cellX, cellY)
  76. def IsDoorOpen(self, cellX: int, cellY: int) -> bool:
  77. return self.__logic.IsDoorOpen(cellX, cellY)
  78. def GetChestProgress(self, cellX: int, cellY: int) -> int:
  79. return self.__logic.GetChestProgress(cellX, cellY)
  80. def GetGateProgress(self, cellX: int, cellY: int) -> int:
  81. return self.__logic.GetGateProgress(cellX, cellY)
  82. def GetClassroomProgress(self, cellX: int, cellY: int) -> int:
  83. return self.__logic.GetClassroomProgress(cellX, cellY)
  84. def GetDoorProgress(self, cellX: int, cellY: int) -> int:
  85. return self.__logic.GetDoorProgress(cellX, cellY)
  86. def GetHiddenGateState(self, cellX: int, cellY: int) -> THUAI6.HiddenGateState:
  87. return self.__logic.GetHiddenGateState(cellX, cellY)
  88. def GetGameInfo(self) -> THUAI6.GameInfo:
  89. return self.__logic.GetGameInfo()
  90. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  91. def Print(self, cont: str) -> None:
  92. pass
  93. def PrintStudent(self) -> None:
  94. pass
  95. def PrintTricker(self) -> None:
  96. pass
  97. def PrintProp(self) -> None:
  98. pass
  99. def PrintSelfInfo(self) -> None:
  100. pass
  101. # 人类阵营的特殊函数
  102. def Graduate(self) -> Future[bool]:
  103. return self.__pool.submit(self.__logic.Graduate)
  104. def StartLearning(self) -> Future[bool]:
  105. return self.__pool.submit(self.__logic.StartLearning)
  106. def StartEncourageMate(self, mateID: int) -> Future[bool]:
  107. return self.__pool.submit(self.__logic.StartEncourageMate, mateID)
  108. def StartRouseMate(self, mateID: int) -> Future[bool]:
  109. return self.__pool.submit(self.__logic.StartRouseMate, mateID)
  110. def GetSelfInfo(self) -> THUAI6.Student:
  111. return cast(THUAI6.Student, self.__logic.GetSelfInfo())
  112. # Timer用
  113. def StartTimer(self) -> None:
  114. pass
  115. def EndTimer(self) -> None:
  116. pass
  117. def Play(self, ai: IAI) -> None:
  118. ai.StudentPlay(self)
  119. class TrickerAPI(ITrickerAPI, IGameTimer):
  120. def __init__(self, logic: ILogic) -> None:
  121. self.__logic = logic
  122. self.__pool = ThreadPoolExecutor(20)
  123. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  124. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  125. return self.__pool.submit(self.__logic.Move, timeInMilliseconds, angle)
  126. # 向特定方向移动
  127. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  128. return self.Move(timeInMilliseconds, pi * 0.5)
  129. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  130. return self.Move(timeInMilliseconds, pi * 1.5)
  131. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  132. return self.Move(timeInMilliseconds, pi)
  133. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  134. return self.Move(timeInMilliseconds, 0)
  135. def Attack(self, angle: float) -> Future[bool]:
  136. return self.__pool.submit(self.__logic.Attack, angle)
  137. # 道具和技能相关
  138. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  139. return self.__pool.submit(self.__logic.PickProp, propType)
  140. def UseProp(self, propType: THUAI6.PropType) -> Future[bool]:
  141. return self.__pool.submit(self.__logic.UseProp, propType)
  142. def ThrowProp(self, propType: THUAI6.PropType) -> Future[bool]:
  143. return self.__pool.submit(self.__logic.ThrowProp, propType)
  144. def UseSkill(self, skillID: int) -> Future[bool]:
  145. return self.__pool.submit(self.__logic.UseSkill, skillID)
  146. # 与地图交互相关
  147. def OpenDoor(self) -> Future[bool]:
  148. return self.__pool.submit(self.__logic.OpenDoor)
  149. def CloseDoor(self) -> Future[bool]:
  150. return self.__pool.submit(self.__logic.CloseDoor)
  151. def SkipWindow(self) -> Future[bool]:
  152. return self.__pool.submit(self.__logic.SkipWindow)
  153. def StartOpenGate(self) -> Future[bool]:
  154. return self.__pool.submit(self.__logic.StartOpenGate)
  155. def StartOpenChest(self) -> Future[bool]:
  156. return self.__pool.submit(self.__logic.StartOpenChest)
  157. def EndAllAction(self) -> Future[bool]:
  158. return self.__pool.submit(self.__logic.EndAllAction)
  159. # 消息相关,接收消息时无消息则返回(-1, '')
  160. def SendMessage(self, toID: int, message: str) -> Future[bool]:
  161. return self.__pool.submit(self.__logic.SendMessage, toID, message)
  162. def HaveMessage(self) -> bool:
  163. return self.__logic.HaveMessage()
  164. def GetMessage(self) -> Tuple[int, str]:
  165. return self.__logic.GetMessage()
  166. # 等待下一帧
  167. def Wait(self) -> Future[bool]:
  168. if self.__logic.GetCounter() == -1:
  169. return self.__pool.submit(lambda: False)
  170. else:
  171. return self.__pool.submit(self.__logic.WaitThread)
  172. # 获取各类游戏中的消息
  173. def GetFrameCount(self) -> int:
  174. return self.__logic.GetCounter()
  175. def GetPlayerGUIDs(self) -> List[int]:
  176. return self.__logic.GetPlayerGUIDs()
  177. def GetTrickers(self) -> List[THUAI6.Tricker]:
  178. return self.__logic.GetTrickers()
  179. def GetStudents(self) -> List[THUAI6.Student]:
  180. return self.__logic.GetStudents()
  181. def GetProps(self) -> List[THUAI6.Prop]:
  182. return self.__logic.GetProps()
  183. def GetBullets(self) -> List[THUAI6.Bullet]:
  184. return self.__logic.GetBullets()
  185. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  186. return self.__logic.GetFullMap()
  187. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  188. return self.__logic.GetPlaceType(cellX, cellY)
  189. def IsDoorOpen(self, cellX: int, cellY: int) -> bool:
  190. return self.__logic.IsDoorOpen(cellX, cellY)
  191. def GetChestProgress(self, cellX: int, cellY: int) -> int:
  192. return self.__logic.GetChestProgress(cellX, cellY)
  193. def GetGateProgress(self, cellX: int, cellY: int) -> int:
  194. return self.__logic.GetGateProgress(cellX, cellY)
  195. def GetClassroomProgress(self, cellX: int, cellY: int) -> int:
  196. return self.__logic.GetClassroomProgress(cellX, cellY)
  197. def GetDoorProgress(self, cellX: int, cellY: int) -> int:
  198. return self.__logic.GetDoorProgress(cellX, cellY)
  199. def GetHiddenGateState(self, cellX: int, cellY: int) -> THUAI6.HiddenGateState:
  200. return self.__logic.GetHiddenGateState(cellX, cellY)
  201. def GetGameInfo(self) -> THUAI6.GameInfo:
  202. return self.__logic.GetGameInfo()
  203. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  204. def Print(self, cont: str) -> None:
  205. pass
  206. def PrintStudent(self) -> None:
  207. pass
  208. def PrintTricker(self) -> None:
  209. pass
  210. def PrintProp(self) -> None:
  211. pass
  212. def PrintSelfInfo(self) -> None:
  213. pass
  214. # 屠夫阵营的特殊函数
  215. def GetSelfInfo(self) -> THUAI6.Tricker:
  216. return cast(THUAI6.Tricker, self.__logic.GetSelfInfo())
  217. # Timer用
  218. def StartTimer(self) -> None:
  219. pass
  220. def EndTimer(self) -> None:
  221. pass
  222. def Play(self, ai: IAI) -> None:
  223. ai.TrickerPlay(self)