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

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