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.

API.cpp 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. #include <optional>
  2. #include "AI.h"
  3. #include "API.h"
  4. #define PI 3.14159265358979323846
  5. int StudentAPI::GetFrameCount() const
  6. {
  7. return logic.GetCounter();
  8. }
  9. int TrickerAPI::GetFrameCount() const
  10. {
  11. return logic.GetCounter();
  12. }
  13. std::future<bool> StudentAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
  14. {
  15. return std::async(std::launch::async, [=]()
  16. { return logic.Move(timeInMilliseconds, angleInRadian); });
  17. }
  18. std::future<bool> StudentAPI::MoveDown(int64_t timeInMilliseconds)
  19. {
  20. return Move(timeInMilliseconds, 0);
  21. }
  22. std::future<bool> StudentAPI::MoveRight(int64_t timeInMilliseconds)
  23. {
  24. return Move(timeInMilliseconds, PI * 0.5);
  25. }
  26. std::future<bool> StudentAPI::MoveUp(int64_t timeInMilliseconds)
  27. {
  28. return Move(timeInMilliseconds, PI);
  29. }
  30. std::future<bool> StudentAPI::MoveLeft(int64_t timeInMilliseconds)
  31. {
  32. return Move(timeInMilliseconds, PI * 1.5);
  33. }
  34. std::future<bool> TrickerAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
  35. {
  36. return std::async(std::launch::async, [=]()
  37. { return logic.Move(timeInMilliseconds, angleInRadian); });
  38. }
  39. std::future<bool> TrickerAPI::MoveDown(int64_t timeInMilliseconds)
  40. {
  41. return Move(timeInMilliseconds, 0);
  42. }
  43. std::future<bool> TrickerAPI::MoveRight(int64_t timeInMilliseconds)
  44. {
  45. return Move(timeInMilliseconds, PI * 0.5);
  46. }
  47. std::future<bool> TrickerAPI::MoveUp(int64_t timeInMilliseconds)
  48. {
  49. return Move(timeInMilliseconds, PI);
  50. }
  51. std::future<bool> TrickerAPI::MoveLeft(int64_t timeInMilliseconds)
  52. {
  53. return Move(timeInMilliseconds, PI * 1.5);
  54. }
  55. std::future<bool> StudentAPI::PickProp(THUAI6::PropType prop)
  56. {
  57. return std::async(std::launch::async, [=]()
  58. { return logic.PickProp(prop); });
  59. }
  60. std::future<bool> StudentAPI::UseProp(THUAI6::PropType prop)
  61. {
  62. return std::async(std::launch::async, [=]()
  63. { return logic.UseProp(prop); });
  64. }
  65. std::future<bool> TrickerAPI::PickProp(THUAI6::PropType prop)
  66. {
  67. return std::async(std::launch::async, [=]()
  68. { return logic.PickProp(prop); });
  69. }
  70. std::future<bool> TrickerAPI::UseProp(THUAI6::PropType prop)
  71. {
  72. return std::async(std::launch::async, [=]()
  73. { return logic.UseProp(prop); });
  74. }
  75. std::future<bool> StudentAPI::ThrowProp(THUAI6::PropType prop)
  76. {
  77. return std::async(std::launch::async, [=]()
  78. { return logic.ThrowProp(prop); });
  79. }
  80. std::future<bool> TrickerAPI::ThrowProp(THUAI6::PropType prop)
  81. {
  82. return std::async(std::launch::async, [=]()
  83. { return logic.ThrowProp(prop); });
  84. }
  85. std::future<bool> StudentAPI::UseSkill(int32_t skillID)
  86. {
  87. return std::async(std::launch::async, [=]()
  88. { return logic.UseSkill(skillID); });
  89. }
  90. std::future<bool> TrickerAPI::UseSkill(int32_t skillID)
  91. {
  92. return std::async(std::launch::async, [=]()
  93. { return logic.UseSkill(skillID); });
  94. }
  95. std::future<bool> StudentAPI::OpenDoor()
  96. {
  97. return std::async(std::launch::async, [this]()
  98. { return logic.OpenDoor(); });
  99. }
  100. std::future<bool> TrickerAPI::OpenDoor()
  101. {
  102. return std::async(std::launch::async, [this]()
  103. { return logic.OpenDoor(); });
  104. }
  105. std::future<bool> StudentAPI::CloseDoor()
  106. {
  107. return std::async(std::launch::async, [this]()
  108. { return logic.CloseDoor(); });
  109. }
  110. std::future<bool> TrickerAPI::CloseDoor()
  111. {
  112. return std::async(std::launch::async, [this]()
  113. { return logic.CloseDoor(); });
  114. }
  115. std::future<bool> StudentAPI::SkipWindow()
  116. {
  117. return std::async(std::launch::async, [this]()
  118. { return logic.SkipWindow(); });
  119. }
  120. std::future<bool> TrickerAPI::SkipWindow()
  121. {
  122. return std::async(std::launch::async, [this]()
  123. { return logic.SkipWindow(); });
  124. }
  125. std::future<bool> StudentAPI::StartOpenGate()
  126. {
  127. return std::async(std::launch::async, [this]()
  128. { return logic.StartOpenGate(); });
  129. }
  130. std::future<bool> TrickerAPI::StartOpenGate()
  131. {
  132. return std::async(std::launch::async, [this]()
  133. { return logic.StartOpenGate(); });
  134. }
  135. std::future<bool> StudentAPI::StartOpenChest()
  136. {
  137. return std::async(std::launch::async, [this]()
  138. { return logic.StartOpenChest(); });
  139. }
  140. std::future<bool> TrickerAPI::StartOpenChest()
  141. {
  142. return std::async(std::launch::async, [this]()
  143. { return logic.StartOpenChest(); });
  144. }
  145. std::future<bool> StudentAPI::EndAllAction()
  146. {
  147. return std::async(std::launch::async, [this]()
  148. { return logic.EndAllAction(); });
  149. }
  150. std::future<bool> TrickerAPI::EndAllAction()
  151. {
  152. return std::async(std::launch::async, [this]()
  153. { return logic.EndAllAction(); });
  154. }
  155. std::future<bool> StudentAPI::SendMessage(int64_t toID, std::string message)
  156. {
  157. return std::async(std::launch::async, [=]()
  158. { return logic.SendMessage(toID, message); });
  159. }
  160. std::future<bool> TrickerAPI::SendMessage(int64_t toID, std::string message)
  161. {
  162. return std::async(std::launch::async, [=]()
  163. { return logic.SendMessage(toID, message); });
  164. }
  165. bool StudentAPI::HaveMessage()
  166. {
  167. return logic.HaveMessage();
  168. }
  169. bool TrickerAPI::HaveMessage()
  170. {
  171. return logic.HaveMessage();
  172. }
  173. std::pair<int64_t, std::string> StudentAPI::GetMessage()
  174. {
  175. return logic.GetMessage();
  176. }
  177. std::pair<int64_t, std::string> TrickerAPI::GetMessage()
  178. {
  179. return logic.GetMessage();
  180. }
  181. std::future<bool> StudentAPI::Wait()
  182. {
  183. if (logic.GetCounter() == -1)
  184. return std::async(std::launch::async, [this]()
  185. { return false; });
  186. else
  187. return std::async(std::launch::async, [this]()
  188. { return logic.WaitThread(); });
  189. }
  190. std::future<bool> TrickerAPI::Wait()
  191. {
  192. if (logic.GetCounter() == -1)
  193. return std::async(std::launch::async, [this]()
  194. { return false; });
  195. else
  196. return std::async(std::launch::async, [this]()
  197. { return logic.WaitThread(); });
  198. }
  199. std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentAPI::GetTrickers() const
  200. {
  201. return logic.GetTrickers();
  202. }
  203. std::vector<std::shared_ptr<const THUAI6::Student>> StudentAPI::GetStudents() const
  204. {
  205. return logic.GetStudents();
  206. }
  207. std::vector<std::shared_ptr<const THUAI6::Tricker>> TrickerAPI::GetTrickers() const
  208. {
  209. return logic.GetTrickers();
  210. }
  211. std::vector<std::shared_ptr<const THUAI6::Student>> TrickerAPI::GetStudents() const
  212. {
  213. return logic.GetStudents();
  214. }
  215. std::vector<std::shared_ptr<const THUAI6::Prop>> StudentAPI::GetProps() const
  216. {
  217. return logic.GetProps();
  218. }
  219. std::vector<std::shared_ptr<const THUAI6::Prop>> TrickerAPI::GetProps() const
  220. {
  221. return logic.GetProps();
  222. }
  223. std::vector<std::shared_ptr<const THUAI6::Bullet>> StudentAPI::GetBullets() const
  224. {
  225. return logic.GetBullets();
  226. }
  227. std::vector<std::shared_ptr<const THUAI6::Bullet>> TrickerAPI::GetBullets() const
  228. {
  229. return logic.GetBullets();
  230. }
  231. std::vector<std::vector<THUAI6::PlaceType>> StudentAPI::GetFullMap() const
  232. {
  233. return logic.GetFullMap();
  234. }
  235. THUAI6::PlaceType StudentAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
  236. {
  237. return logic.GetPlaceType(cellX, cellY);
  238. }
  239. THUAI6::PlaceType TrickerAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
  240. {
  241. return logic.GetPlaceType(cellX, cellY);
  242. }
  243. std::vector<std::vector<THUAI6::PlaceType>> TrickerAPI::GetFullMap() const
  244. {
  245. return logic.GetFullMap();
  246. }
  247. bool StudentAPI::IsDoorOpen(int32_t cellX, int32_t cellY) const
  248. {
  249. return logic.IsDoorOpen(cellX, cellY);
  250. }
  251. bool TrickerAPI::IsDoorOpen(int32_t cellX, int32_t cellY) const
  252. {
  253. return logic.IsDoorOpen(cellX, cellY);
  254. }
  255. int32_t StudentAPI::GetClassroomProgress(int32_t cellX, int32_t cellY) const
  256. {
  257. return logic.GetClassroomProgress(cellX, cellY);
  258. }
  259. int32_t TrickerAPI::GetClassroomProgress(int32_t cellX, int32_t cellY) const
  260. {
  261. return logic.GetClassroomProgress(cellX, cellY);
  262. }
  263. int32_t StudentAPI::GetChestProgress(int32_t cellX, int32_t cellY) const
  264. {
  265. return logic.GetChestProgress(cellX, cellY);
  266. }
  267. int32_t TrickerAPI::GetChestProgress(int32_t cellX, int32_t cellY) const
  268. {
  269. return logic.GetChestProgress(cellX, cellY);
  270. }
  271. int32_t StudentAPI::GetGateProgress(int32_t cellX, int32_t cellY) const
  272. {
  273. return logic.GetGateProgress(cellX, cellY);
  274. }
  275. int32_t TrickerAPI::GetGateProgress(int32_t cellX, int32_t cellY) const
  276. {
  277. return logic.GetGateProgress(cellX, cellY);
  278. }
  279. int32_t StudentAPI::GetDoorProgress(int32_t cellX, int32_t cellY) const
  280. {
  281. return logic.GetDoorProgress(cellX, cellY);
  282. }
  283. int32_t TrickerAPI::GetDoorProgress(int32_t cellX, int32_t cellY) const
  284. {
  285. return logic.GetDoorProgress(cellX, cellY);
  286. }
  287. THUAI6::HiddenGateState StudentAPI::GetHiddenGateState(int32_t cellX, int32_t cellY) const
  288. {
  289. return logic.GetHiddenGateState(cellX, cellY);
  290. }
  291. THUAI6::HiddenGateState TrickerAPI::GetHiddenGateState(int32_t cellX, int32_t cellY) const
  292. {
  293. return logic.GetHiddenGateState(cellX, cellY);
  294. }
  295. std::shared_ptr<const THUAI6::GameInfo> StudentAPI::GetGameInfo() const
  296. {
  297. return logic.GetGameInfo();
  298. }
  299. std::shared_ptr<const THUAI6::GameInfo> TrickerAPI::GetGameInfo() const
  300. {
  301. return logic.GetGameInfo();
  302. }
  303. std::vector<int64_t> StudentAPI::GetPlayerGUIDs() const
  304. {
  305. return logic.GetPlayerGUIDs();
  306. }
  307. std::vector<int64_t> TrickerAPI::GetPlayerGUIDs() const
  308. {
  309. return logic.GetPlayerGUIDs();
  310. }
  311. std::future<bool> StudentAPI::StartLearning()
  312. {
  313. return std::async(std::launch::async, [this]()
  314. { return logic.StartLearning(); });
  315. }
  316. std::future<bool> StudentAPI::StartTreatMate(int64_t mateID)
  317. {
  318. return std::async(std::launch::async, [=]()
  319. { return logic.StartTreatMate(mateID); });
  320. }
  321. std::future<bool> StudentAPI::StartRescueMate(int64_t mateID)
  322. {
  323. return std::async(std::launch::async, [=]()
  324. { return logic.StartRescueMate(mateID); });
  325. }
  326. std::future<bool> StudentAPI::Graduate()
  327. {
  328. return std::async(std::launch::async, [this]()
  329. { return logic.Graduate(); });
  330. }
  331. std::shared_ptr<const THUAI6::Student> StudentAPI::GetSelfInfo() const
  332. {
  333. return logic.StudentGetSelfInfo();
  334. }
  335. std::future<bool> TrickerAPI::Attack(double angleInRadian)
  336. {
  337. return std::async(std::launch::async, [=]()
  338. { return logic.Attack(angleInRadian); });
  339. }
  340. std::future<bool> StudentAPI::Attack(double angleInRadian)
  341. {
  342. return std::async(std::launch::async, [=]()
  343. { return logic.Attack(angleInRadian); });
  344. }
  345. std::shared_ptr<const THUAI6::Tricker> TrickerAPI::GetSelfInfo() const
  346. {
  347. return logic.TrickerGetSelfInfo();
  348. }
  349. void StudentAPI::Play(IAI& ai)
  350. {
  351. ai.play(*this);
  352. }
  353. void TrickerAPI::Play(IAI& ai)
  354. {
  355. ai.play(*this);
  356. }