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

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