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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. #include "AI.h"
  2. #include "API.h"
  3. #define PI 3.14159265358979323846
  4. int HumanAPI::GetFrameCount() const
  5. {
  6. return logic.GetCounter();
  7. }
  8. int ButcherAPI::GetFrameCount() const
  9. {
  10. return logic.GetCounter();
  11. }
  12. std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
  13. {
  14. return std::async(std::launch::async, [&]()
  15. { return logic.Move(timeInMilliseconds, angleInRadian); });
  16. }
  17. std::future<bool> HumanAPI::MoveDown(int64_t timeInMilliseconds)
  18. {
  19. return Move(timeInMilliseconds, 0);
  20. }
  21. std::future<bool> HumanAPI::MoveRight(int64_t timeInMilliseconds)
  22. {
  23. return Move(timeInMilliseconds, PI * 0.5);
  24. }
  25. std::future<bool> HumanAPI::MoveUp(int64_t timeInMilliseconds)
  26. {
  27. return Move(timeInMilliseconds, PI);
  28. }
  29. std::future<bool> HumanAPI::MoveLeft(int64_t timeInMilliseconds)
  30. {
  31. return Move(timeInMilliseconds, PI * 1.5);
  32. }
  33. std::future<bool> ButcherAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
  34. {
  35. return std::async(std::launch::async, [&]()
  36. { return logic.Move(timeInMilliseconds, angleInRadian); });
  37. }
  38. std::future<bool> ButcherAPI::MoveDown(int64_t timeInMilliseconds)
  39. {
  40. return Move(timeInMilliseconds, 0);
  41. }
  42. std::future<bool> ButcherAPI::MoveRight(int64_t timeInMilliseconds)
  43. {
  44. return Move(timeInMilliseconds, PI * 0.5);
  45. }
  46. std::future<bool> ButcherAPI::MoveUp(int64_t timeInMilliseconds)
  47. {
  48. return Move(timeInMilliseconds, PI);
  49. }
  50. std::future<bool> ButcherAPI::MoveLeft(int64_t timeInMilliseconds)
  51. {
  52. return Move(timeInMilliseconds, PI * 1.5);
  53. }
  54. std::future<bool> HumanAPI::PickProp(THUAI6::PropType prop)
  55. {
  56. return std::async(std::launch::async, [&]()
  57. { return logic.PickProp(prop); });
  58. }
  59. std::future<bool> HumanAPI::UseProp()
  60. {
  61. return std::async(std::launch::async, [&]()
  62. { return logic.UseProp(); });
  63. }
  64. std::future<bool> ButcherAPI::PickProp(THUAI6::PropType prop)
  65. {
  66. return std::async(std::launch::async, [&]()
  67. { return logic.PickProp(prop); });
  68. }
  69. std::future<bool> ButcherAPI::UseProp()
  70. {
  71. return std::async(std::launch::async, [&]()
  72. { return logic.UseProp(); });
  73. }
  74. std::future<bool> HumanAPI::UseSkill()
  75. {
  76. return std::async(std::launch::async, [&]()
  77. { return logic.UseSkill(); });
  78. }
  79. std::future<bool> ButcherAPI::UseSkill()
  80. {
  81. return std::async(std::launch::async, [&]()
  82. { return logic.UseSkill(); });
  83. }
  84. std::future<bool> HumanAPI::SendMessage(int64_t toID, std::string message)
  85. {
  86. return std::async(std::launch::async, [&]()
  87. { return logic.SendMessage(toID, message); });
  88. }
  89. std::future<bool> ButcherAPI::SendMessage(int64_t toID, std::string message)
  90. {
  91. return std::async(std::launch::async, [&]()
  92. { return logic.SendMessage(toID, message); });
  93. }
  94. std::future<bool> HumanAPI::HaveMessage()
  95. {
  96. return std::async(std::launch::async, [&]()
  97. { return logic.HaveMessage(); });
  98. }
  99. std::future<bool> ButcherAPI::HaveMessage()
  100. {
  101. return std::async(std::launch::async, [&]()
  102. { return logic.HaveMessage(); });
  103. }
  104. std::future<std::optional<std::pair<int64_t, std::string>>> HumanAPI::GetMessage()
  105. {
  106. return std::async(std::launch::async, [&]()
  107. { return logic.GetMessage(); });
  108. }
  109. std::future<std::optional<std::pair<int64_t, std::string>>> ButcherAPI::GetMessage()
  110. {
  111. return std::async(std::launch::async, [&]()
  112. { return logic.GetMessage(); });
  113. }
  114. std::future<bool> HumanAPI::Wait()
  115. {
  116. if (logic.GetCounter() == -1)
  117. return std::async(std::launch::async, [&]()
  118. { return false; });
  119. else
  120. return std::async(std::launch::async, [&]()
  121. { return logic.WaitThread(); });
  122. }
  123. std::future<bool> ButcherAPI::Wait()
  124. {
  125. if (logic.GetCounter() == -1)
  126. return std::async(std::launch::async, [&]()
  127. { return false; });
  128. else
  129. return std::async(std::launch::async, [&]()
  130. { return logic.WaitThread(); });
  131. }
  132. std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanAPI::GetButcher() const
  133. {
  134. return logic.GetButchers();
  135. }
  136. std::vector<std::shared_ptr<const THUAI6::Human>> HumanAPI::GetHuman() const
  137. {
  138. return logic.GetHumans();
  139. }
  140. std::vector<std::shared_ptr<const THUAI6::Butcher>> ButcherAPI::GetButcher() const
  141. {
  142. return logic.GetButchers();
  143. }
  144. std::vector<std::shared_ptr<const THUAI6::Human>> ButcherAPI::GetHuman() const
  145. {
  146. return logic.GetHumans();
  147. }
  148. std::vector<std::shared_ptr<const THUAI6::Prop>> HumanAPI::GetProps() const
  149. {
  150. return logic.GetProps();
  151. }
  152. std::vector<std::shared_ptr<const THUAI6::Prop>> ButcherAPI::GetProps() const
  153. {
  154. return logic.GetProps();
  155. }
  156. std::vector<std::vector<THUAI6::PlaceType>> HumanAPI::GetFullMap() const
  157. {
  158. return logic.GetFullMap();
  159. }
  160. THUAI6::PlaceType HumanAPI::GetPlaceType(int32_t CellX, int32_t CellY) const
  161. {
  162. return logic.GetPlaceType(CellX, CellY);
  163. }
  164. THUAI6::PlaceType ButcherAPI::GetPlaceType(int32_t CellX, int32_t CellY) const
  165. {
  166. return logic.GetPlaceType(CellX, CellY);
  167. }
  168. std::vector<std::vector<THUAI6::PlaceType>> ButcherAPI::GetFullMap() const
  169. {
  170. return logic.GetFullMap();
  171. }
  172. const std::vector<int64_t> HumanAPI::GetPlayerGUIDs() const
  173. {
  174. return logic.GetPlayerGUIDs();
  175. }
  176. const std::vector<int64_t> ButcherAPI::GetPlayerGUIDs() const
  177. {
  178. return logic.GetPlayerGUIDs();
  179. }
  180. std::future<bool> HumanAPI::StartFixMachine()
  181. {
  182. return std::async(std::launch::async, [&]()
  183. { return logic.StartFixMachine(); });
  184. }
  185. std::future<bool> HumanAPI::EndFixMachine()
  186. {
  187. return std::async(std::launch::async, [&]()
  188. { return logic.EndFixMachine(); });
  189. }
  190. std::future<bool> HumanAPI::StartSaveHuman()
  191. {
  192. return std::async(std::launch::async, [&]()
  193. { return logic.StartSaveHuman(); });
  194. }
  195. std::future<bool> HumanAPI::EndSaveHuman()
  196. {
  197. return std::async(std::launch::async, [&]()
  198. { return logic.EndSaveHuman(); });
  199. }
  200. std::future<bool> HumanAPI::Escape()
  201. {
  202. return std::async(std::launch::async, [&]()
  203. { return logic.Escape(); });
  204. }
  205. std::shared_ptr<const THUAI6::Human> HumanAPI::GetSelfInfo() const
  206. {
  207. return logic.HumanGetSelfInfo();
  208. }
  209. std::future<bool> ButcherAPI::Attack(double angleInRadian)
  210. {
  211. return std::async(std::launch::async, [&]()
  212. { return logic.Attack(angleInRadian); });
  213. }
  214. std::future<bool> ButcherAPI::CarryHuman()
  215. {
  216. return std::async(std::launch::async, [&]()
  217. { return logic.CarryHuman(); });
  218. }
  219. std::future<bool> ButcherAPI::ReleaseHuman()
  220. {
  221. return std::async(std::launch::async, [&]()
  222. { return logic.ReleaseHuman(); });
  223. }
  224. std::future<bool> ButcherAPI::HangHuman()
  225. {
  226. return std::async(std::launch::async, [&]()
  227. { return logic.HangHuman(); });
  228. }
  229. std::shared_ptr<const THUAI6::Butcher> ButcherAPI::GetSelfInfo() const
  230. {
  231. return logic.ButcherGetSelfInfo();
  232. }
  233. void HumanAPI::Play(IAI& ai)
  234. {
  235. ai.play(*this);
  236. }
  237. void ButcherAPI::Play(IAI& ai)
  238. {
  239. ai.play(*this);
  240. }