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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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(self, gridX: int, gridY: int, selfX: int, selfY: int, viewRange: int) -> bool:
  118. pass
  119. class IAPI(metaclass=ABCMeta):
  120. # 选手可执行的操作
  121. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  122. @abstractmethod
  123. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  124. pass
  125. # 向特定方向移动
  126. @abstractmethod
  127. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  128. pass
  129. @abstractmethod
  130. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  131. pass
  132. @abstractmethod
  133. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  134. pass
  135. @abstractmethod
  136. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  137. pass
  138. # 道具和技能相关
  139. @abstractmethod
  140. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  141. pass
  142. @abstractmethod
  143. def UseProp(self, propType: THUAI6.PropType) -> Future[bool]:
  144. pass
  145. @abstractmethod
  146. def ThrowProp(self, propType: THUAI6.PropType) -> Future[bool]:
  147. pass
  148. @abstractmethod
  149. def UseSkill(self, skillID: int) -> Future[bool]:
  150. pass
  151. @abstractmethod
  152. def Attack(self, angle: float) -> Future[bool]:
  153. pass
  154. @abstractmethod
  155. def OpenDoor(self) -> Future[bool]:
  156. pass
  157. @abstractmethod
  158. def CloseDoor(self) -> Future[bool]:
  159. pass
  160. @abstractmethod
  161. def SkipWindow(self) -> Future[bool]:
  162. pass
  163. @abstractmethod
  164. def StartOpenGate(self) -> Future[bool]:
  165. pass
  166. @abstractmethod
  167. def StartOpenChest(self) -> Future[bool]:
  168. pass
  169. @abstractmethod
  170. def EndAllAction(self) -> Future[bool]:
  171. pass
  172. # 消息相关,接收消息时无消息则返回(-1, '')
  173. @abstractmethod
  174. def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]:
  175. pass
  176. @abstractmethod
  177. def HaveMessage(self) -> bool:
  178. pass
  179. @abstractmethod
  180. def GetMessage(self) -> Tuple[int, str]:
  181. pass
  182. # 等待下一帧
  183. @abstractmethod
  184. def Wait(self) -> bool:
  185. pass
  186. # 获取各类游戏中的消息
  187. @abstractmethod
  188. def GetFrameCount(self) -> int:
  189. pass
  190. @abstractmethod
  191. def GetPlayerGUIDs(self) -> List[int]:
  192. pass
  193. @abstractmethod
  194. def GetTrickers(self) -> List[THUAI6.Tricker]:
  195. pass
  196. @abstractmethod
  197. def GetStudents(self) -> List[THUAI6.Student]:
  198. pass
  199. @abstractmethod
  200. def GetProps(self) -> List[THUAI6.Prop]:
  201. pass
  202. @abstractmethod
  203. def GetBullets(self) -> List[THUAI6.Bullet]:
  204. pass
  205. @abstractmethod
  206. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  207. pass
  208. @abstractmethod
  209. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  210. pass
  211. @abstractmethod
  212. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  213. pass
  214. @abstractmethod
  215. def IsDoorOpen(self, cellX: int, cellY: int) -> bool:
  216. pass
  217. @abstractmethod
  218. def GetChestProgress(self, cellX: int, cellY: int) -> int:
  219. pass
  220. @abstractmethod
  221. def GetGateProgress(self, cellX: int, cellY: int) -> int:
  222. pass
  223. @abstractmethod
  224. def GetClassroomProgress(self, cellX: int, cellY: int) -> int:
  225. pass
  226. @abstractmethod
  227. def GetDoorProgress(self, cellX: int, cellY: int) -> int:
  228. pass
  229. @abstractmethod
  230. def GetHiddenGateState(self, cellX: int, cellY: int) -> THUAI6.HiddenGateState:
  231. pass
  232. @abstractmethod
  233. def GetGameInfo(self) -> THUAI6.GameInfo:
  234. pass
  235. @abstractmethod
  236. def HaveView(self, gridX: int, gridY: int) -> bool:
  237. pass
  238. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  239. @abstractmethod
  240. def Print(self, cont: str) -> None:
  241. pass
  242. @abstractmethod
  243. def PrintStudent(self) -> None:
  244. pass
  245. @abstractmethod
  246. def PrintTricker(self) -> None:
  247. pass
  248. @abstractmethod
  249. def PrintProp(self) -> None:
  250. pass
  251. @abstractmethod
  252. def PrintSelfInfo(self) -> None:
  253. pass
  254. class IStudentAPI(IAPI, metaclass=ABCMeta):
  255. # 人类阵营的特殊函数
  256. @abstractmethod
  257. def Graduate(self) -> Future[bool]:
  258. pass
  259. @abstractmethod
  260. def StartLearning(self) -> Future[bool]:
  261. pass
  262. @abstractmethod
  263. def StartEncourageMate(self, mateID: int) -> Future[bool]:
  264. pass
  265. @abstractmethod
  266. def StartRouseMate(self, mateID: int) -> Future[bool]:
  267. pass
  268. @abstractmethod
  269. def GetSelfInfo(self) -> THUAI6.Student:
  270. pass
  271. class ITrickerAPI(IAPI, metaclass=ABCMeta):
  272. # 屠夫阵营的特殊函数
  273. @abstractmethod
  274. def GetSelfInfo(self) -> THUAI6.Tricker:
  275. pass
  276. class IAI(metaclass=ABCMeta):
  277. @abstractmethod
  278. def StudentPlay(self, api: IStudentAPI) -> None:
  279. pass
  280. @abstractmethod
  281. def TrickerPlay(self, api: ITrickerAPI) -> None:
  282. pass
  283. class IGameTimer(metaclass=ABCMeta):
  284. # 用于计时的接口
  285. @abstractmethod
  286. def StartTimer(self) -> None:
  287. pass
  288. @abstractmethod
  289. def EndTimer(self) -> None:
  290. pass
  291. @abstractmethod
  292. def Play(self, ai: IAI) -> None:
  293. pass
  294. class IErrorHandler(metaclass=ABCMeta):
  295. @staticmethod
  296. @abstractmethod
  297. def result():
  298. pass