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

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