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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. from typing import List, Union, Tuple
  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 GetBullets(self) -> List[THUAI6.Bullet]:
  18. pass
  19. @abstractmethod
  20. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  21. pass
  22. @abstractmethod
  23. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  24. pass
  25. @abstractmethod
  26. def GetPlaceType(self, x: int, y: int) -> THUAI6.PlaceType:
  27. pass
  28. @abstractmethod
  29. def GetClassroomProgress(self, x: int, y: int) -> int:
  30. pass
  31. @abstractmethod
  32. def GetChestProgress(self, x: int, y: int) -> int:
  33. pass
  34. @abstractmethod
  35. def GetGateProgress(self, x: int, y: int) -> int:
  36. pass
  37. @abstractmethod
  38. def IsDoorOpen(self, x: int, y: int) -> bool:
  39. pass
  40. @abstractmethod
  41. def GetHiddenGateState(self, x: int, y: int) -> THUAI6.HiddenGateState:
  42. pass
  43. @abstractmethod
  44. def GetDoorProgress(self, x: int, y: int) -> int:
  45. pass
  46. @abstractmethod
  47. def GetGameInfo(self) -> THUAI6.GameInfo:
  48. pass
  49. @abstractmethod
  50. def Move(self, time: int, angle: float) -> bool:
  51. pass
  52. @abstractmethod
  53. def PickProp(self, propType: THUAI6.PropType) -> bool:
  54. pass
  55. @abstractmethod
  56. def UseProp(self, propType: THUAI6.PropType) -> bool:
  57. pass
  58. @abstractmethod
  59. def ThrowProp(self, propType: THUAI6.PropType) -> bool:
  60. pass
  61. @abstractmethod
  62. def UseSkill(self, skillID: int) -> bool:
  63. pass
  64. @abstractmethod
  65. def SendMessage(self, toID: int, message: Union[str, bytes]) -> bool:
  66. pass
  67. @abstractmethod
  68. def HaveMessage(self) -> bool:
  69. pass
  70. @abstractmethod
  71. def GetMessage(self) -> Tuple[int, str]:
  72. pass
  73. @abstractmethod
  74. def WaitThread(self) -> bool:
  75. pass
  76. @abstractmethod
  77. def GetCounter(self) -> int:
  78. pass
  79. @abstractmethod
  80. def GetPlayerGUIDs(self) -> List[int]:
  81. pass
  82. @abstractmethod
  83. def Attack(self, angle: float) -> bool:
  84. pass
  85. @abstractmethod
  86. def OpenDoor(self) -> bool:
  87. pass
  88. @abstractmethod
  89. def CloseDoor(self) -> bool:
  90. pass
  91. @abstractmethod
  92. def SkipWindow(self) -> bool:
  93. pass
  94. @abstractmethod
  95. def StartOpenGate(self) -> bool:
  96. pass
  97. @abstractmethod
  98. def StartOpenChest(self) -> bool:
  99. pass
  100. @abstractmethod
  101. def EndAllAction(self) -> bool:
  102. pass
  103. # IStudentAPI使用的接口
  104. @abstractmethod
  105. def Graduate(self) -> bool:
  106. pass
  107. @abstractmethod
  108. def StartLearning(self) -> bool:
  109. pass
  110. @abstractmethod
  111. def StartEncourageMate(self, mateID: int) -> bool:
  112. pass
  113. @abstractmethod
  114. def StartRouseMate(self, mateID: int) -> bool:
  115. pass
  116. @abstractmethod
  117. def HaveView(
  118. self, gridX: int, gridY: int, selfX: int, selfY: int, viewRange: int
  119. ) -> bool:
  120. pass
  121. class IAPI(metaclass=ABCMeta):
  122. # 选手可执行的操作
  123. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  124. @abstractmethod
  125. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  126. pass
  127. # 向特定方向移动
  128. @abstractmethod
  129. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  130. pass
  131. @abstractmethod
  132. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  133. pass
  134. @abstractmethod
  135. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  136. pass
  137. @abstractmethod
  138. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  139. pass
  140. # 道具和技能相关
  141. @abstractmethod
  142. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  143. pass
  144. @abstractmethod
  145. def UseProp(self, propType: THUAI6.PropType) -> Future[bool]:
  146. pass
  147. @abstractmethod
  148. def ThrowProp(self, propType: THUAI6.PropType) -> Future[bool]:
  149. pass
  150. @abstractmethod
  151. def UseSkill(self, skillID: int) -> Future[bool]:
  152. pass
  153. @abstractmethod
  154. def Attack(self, angle: float) -> Future[bool]:
  155. pass
  156. @abstractmethod
  157. def OpenDoor(self) -> Future[bool]:
  158. pass
  159. @abstractmethod
  160. def CloseDoor(self) -> Future[bool]:
  161. pass
  162. @abstractmethod
  163. def SkipWindow(self) -> Future[bool]:
  164. pass
  165. @abstractmethod
  166. def StartOpenGate(self) -> Future[bool]:
  167. pass
  168. @abstractmethod
  169. def StartOpenChest(self) -> Future[bool]:
  170. pass
  171. @abstractmethod
  172. def EndAllAction(self) -> Future[bool]:
  173. pass
  174. # 消息相关,接收消息时无消息则返回(-1, '')
  175. @abstractmethod
  176. def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]:
  177. pass
  178. @abstractmethod
  179. def HaveMessage(self) -> bool:
  180. pass
  181. @abstractmethod
  182. def GetMessage(self) -> Tuple[int, str]:
  183. pass
  184. # 等待下一帧
  185. @abstractmethod
  186. def Wait(self) -> bool:
  187. pass
  188. # 获取各类游戏中的消息
  189. @abstractmethod
  190. def GetFrameCount(self) -> int:
  191. pass
  192. @abstractmethod
  193. def GetPlayerGUIDs(self) -> List[int]:
  194. pass
  195. @abstractmethod
  196. def GetTrickers(self) -> List[THUAI6.Tricker]:
  197. pass
  198. @abstractmethod
  199. def GetStudents(self) -> List[THUAI6.Student]:
  200. pass
  201. @abstractmethod
  202. def GetProps(self) -> List[THUAI6.Prop]:
  203. pass
  204. @abstractmethod
  205. def GetBullets(self) -> List[THUAI6.Bullet]:
  206. pass
  207. @abstractmethod
  208. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  209. pass
  210. @abstractmethod
  211. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  212. pass
  213. @abstractmethod
  214. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  215. pass
  216. @abstractmethod
  217. def IsDoorOpen(self, cellX: int, cellY: int) -> bool:
  218. pass
  219. @abstractmethod
  220. def GetChestProgress(self, cellX: int, cellY: int) -> int:
  221. pass
  222. @abstractmethod
  223. def GetGateProgress(self, cellX: int, cellY: int) -> int:
  224. pass
  225. @abstractmethod
  226. def GetClassroomProgress(self, cellX: int, cellY: int) -> int:
  227. pass
  228. @abstractmethod
  229. def GetDoorProgress(self, cellX: int, cellY: int) -> int:
  230. pass
  231. @abstractmethod
  232. def GetHiddenGateState(self, cellX: int, cellY: int) -> THUAI6.HiddenGateState:
  233. pass
  234. @abstractmethod
  235. def GetGameInfo(self) -> THUAI6.GameInfo:
  236. pass
  237. @abstractmethod
  238. def HaveView(self, gridX: int, gridY: int) -> bool:
  239. pass
  240. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  241. @abstractmethod
  242. def Print(self, cont: str) -> None:
  243. pass
  244. @abstractmethod
  245. def PrintStudent(self) -> None:
  246. pass
  247. @abstractmethod
  248. def PrintTricker(self) -> None:
  249. pass
  250. @abstractmethod
  251. def PrintProp(self) -> None:
  252. pass
  253. @abstractmethod
  254. def PrintSelfInfo(self) -> None:
  255. pass
  256. class IStudentAPI(IAPI, metaclass=ABCMeta):
  257. # 人类阵营的特殊函数
  258. @abstractmethod
  259. def Graduate(self) -> Future[bool]:
  260. pass
  261. @abstractmethod
  262. def StartLearning(self) -> Future[bool]:
  263. pass
  264. @abstractmethod
  265. def StartEncourageMate(self, mateID: int) -> Future[bool]:
  266. pass
  267. @abstractmethod
  268. def StartRouseMate(self, mateID: int) -> Future[bool]:
  269. pass
  270. @abstractmethod
  271. def GetSelfInfo(self) -> THUAI6.Student:
  272. pass
  273. class ITrickerAPI(IAPI, metaclass=ABCMeta):
  274. # 屠夫阵营的特殊函数
  275. @abstractmethod
  276. def GetSelfInfo(self) -> THUAI6.Tricker:
  277. pass
  278. class IAI(metaclass=ABCMeta):
  279. @abstractmethod
  280. def StudentPlay(self, api: IStudentAPI) -> None:
  281. pass
  282. @abstractmethod
  283. def TrickerPlay(self, api: ITrickerAPI) -> None:
  284. pass
  285. class IGameTimer(metaclass=ABCMeta):
  286. # 用于计时的接口
  287. @abstractmethod
  288. def StartTimer(self) -> None:
  289. pass
  290. @abstractmethod
  291. def EndTimer(self) -> None:
  292. pass
  293. @abstractmethod
  294. def Play(self, ai: IAI) -> None:
  295. pass
  296. class IErrorHandler(metaclass=ABCMeta):
  297. @staticmethod
  298. @abstractmethod
  299. def result():
  300. pass