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接口(cpp).md 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. [toc]
  2. # CAPI接口(cpp)
  3. ## 接口解释
  4. ### 主动指令
  5. - 每帧最多发送50条主动指令
  6. - EndAllAction 及 Move 指令调用数总和一帧内不超过 10 次
  7. - 指令执行失败可能会使你返回idle状态,而非简单的无效
  8. #### 移动
  9. - `std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian)`:移动,`timeInMilliseconds` 为移动时间,单位毫秒;`angleInRadian` 表示移动方向,单位弧度,使用极坐标,**竖直向下方向为 x 轴,水平向右方向为 y 轴**。因为移动过程中你会受到多种干扰使得移动结果不符合你的预期;因此建议小步移动,边移动边考虑之后的行为。
  10. - 5ms 以内的移动指令会被禁止,你不应当使用过小的移动指令
  11. - `std::future<bool> MoveRight(uint32_t timeInMilliseconds)`即向右移动,`MoveLeft`、`MoveDown`、`MoveUp` 同理
  12. #### 使用技能
  13. - `std::future<bool> UseSkill(int32_t skillID)`:使用对应序号的主动技能
  14. #### 人物
  15. - `std::future<bool> EndAllAction()`:可以使不处在不可行动状态中的玩家终止当前行动
  16. - 在指令仍在进行时,重复发出同一类型的交互指令和移动指令是无效的,你需要先发出 EndAllAction 指令终止进行的指令
  17. #### 攻击
  18. - `std::future<bool> Attack(double angleInRadian)`:`angleInRadian` 为攻击方向
  19. #### 学习与毕业
  20. - `std::future<bool> StartLearning()`:在教室里开始做作业
  21. - `std::future<bool> StartOpenGate()`:开始开启校门
  22. - `std::future<bool> Graduate()`:从开启的校门或隐藏校门毕业。
  23. #### 勉励与唤醒
  24. - `std::future<bool> StartEncourageMate(int64_t mateID)`:勉励对应玩家 ID 的学生。
  25. - `std::future<bool> StartRouseMate(int64_t mateID)`:唤醒对应玩家 ID 的沉迷的学生。
  26. #### 地图互动
  27. - `std::future<bool> OpenDoor()`:开门
  28. - `std::future<bool> CloseDoor()`:关门
  29. - `std::future<bool> SkipWindow()`:翻窗
  30. - `std::future<bool> StartOpenChest()`:开箱
  31. #### 道具
  32. - `bool PickProp(THUAI6::PropType prop)`:捡起与自己处于同一个格子(cell)的道具。
  33. - `bool UseProp(THUAI6::PropType prop)`:使用对应类型的道具
  34. - `bool ThrowProp(THUAI6::PropType prop)`:将对应类型的道具扔在原地
  35. ### 信息获取
  36. #### 队内信息
  37. - `std::future<bool> SendTextMessage(int64_t, std::string)`:给同队的队友发送文本消息,队友在下一帧收到。第一个参数指定发送的对象,第二个参数指定发送的内容,形式为 Unicode 字符串,不得超过 256 字节。
  38. - `std::future<bool> SendBinaryMessage(int64_t, std::string)`:给同队的队友发送二进制消息,队友在下一帧收到。第一个参数指定发送的对象,第二个参数指定发送的内容,形式为二进制字符串,不得超过 256 字节。
  39. - `bool HaveMessage()`:是否有队友发来的尚未接收的信息。
  40. - `std::pair<int64_t, std::string> GetMessage()`:按照消息发送顺序获取来自队友的信息,第一个参数为发送该消息的 PlayerID。
  41. > 需要注意,收到的二进制消息和文本消息都会被这个函数一并返回,选手需要自行约定消息类型。
  42. #### 查询可视范围内的信息
  43. - `std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const`:对于学生,返回所有学生的信息;对于捣蛋鬼,返回可视学生的信息。
  44. - `std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const`:返回所有可视捣蛋鬼的信息。
  45. - `std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const`:返回所有可视道具的信息。
  46. - `std::vector<std::shared_ptr<const THUAI6::Bullet>> GetBullets() const`:返回所有可视子弹(攻击)的信息。
  47. - `bool HaveView(int gridX, int gridY) const`:判断坐标是否可见
  48. #### 查询特定位置物体的信息
  49. 下面的 CellX 和 CellY 指的是地图格数,而非绝对坐标。
  50. - `THUAI6::PlaceType GetPlaceType(int32_t cellX, int32_t cellY)`:返回某一位置场地种类信息。场地种类详见 structure.h。
  51. - 以下指令,若查询物品当前在视野内,则返回最新进度/状态;若物品当前不在视野内、但曾经出现在视野内,则返回最后一次看到时的进度/状态;若物品从未出现在视野内,或查询位置没有对应的物品,则返回 -1。
  52. - `int32_t GetChestProgress(int32_t cellX, int32_t cellY) const`:查询特定位置箱子开启进度
  53. - `int32_t GetGateProgress(int32_t cellX, int32_t cellY) const`:查询特定位置校门开启进度
  54. - `int32_t GetClassroomProgress(int32_t cellX, int32_t cellY) const`:查询特定位置教室作业完成进度
  55. - `int32_t GetDoorProgress(int32_t cellX, int32_t cellY) const`:查询特定位置门开启状态
  56. - `bool IsDoorOpen(int32_t cellX, int32_t cellY) const`:查询特定位置门是否开启,没有门/不在视野内也返回 false
  57. - `THUAI6::HiddenGateState GetHiddenGateState(int32_t cellX, int32_t cellY) const`:查询特定位置隐藏校门状态,没有隐藏校门/不在视野内返回 THUAI6::HiddenGateState::Null
  58. #### 其他
  59. - `std::shared_ptr<const THUAI6::GameInfo> GetGameInfo() const`:查询当前游戏状态
  60. - `std::vector<int64_t> GetPlayerGUIDs() const`:获取所有玩家的 GUID
  61. - `int GetFrameCount() const`:获取目前所进行的帧数
  62. - `std::shared_ptr<const THUAI6::Tricker> GetSelfInfo() const` 或 `std::shared_ptr<const THUAI6::Student> GetSelfInfo() const`:获取自己的信息
  63. - `std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const`:返回整张地图的地形信息。可以写成类似 `api.GetFullMap()[x][y]`,其中 x 为地图自上到下第几行,y 为自左向右第几列,注意从 0 开始
  64. ### 辅助函数
  65. `static inline int CellToGrid(int cell) noexcept`:将地图格数 cell 转换为绝对坐标 grid。
  66. `static inline int GridToCell(int grid) noexcept`:将绝对坐标 grid 转换为地图格数 cell。
  67. 下面为用于 DEBUG 的输出函数,选手仅在开启 Debug 模式的情况下可以使用
  68. ~~~c++
  69. void Print(std::string str) const;
  70. void PrintStudent() const;
  71. void PrintTricker() const;
  72. void PrintProp() const;
  73. void PrintSelfInfo() const;
  74. ~~~
  75. ### 部分属性解释 stuctures.h
  76. ~~~c++
  77. struct Player
  78. {
  79. std::vector<PropType> props;//大小固定为3,空的位置为NullPropType
  80. };
  81. ~~~
  82. ## 接口一览
  83. ~~~c++
  84. // 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴
  85. virtual std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) = 0;
  86. // 向特定方向移动
  87. virtual std::future<bool> MoveRight(int64_t timeInMilliseconds) = 0;
  88. virtual std::future<bool> MoveUp(int64_t timeInMilliseconds) = 0;
  89. virtual std::future<bool> MoveLeft(int64_t timeInMilliseconds) = 0;
  90. virtual std::future<bool> MoveDown(int64_t timeInMilliseconds) = 0;
  91. // 捡道具、使用技能
  92. virtual std::future<bool> PickProp(THUAI6::PropType prop) = 0;
  93. virtual std::future<bool> UseProp(THUAI6::PropType prop) = 0;
  94. virtual std::future<bool> UseSkill(int32_t skillID) = 0;
  95. virtual std::future<bool> Attack(double angleInRadian) = 0;
  96. virtual std::future<bool> OpenDoor() = 0;
  97. virtual std::future<bool> CloseDoor() = 0;
  98. virtual std::future<bool> SkipWindow() = 0;
  99. virtual std::future<bool> StartOpenGate() = 0;
  100. virtual std::future<bool> StartOpenChest() = 0;
  101. virtual std::future<bool> EndAllAction() = 0;
  102. // 发送信息、接受信息,注意收消息时无消息则返回nullopt
  103. virtual std::future<bool> SendTextMessage(int64_t, std::string) = 0;
  104. virtual std::future<bool> SendBinaryMessage(int64_t, std::string) = 0;
  105. [[nodiscard]] virtual bool HaveMessage() = 0;
  106. [[nodiscard]] virtual std::pair<int64_t, std::string> GetMessage() = 0;
  107. // 等待下一帧
  108. virtual std::future<bool> Wait() = 0;
  109. // 获取视野内可见的学生/捣蛋鬼的信息
  110. [[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const = 0;
  111. [[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const = 0;
  112. // 获取视野内可见的道具信息
  113. [[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const = 0;
  114. // 获取地图信息
  115. [[nodiscard]] virtual std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const = 0;
  116. [[nodiscard]] virtual THUAI6::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
  117. [[nodiscard]] virtual bool IsDoorOpen(int32_t cellX, int32_t cellY) const = 0;
  118. [[nodiscard]] virtual int32_t GetChestProgress(int32_t cellX, int32_t cellY) const = 0;
  119. [[nodiscard]] virtual int32_t GetGateProgress(int32_t cellX, int32_t cellY) const = 0;
  120. [[nodiscard]] virtual int32_t GetClassroomProgress(int32_t cellX, int32_t cellY) const = 0;
  121. [[nodiscard]] virtual THUAI6::HiddenGateState GetHiddenGateState(int32_t cellX, int32_t cellY) const = 0;
  122. [[nodiscard]] virtual int32_t GetDoorProgress(int32_t cellX, int32_t cellY) const = 0;
  123. [[nodiscard]] virtual std::shared_ptr<const THUAI6::GameInfo> GetGameInfo() const = 0;
  124. // 获取所有玩家的GUID
  125. [[nodiscard]] virtual std::vector<int64_t> GetPlayerGUIDs() const = 0;
  126. // 获取游戏目前所进行的帧数
  127. [[nodiscard]] virtual int GetFrameCount() const = 0;
  128. /*****选手可能用的辅助函数*****/
  129. // 获取指定格子中心的坐标
  130. [[nodiscard]] static inline int CellToGrid(int cell) noexcept
  131. {
  132. return cell * numOfGridPerCell + numOfGridPerCell / 2;
  133. }
  134. // 获取指定坐标点所位于的格子的 X 序号
  135. [[nodiscard]] static inline int GridToCell(int grid) noexcept
  136. {
  137. return grid / numOfGridPerCell;
  138. }
  139. [[nodiscard]] virtual bool HaveView(int gridX, int gridY) const = 0;
  140. // 用于DEBUG的输出函数,选手仅在开启Debug模式的情况下可以使用
  141. virtual void Print(std::string str) const = 0;
  142. virtual void PrintStudent() const = 0;
  143. virtual void PrintTricker() const = 0;
  144. virtual void PrintProp() const = 0;
  145. virtual void PrintSelfInfo() const = 0;
  146. };
  147. class IStudentAPI : public IAPI
  148. {
  149. public:
  150. /*****学生阵营的特定函数*****/
  151. virtual std::future<bool> StartLearning() = 0;
  152. virtual std::future<bool> StartEncourageMate(int64_t mateID) = 0;
  153. virtual std::future<bool> StartRouseMate(int64_t mateID) = 0;
  154. virtual std::future<bool> Graduate() = 0;
  155. [[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const = 0;
  156. };
  157. class ITrickerAPI : public IAPI
  158. {
  159. public:
  160. /*****捣蛋鬼阵营的特定函数*****/
  161. [[nodiscard]] virtual std::shared_ptr<const THUAI6::Tricker> GetSelfInfo() const = 0;
  162. };
  163. ~~~