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.0 kB

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