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.

CAPI接口(python).md 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. [toc]
  2. # CAPI接口(python)
  3. ## 接口解释
  4. ### 主动指令
  5. - 每帧最多发送 50 条主动指令
  6. - EndAllAction 及 Move 指令调用数总和一帧内不超过 10 次
  7. #### 移动
  8. - `def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]`:移动,`timeInMilliseconds` 为移动时间,单位毫秒;`angleInRadian` 表示移动方向,单位弧度,使用极坐标,**竖直向下方向为 x 轴,水平向右方向为 y 轴**因为移动过程中你会受到多种干扰使得移动结果不符合你的预期;因此建议小步移动,边移动边考虑之后的行为。
  9. - 5ms 以内的移动指令会被禁止,你不应当使用过小的移动指令
  10. - `def MoveRight(self, timeInMilliseconds: int) -> Future[bool]` 即向右移动, `MoveLeft`、`MoveDown`、`MoveUp` 同理
  11. #### 使用技能
  12. - `def UseSkill(self, skillID: int) -> Future[bool]`:使用对应序号的主动技能
  13. #### 人物
  14. - `def EndAllAction(self) -> Future[bool]`:可以使不处在不可行动状态中的玩家终止当前行动
  15. - 在指令仍在进行时,重复发出同一类型的交互指令和移动指令是无效的,你需要先发出 EndAllAction 指令终止进行的指令
  16. - 实际上唤醒或勉励不同的人是有效的
  17. - EndAllAction 及 Move 指令调用数总和一帧内不超过 10 次
  18. #### 攻击
  19. - `def Attack(self, angle: float) -> Future[bool]`:`angleInRadian` 为攻击方向
  20. #### 学习与毕业
  21. - `def StartLearning(self) -> Future[bool]`:在教室里开始做作业
  22. - `def StartOpenGate(self) -> Future[bool]`:开始开启校门
  23. - `def Graduate(self) -> Future[bool]`:从开启的校门或隐藏校门毕业。
  24. #### 勉励与唤醒
  25. - `def StartEncourageMate(self, mateID: int) -> Future[bool]`:勉励对应玩家 ID 的学生。
  26. - `def StartRouseMate(self, mateID: int) -> Future[bool]`:唤醒对应玩家 ID 的沉迷的学生。
  27. #### 地图互动
  28. - `def OpenDoor(self) -> Future[bool]`:开门
  29. - `def CloseDoor(self) -> Future[bool]`:关门
  30. - `def SkipWindow(self) -> Future[bool]`:翻窗
  31. - `def StartOpenChest(self) -> Future[bool]`:开箱
  32. #### 道具
  33. - `def PickProp(self, propType: THUAI6.PropType) -> Future[bool]`:捡起与自己处于同一个格子(cell)的道具。
  34. - `def UseProp(self, propType: THUAI6.PropType) -> Future[bool]`:使用对应类型的道具
  35. - `def ThrowProp(self, propType: THUAI6.PropType) -> Future[bool]`:将对应类型的道具扔在原地
  36. ### 信息获取
  37. #### 队内信息
  38. - `def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]`:给同队的队友发送消息,队友在下一帧收到。第一个参数指定发送的对象,第二个参数指定发送的内容,可以是Unicode字符串,也可以是二进制字符串;不得超过 256 字节。
  39. - `def HaveMessage(self) -> bool`:是否有队友发来的尚未接收的信息。
  40. - `def GetMessage(self) -> Tuple[int, Union[str, bytes]]`:按照消息发送顺序获取来自队友的信息,第一个参数为发送该消息的 PlayerID。
  41. > 需要注意,文本消息和二进制消息都会在这里接受,选手可以简单地使用 `isinstance()` 来判断消息类型。
  42. #### 查询可视范围内的信息
  43. - `def GetStudents(self) -> List[THUAI6.Student]`:对于学生,返回所有学生的信息;对于捣蛋鬼,返回可视学生的信息。
  44. - `def GetTrickers(self) -> List[THUAI6.Tricker]`:返回所有可视捣蛋鬼的信息。
  45. - `def GetProps(self) -> List[THUAI6.Prop]`:返回所有可视道具的信息。
  46. - `def GetBullets(self) -> List[THUAI6.Bullet]`:返回所有可视子弹(攻击)的信息。
  47. - `def HaveView(self, gridX: int, gridY: int) -> bool`:判断坐标是否可见
  48. #### 查询特定位置物体的信息
  49. 下面的 CellX 和 CellY 指的是地图格数,而非绝对坐标。
  50. - `def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType`:返回某一位置场地种类信息。场地种类详见 structure.h。
  51. - 以下指令,若查询物品当前在视野内,则返回最新进度/状态;若物品当前不在视野内、但曾经出现在视野内,则返回最后一次看到时的进度/状态;若物品从未出现在视野内,或查询位置没有对应的物品,则返回 -1。
  52. - `def GetChestProgress(self, cellX: int, cellY: int) -> int`:查询特定位置箱子开启进度
  53. - `def GetGateProgress(self, cellX: int, cellY: int) -> int`:查询特定位置校门开启进度
  54. - `def GetClassroomProgress(self, cellX: int, cellY: int) -> int`:查询特定位置教室作业完成进度
  55. - `def GetDoorProgress(self, cellX: int, cellY: int) -> int`:查询特定位置门开启状态
  56. - `def IsDoorOpen(self, cellX: int, cellY: int) -> bool`:查询特定位置门是否开启,没有门/不在视野内也返回 false
  57. - `def GetHiddenGateState(self, cellX: int, cellY: int) -> THUAI6.HiddenGateState`:查询特定位置隐藏校门状态,没有隐藏校门/不在视野内返回 THUAI6::HiddenGateState::Null
  58. #### 其他
  59. - `def GetGameInfo(self) -> THUAI6.GameInfo`:查询当前游戏状态
  60. - `def GetPlayerGUIDs(self) -> List[int]`:获取所有玩家的 GUID
  61. - `def GetFrameCount(self) -> int`:获取目前所进行的帧数
  62. - `def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]`:获取自己的信息
  63. - `def GetFullMap(self) -> List[List[THUAI6.PlaceType]]`:返回整张地图的地形信息。可以写成类似 `self.GetFullMap()[x][y]`,其中 x 为地图自上到下第几行,y 为自左向右第几列,注意从 0 开始
  64. ### 辅助函数
  65. `def CellToGrid(cell: int) -> int`:将地图格数 cell 转换为绝对坐标 grid。
  66. `def GridToCell(grid: int) -> int`:将绝对坐标 grid 转换为地图格数 cell。
  67. 下面为用于 DEBUG 的输出函数,选手仅在开启 Debug 模式的情况下可以使用
  68. ~~~python
  69. def Print(self, cont: str) -> None:
  70. def PrintStudent(self) -> None:
  71. def PrintTricker(self) -> None:
  72. def PrintProp(self) -> None:
  73. def PrintSelfInfo(self) -> None:
  74. ~~~
  75. ### 部分属性解释 stuctures.h
  76. ~~~python
  77. class Player:
  78. def __init__(self, **kwargs) -> None:
  79. self.prop: List[PropType] = []//大小固定为3,空的位置为NullPropType
  80. ~~~
  81. ## 接口一览
  82. ~~~python
  83. class IAPI(metaclass=ABCMeta):
  84. # 选手可执行的操作
  85. # 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  86. @abstractmethod
  87. def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]:
  88. pass
  89. # 向特定方向移动
  90. @abstractmethod
  91. def MoveRight(self, timeInMilliseconds: int) -> Future[bool]:
  92. pass
  93. @abstractmethod
  94. def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]:
  95. pass
  96. @abstractmethod
  97. def MoveUp(self, timeInMilliseconds: int) -> Future[bool]:
  98. pass
  99. @abstractmethod
  100. def MoveDown(self, timeInMilliseconds: int) -> Future[bool]:
  101. pass
  102. # 道具和技能相关
  103. @abstractmethod
  104. def PickProp(self, propType: THUAI6.PropType) -> Future[bool]:
  105. pass
  106. @abstractmethod
  107. def UseProp(self, propType: THUAI6.PropType) -> Future[bool]:
  108. pass
  109. @abstractmethod
  110. def ThrowProp(self, propType: THUAI6.PropType) -> Future[bool]:
  111. pass
  112. @abstractmethod
  113. def UseSkill(self, skillID: int) -> Future[bool]:
  114. pass
  115. @abstractmethod
  116. def Attack(self, angle: float) -> Future[bool]:
  117. pass
  118. @abstractmethod
  119. def OpenDoor(self) -> Future[bool]:
  120. pass
  121. @abstractmethod
  122. def CloseDoor(self) -> Future[bool]:
  123. pass
  124. @abstractmethod
  125. def SkipWindow(self) -> Future[bool]:
  126. pass
  127. @abstractmethod
  128. def StartOpenGate(self) -> Future[bool]:
  129. pass
  130. @abstractmethod
  131. def StartOpenChest(self) -> Future[bool]:
  132. pass
  133. @abstractmethod
  134. def EndAllAction(self) -> Future[bool]:
  135. pass
  136. # 消息相关,接收消息时无消息则返回(-1, '')
  137. @abstractmethod
  138. def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]:
  139. pass
  140. @abstractmethod
  141. def HaveMessage(self) -> bool:
  142. pass
  143. @abstractmethod
  144. def GetMessage(self) -> Tuple[int, Union[str, bytes]]:
  145. pass
  146. # 等待下一帧
  147. @abstractmethod
  148. def Wait(self) -> Future[bool]:
  149. pass
  150. # 获取各类游戏中的消息
  151. @abstractmethod
  152. def GetFrameCount(self) -> int:
  153. pass
  154. @abstractmethod
  155. def GetPlayerGUIDs(self) -> List[int]:
  156. pass
  157. @abstractmethod
  158. def GetTrickers(self) -> List[THUAI6.Tricker]:
  159. pass
  160. @abstractmethod
  161. def GetStudents(self) -> List[THUAI6.Student]:
  162. pass
  163. @abstractmethod
  164. def GetProps(self) -> List[THUAI6.Prop]:
  165. pass
  166. @abstractmethod
  167. def GetBullets(self) -> List[THUAI6.Bullet]:
  168. pass
  169. @abstractmethod
  170. def GetSelfInfo(self) -> Union[THUAI6.Student, THUAI6.Tricker]:
  171. pass
  172. @abstractmethod
  173. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  174. pass
  175. @abstractmethod
  176. def GetPlaceType(self, cellX: int, cellY: int) -> THUAI6.PlaceType:
  177. pass
  178. @abstractmethod
  179. def IsDoorOpen(self, cellX: int, cellY: int) -> bool:
  180. pass
  181. @abstractmethod
  182. def GetChestProgress(self, cellX: int, cellY: int) -> int:
  183. pass
  184. @abstractmethod
  185. def GetGateProgress(self, cellX: int, cellY: int) -> int:
  186. pass
  187. @abstractmethod
  188. def GetClassroomProgress(self, cellX: int, cellY: int) -> int:
  189. pass
  190. @abstractmethod
  191. def GetDoorProgress(self, cellX: int, cellY: int) -> int:
  192. pass
  193. @abstractmethod
  194. def GetHiddenGateState(self, cellX: int, cellY: int) -> THUAI6.HiddenGateState:
  195. pass
  196. @abstractmethod
  197. def GetGameInfo(self) -> THUAI6.GameInfo:
  198. pass
  199. @abstractmethod
  200. def HaveView(self, gridX: int, gridY: int) -> bool
  201. pass
  202. # 用于DEBUG的输出函数,仅在DEBUG模式下有效
  203. @abstractmethod
  204. def Print(self, cont: str) -> None:
  205. pass
  206. @abstractmethod
  207. def PrintStudent(self) -> None:
  208. pass
  209. @abstractmethod
  210. def PrintTricker(self) -> None:
  211. pass
  212. @abstractmethod
  213. def PrintProp(self) -> None:
  214. pass
  215. @abstractmethod
  216. def PrintSelfInfo(self) -> None:
  217. pass
  218. class IStudentAPI(IAPI, metaclass=ABCMeta):
  219. # 人类阵营的特殊函数
  220. @abstractmethod
  221. def Graduate(self) -> Future[bool]:
  222. pass
  223. @abstractmethod
  224. def StartLearning(self) -> Future[bool]:
  225. pass
  226. @abstractmethod
  227. def StartEncourageMate(self, mateID: int) -> Future[bool]:
  228. pass
  229. @abstractmethod
  230. def StartRouseMate(self, mateID: int) -> Future[bool]:
  231. pass
  232. @abstractmethod
  233. def GetSelfInfo(self) -> THUAI6.Student:
  234. pass
  235. class ITrickerAPI(IAPI, metaclass=ABCMeta):
  236. # 屠夫阵营的特殊函数
  237. @abstractmethod
  238. def GetSelfInfo(self) -> THUAI6.Tricker:
  239. pass
  240. ~~~