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.

Interface.py 6.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. from typing import List, Union
  2. from concurrent.futures import Future
  3. from abc import abstractmethod, ABCMeta
  4. import PyAPI.structures as THUAI6
  5. class ILogic(metaclass=ABCMeta):
  6. # IAPI统一可用的接口
  7. @abstractmethod
  8. def GetTrickers(self) -> List[THUAI6.Tricker]:
  9. pass
  10. @abstractmethod
  11. def GetStudents(self) -> List[THUAI6.Student]:
  12. pass
  13. @abstractmethod
  14. def GetProps(self) -> List[THUAI6.Prop]:
  15. pass
  16. @abstractmethod
  17. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  18. pass
  19. @abstractmethod
  20. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  21. pass
  22. @abstractmethod
  23. def GetPlaceType(self, x: int, y: int) -> THUAI6.PlaceType:
  24. pass
  25. @abstractmethod
  26. def Move(self, time: int, angle: float) -> bool:
  27. pass
  28. @abstractmethod
  29. def PickProp(self, propType: THUAI6.PropType) -> bool:
  30. pass
  31. @abstractmethod
  32. def UseProp(self) -> bool:
  33. pass
  34. @abstractmethod
  35. def UseSkill(self) -> bool:
  36. pass
  37. @abstractmethod
  38. def SendMessage(self, toID: int, message: str) -> bool:
  39. pass
  40. @abstractmethod
  41. def HaveMessage(self) -> bool:
  42. pass
  43. @abstractmethod
  44. def GetMessage(self) -> tuple[int, str]:
  45. pass
  46. @abstractmethod
  47. def WaitThread(self) -> bool:
  48. pass
  49. @abstractmethod
  50. def GetCounter(self) -> int:
  51. pass
  52. @abstractmethod
  53. def GetPlayerGUIDs(self) -> List[int]:
  54. pass
  55. # IStudentAPI使用的接口
  56. @abstractmethod
  57. def Graduate(self) -> bool:
  58. pass
  59. @abstractmethod
  60. def StartLearning(self) -> bool:
  61. pass
  62. @abstractmethod
  63. def EndLearning(self) -> bool:
  64. pass
  65. @abstractmethod
  66. def StartHelpMate(self) -> bool:
  67. pass
  68. @abstractmethod
  69. def EndHelpMate(self) -> bool:
  70. pass
  71. # Tricker使用的接口
  72. @abstractmethod
  73. def Trick(self, angle: float) -> bool:
  74. pass
  75. @abstractmethod
  76. def StartExam(self) -> bool:
  77. pass
  78. @abstractmethod
  79. def EndExam(self) -> bool:
  80. pass
  81. @abstractmethod
  82. def MakeFail(self) -> bool:
  83. pass
  84. class IAPI(metaclass=ABCMeta):
  85. # 选手可执行的操作
  86. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  87. @abstractmethod
  88. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  89. pass
  90. # 向特定方向移动
  91. @abstractmethod
  92. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  93. pass
  94. @abstractmethod
  95. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  96. pass
  97. @abstractmethod
  98. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  99. pass
  100. @abstractmethod
  101. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  102. pass
  103. # 道具和技能相关
  104. @abstractmethod
  105. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  106. pass
  107. @abstractmethod
  108. def UseProp(self) -> Future[bool]:
  109. pass
  110. @abstractmethod
  111. def UseSkill(self) -> Future[bool]:
  112. pass
  113. # 消息相关,接收消息时无消息则返回(-1, '')
  114. @abstractmethod
  115. def SendMessage(self, toID: int, message: str) -> Future[bool]:
  116. pass
  117. @abstractmethod
  118. def HaveMessage(self) -> Future[bool]:
  119. pass
  120. @abstractmethod
  121. def GetMessage(self) -> Future[tuple[int, str]]:
  122. pass
  123. # 等待下一帧
  124. @abstractmethod
  125. def Wait(self) -> Future[bool]:
  126. pass
  127. # 获取各类游戏中的消息
  128. @abstractmethod
  129. def GetFrameCount(self) -> int:
  130. pass
  131. @abstractmethod
  132. def GetPlayerGUIDs(self) -> List[int]:
  133. pass
  134. @abstractmethod
  135. def GetTrickers(self) -> List[THUAI6.Tricker]:
  136. pass
  137. @abstractmethod
  138. def GetStudents(self) -> List[THUAI6.Student]:
  139. pass
  140. @abstractmethod
  141. def GetProps(self) -> List[THUAI6.Prop]:
  142. pass
  143. @abstractmethod
  144. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  145. pass
  146. @abstractmethod
  147. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  148. pass
  149. @abstractmethod
  150. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  151. pass
  152. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  153. @abstractmethod
  154. def PrintStudent(self) -> None:
  155. pass
  156. @abstractmethod
  157. def PrintTricker(self) -> None:
  158. pass
  159. @abstractmethod
  160. def PrintProp(self) -> None:
  161. pass
  162. @abstractmethod
  163. def PrintSelfInfo(self) -> None:
  164. pass
  165. class IStudentAPI(IAPI, metaclass=ABCMeta):
  166. # 人类阵营的特殊函数
  167. @abstractmethod
  168. def Graduate(self) -> Future[bool]:
  169. pass
  170. @abstractmethod
  171. def StartLearning(self) -> Future[bool]:
  172. pass
  173. @abstractmethod
  174. def EndLearning(self) -> Future[bool]:
  175. pass
  176. @abstractmethod
  177. def StartHelpMate(self) -> Future[bool]:
  178. pass
  179. @abstractmethod
  180. def EndHelpMate(self) -> Future[bool]:
  181. pass
  182. class ITrickerAPI(IAPI, metaclass=ABCMeta):
  183. # 屠夫阵营的特殊函数
  184. @abstractmethod
  185. def Trick(self, angle: float) -> Future[bool]:
  186. pass
  187. @abstractmethod
  188. def StartExam(self) -> Future[bool]:
  189. pass
  190. @abstractmethod
  191. def EndExam(self) -> Future[bool]:
  192. pass
  193. @abstractmethod
  194. def MakeFail(self) -> Future[bool]:
  195. pass
  196. class IAI(metaclass=ABCMeta):
  197. @abstractmethod
  198. def play(self, api: Union[IStudentAPI, ITrickerAPI]) -> None:
  199. pass
  200. class IGameTimer(metaclass=ABCMeta):
  201. # 用于计时的接口
  202. @abstractmethod
  203. def StartTimer(self) -> None:
  204. pass
  205. @abstractmethod
  206. def EndTimer(self) -> None:
  207. pass
  208. @abstractmethod
  209. def Play(self, ai: IAI) -> None:
  210. pass
  211. class IErrorHandler(metaclass=ABCMeta):
  212. @staticmethod
  213. @abstractmethod
  214. def result():
  215. pass