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

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