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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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()
  61. {
  62. return std::async(std::launch::async, [&]()
  63. { return logic.UseProp(); });
  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()
  71. {
  72. return std::async(std::launch::async, [&]()
  73. { return logic.UseProp(); });
  74. }
  75. std::future<bool> StudentAPI::UseSkill()
  76. {
  77. return std::async(std::launch::async, [&]()
  78. { return logic.UseSkill(); });
  79. }
  80. std::future<bool> TrickerAPI::UseSkill()
  81. {
  82. return std::async(std::launch::async, [&]()
  83. { return logic.UseSkill(); });
  84. }
  85. std::future<bool> StudentAPI::SendMessage(int64_t toID, std::string message)
  86. {
  87. return std::async(std::launch::async, [&]()
  88. { return logic.SendMessage(toID, message); });
  89. }
  90. std::future<bool> TrickerAPI::SendMessage(int64_t toID, std::string message)
  91. {
  92. return std::async(std::launch::async, [&]()
  93. { return logic.SendMessage(toID, message); });
  94. }
  95. std::future<bool> StudentAPI::HaveMessage()
  96. {
  97. return std::async(std::launch::async, [&]()
  98. { return logic.HaveMessage(); });
  99. }
  100. std::future<bool> TrickerAPI::HaveMessage()
  101. {
  102. return std::async(std::launch::async, [&]()
  103. { return logic.HaveMessage(); });
  104. }
  105. std::future<std::optional<std::pair<int64_t, std::string>>> StudentAPI::GetMessage()
  106. {
  107. return std::async(std::launch::async, [&]()
  108. { return logic.GetMessage(); });
  109. }
  110. std::future<std::optional<std::pair<int64_t, std::string>>> TrickerAPI::GetMessage()
  111. {
  112. return std::async(std::launch::async, [&]()
  113. { return logic.GetMessage(); });
  114. }
  115. std::future<bool> StudentAPI::Wait()
  116. {
  117. if (logic.GetCounter() == -1)
  118. return std::async(std::launch::async, [&]()
  119. { return false; });
  120. else
  121. return std::async(std::launch::async, [&]()
  122. { return logic.WaitThread(); });
  123. }
  124. std::future<bool> TrickerAPI::Wait()
  125. {
  126. if (logic.GetCounter() == -1)
  127. return std::async(std::launch::async, [&]()
  128. { return false; });
  129. else
  130. return std::async(std::launch::async, [&]()
  131. { return logic.WaitThread(); });
  132. }
  133. std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentAPI::GetTrickers() const
  134. {
  135. return logic.GetTrickers();
  136. }
  137. std::vector<std::shared_ptr<const THUAI6::Student>> StudentAPI::GetStudents() const
  138. {
  139. return logic.GetStudents();
  140. }
  141. std::vector<std::shared_ptr<const THUAI6::Tricker>> TrickerAPI::GetTrickers() const
  142. {
  143. return logic.GetTrickers();
  144. }
  145. std::vector<std::shared_ptr<const THUAI6::Student>> TrickerAPI::GetStudents() const
  146. {
  147. return logic.GetStudents();
  148. }
  149. std::vector<std::shared_ptr<const THUAI6::Prop>> StudentAPI::GetProps() const
  150. {
  151. return logic.GetProps();
  152. }
  153. std::vector<std::shared_ptr<const THUAI6::Prop>> TrickerAPI::GetProps() const
  154. {
  155. return logic.GetProps();
  156. }
  157. std::vector<std::vector<THUAI6::PlaceType>> StudentAPI::GetFullMap() const
  158. {
  159. return logic.GetFullMap();
  160. }
  161. THUAI6::PlaceType StudentAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
  162. {
  163. return logic.GetPlaceType(cellX, cellY);
  164. }
  165. THUAI6::PlaceType TrickerAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
  166. {
  167. return logic.GetPlaceType(cellX, cellY);
  168. }
  169. std::vector<std::vector<THUAI6::PlaceType>> TrickerAPI::GetFullMap() const
  170. {
  171. return logic.GetFullMap();
  172. }
  173. const std::vector<int64_t> StudentAPI::GetPlayerGUIDs() const
  174. {
  175. return logic.GetPlayerGUIDs();
  176. }
  177. const std::vector<int64_t> TrickerAPI::GetPlayerGUIDs() const
  178. {
  179. return logic.GetPlayerGUIDs();
  180. }
  181. std::future<bool> StudentAPI::StartLearning()
  182. {
  183. return std::async(std::launch::async, [&]()
  184. { return logic.StartLearning(); });
  185. }
  186. std::future<bool> StudentAPI::EndLearning()
  187. {
  188. return std::async(std::launch::async, [&]()
  189. { return logic.EndLearning(); });
  190. }
  191. std::future<bool> StudentAPI::StartHelpMate()
  192. {
  193. return std::async(std::launch::async, [&]()
  194. { return logic.StartHelpMate(); });
  195. }
  196. std::future<bool> StudentAPI::EndHelpMate()
  197. {
  198. return std::async(std::launch::async, [&]()
  199. { return logic.EndHelpMate(); });
  200. }
  201. std::future<bool> StudentAPI::Graduate()
  202. {
  203. return std::async(std::launch::async, [&]()
  204. { return logic.Graduate(); });
  205. }
  206. std::shared_ptr<const THUAI6::Student> StudentAPI::GetSelfInfo() const
  207. {
  208. return logic.StudentGetSelfInfo();
  209. }
  210. std::future<bool> TrickerAPI::Trick(double angleInRadian)
  211. {
  212. return std::async(std::launch::async, [&]()
  213. { return logic.Trick(angleInRadian); });
  214. }
  215. std::future<bool> TrickerAPI::StartExam()
  216. {
  217. return std::async(std::launch::async, [&]()
  218. { return logic.StartExam(); });
  219. }
  220. std::future<bool> TrickerAPI::EndExam()
  221. {
  222. return std::async(std::launch::async, [&]()
  223. { return logic.EndExam(); });
  224. }
  225. std::future<bool> TrickerAPI::MakeFail()
  226. {
  227. return std::async(std::launch::async, [&]()
  228. { return logic.MakeFail(); });
  229. }
  230. std::shared_ptr<const THUAI6::Tricker> TrickerAPI::GetSelfInfo() const
  231. {
  232. return logic.TrickerGetSelfInfo();
  233. }
  234. void StudentAPI::Play(IAI& ai)
  235. {
  236. ai.play(*this);
  237. }
  238. void TrickerAPI::Play(IAI& ai)
  239. {
  240. ai.play(*this);
  241. }