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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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::SendMessage(int64_t toID, std::string message)
  159. {
  160. return std::async(std::launch::async, [=]()
  161. { return logic.SendMessage(toID, message); });
  162. }
  163. std::future<bool> TrickerAPI::SendMessage(int64_t toID, std::string message)
  164. {
  165. return std::async(std::launch::async, [=]()
  166. { return logic.SendMessage(toID, message); });
  167. }
  168. bool StudentAPI::HaveMessage()
  169. {
  170. return logic.HaveMessage();
  171. }
  172. bool TrickerAPI::HaveMessage()
  173. {
  174. return logic.HaveMessage();
  175. }
  176. std::pair<int64_t, std::string> StudentAPI::GetMessage()
  177. {
  178. return logic.GetMessage();
  179. }
  180. std::pair<int64_t, std::string> TrickerAPI::GetMessage()
  181. {
  182. return logic.GetMessage();
  183. }
  184. bool StudentAPI::Wait()
  185. {
  186. if (logic.GetCounter() == -1)
  187. return false;
  188. else
  189. return logic.WaitThread();
  190. }
  191. bool TrickerAPI::Wait()
  192. {
  193. if (logic.GetCounter() == -1)
  194. return false;
  195. else
  196. return logic.WaitThread();
  197. }
  198. std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentAPI::GetTrickers() const
  199. {
  200. return logic.GetTrickers();
  201. }
  202. std::vector<std::shared_ptr<const THUAI6::Student>> StudentAPI::GetStudents() const
  203. {
  204. return logic.GetStudents();
  205. }
  206. std::vector<std::shared_ptr<const THUAI6::Tricker>> TrickerAPI::GetTrickers() const
  207. {
  208. return logic.GetTrickers();
  209. }
  210. std::vector<std::shared_ptr<const THUAI6::Student>> TrickerAPI::GetStudents() const
  211. {
  212. return logic.GetStudents();
  213. }
  214. std::vector<std::shared_ptr<const THUAI6::Prop>> StudentAPI::GetProps() const
  215. {
  216. return logic.GetProps();
  217. }
  218. std::vector<std::shared_ptr<const THUAI6::Prop>> TrickerAPI::GetProps() const
  219. {
  220. return logic.GetProps();
  221. }
  222. std::vector<std::shared_ptr<const THUAI6::Bullet>> StudentAPI::GetBullets() const
  223. {
  224. return logic.GetBullets();
  225. }
  226. std::vector<std::shared_ptr<const THUAI6::Bullet>> TrickerAPI::GetBullets() const
  227. {
  228. return logic.GetBullets();
  229. }
  230. std::vector<std::vector<THUAI6::PlaceType>> StudentAPI::GetFullMap() const
  231. {
  232. return logic.GetFullMap();
  233. }
  234. THUAI6::PlaceType StudentAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
  235. {
  236. return logic.GetPlaceType(cellX, cellY);
  237. }
  238. THUAI6::PlaceType TrickerAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
  239. {
  240. return logic.GetPlaceType(cellX, cellY);
  241. }
  242. std::vector<std::vector<THUAI6::PlaceType>> TrickerAPI::GetFullMap() const
  243. {
  244. return logic.GetFullMap();
  245. }
  246. bool StudentAPI::IsDoorOpen(int32_t cellX, int32_t cellY) const
  247. {
  248. return logic.IsDoorOpen(cellX, cellY);
  249. }
  250. bool TrickerAPI::IsDoorOpen(int32_t cellX, int32_t cellY) const
  251. {
  252. return logic.IsDoorOpen(cellX, cellY);
  253. }
  254. int32_t StudentAPI::GetClassroomProgress(int32_t cellX, int32_t cellY) const
  255. {
  256. return logic.GetClassroomProgress(cellX, cellY);
  257. }
  258. int32_t TrickerAPI::GetClassroomProgress(int32_t cellX, int32_t cellY) const
  259. {
  260. return logic.GetClassroomProgress(cellX, cellY);
  261. }
  262. int32_t StudentAPI::GetChestProgress(int32_t cellX, int32_t cellY) const
  263. {
  264. return logic.GetChestProgress(cellX, cellY);
  265. }
  266. int32_t TrickerAPI::GetChestProgress(int32_t cellX, int32_t cellY) const
  267. {
  268. return logic.GetChestProgress(cellX, cellY);
  269. }
  270. int32_t StudentAPI::GetGateProgress(int32_t cellX, int32_t cellY) const
  271. {
  272. return logic.GetGateProgress(cellX, cellY);
  273. }
  274. int32_t TrickerAPI::GetGateProgress(int32_t cellX, int32_t cellY) const
  275. {
  276. return logic.GetGateProgress(cellX, cellY);
  277. }
  278. int32_t StudentAPI::GetDoorProgress(int32_t cellX, int32_t cellY) const
  279. {
  280. return logic.GetDoorProgress(cellX, cellY);
  281. }
  282. int32_t TrickerAPI::GetDoorProgress(int32_t cellX, int32_t cellY) const
  283. {
  284. return logic.GetDoorProgress(cellX, cellY);
  285. }
  286. THUAI6::HiddenGateState StudentAPI::GetHiddenGateState(int32_t cellX, int32_t cellY) const
  287. {
  288. return logic.GetHiddenGateState(cellX, cellY);
  289. }
  290. THUAI6::HiddenGateState TrickerAPI::GetHiddenGateState(int32_t cellX, int32_t cellY) const
  291. {
  292. return logic.GetHiddenGateState(cellX, cellY);
  293. }
  294. std::shared_ptr<const THUAI6::GameInfo> StudentAPI::GetGameInfo() const
  295. {
  296. return logic.GetGameInfo();
  297. }
  298. std::shared_ptr<const THUAI6::GameInfo> TrickerAPI::GetGameInfo() const
  299. {
  300. return logic.GetGameInfo();
  301. }
  302. std::vector<int64_t> StudentAPI::GetPlayerGUIDs() const
  303. {
  304. return logic.GetPlayerGUIDs();
  305. }
  306. std::vector<int64_t> TrickerAPI::GetPlayerGUIDs() const
  307. {
  308. return logic.GetPlayerGUIDs();
  309. }
  310. std::future<bool> StudentAPI::StartLearning()
  311. {
  312. return std::async(std::launch::async, [this]()
  313. { return logic.StartLearning(); });
  314. }
  315. std::future<bool> StudentAPI::StartEncourageMate(int64_t mateID)
  316. {
  317. return std::async(std::launch::async, [=]()
  318. { return logic.StartEncourageMate(mateID); });
  319. }
  320. std::future<bool> StudentAPI::StartRouseMate(int64_t mateID)
  321. {
  322. return std::async(std::launch::async, [=]()
  323. { return logic.StartRouseMate(mateID); });
  324. }
  325. std::future<bool> StudentAPI::Graduate()
  326. {
  327. return std::async(std::launch::async, [this]()
  328. { return logic.Graduate(); });
  329. }
  330. std::shared_ptr<const THUAI6::Student> StudentAPI::GetSelfInfo() const
  331. {
  332. return logic.StudentGetSelfInfo();
  333. }
  334. std::future<bool> TrickerAPI::Attack(double angleInRadian)
  335. {
  336. return std::async(std::launch::async, [=]()
  337. { return logic.Attack(angleInRadian); });
  338. }
  339. std::future<bool> StudentAPI::Attack(double angleInRadian)
  340. {
  341. return std::async(std::launch::async, [=]()
  342. { return logic.Attack(angleInRadian); });
  343. }
  344. std::shared_ptr<const THUAI6::Tricker> TrickerAPI::GetSelfInfo() const
  345. {
  346. return logic.TrickerGetSelfInfo();
  347. }
  348. bool StudentAPI::HaveView(int gridX, int gridY) const
  349. {
  350. auto selfInfo = GetSelfInfo();
  351. return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange);
  352. }
  353. bool TrickerAPI::HaveView(int gridX, int gridY) const
  354. {
  355. auto selfInfo = GetSelfInfo();
  356. return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange);
  357. }
  358. void StudentAPI::Play(IAI& ai)
  359. {
  360. ai.play(*this);
  361. }
  362. void TrickerAPI::Play(IAI& ai)
  363. {
  364. ai.play(*this);
  365. }