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.

player4.cpp 37 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. #include <vector>
  2. #include <thread>
  3. #include <array>
  4. #include "AI.h"
  5. #include "constants.h"
  6. // 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新
  7. extern const bool asynchronous = false;
  8. static int flag = 0;
  9. static int flagg = 0;
  10. static int flaggg = 0;
  11. static int flagggg = 0;
  12. double angle = 0;
  13. static int homework = 0;
  14. int homework_19_6 = 0;
  15. int homework_31_8 = 0;
  16. int homework_23_19 = 0;
  17. int homework_9_30 = 0;
  18. int homework_11_39 = 0;
  19. int homework_20_42 = 0;
  20. int homework_29_27 = 0;
  21. int homework_34_41 = 0;
  22. int homework_41_13 = 0;
  23. int homework_46_33 = 0;
  24. // 选手需要依次将player0到player4的职业在这里定义
  25. extern const std::array<THUAI6::StudentType, 4> studentType = {
  26. THUAI6::StudentType::StraightAStudent,
  27. THUAI6::StudentType::StraightAStudent,
  28. THUAI6::StudentType::StraightAStudent,
  29. THUAI6::StudentType::StraightAStudent };
  30. extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Assassin;
  31. int ArrayLen(int* a)
  32. {
  33. int i = 0;
  34. while (a[i] != 0)
  35. i++;
  36. return i;
  37. }
  38. int* UpLeft(int dx, int dy, int x, int y, IStudentAPI& api) //会返回一串形如101000111的字符(数字应有dx+dy-1位,若不足,则在高位自动补足0)//
  39. { //从左往右每个数字代表一步,0代表向上一步,1代表向左一步//
  40. int a[200] = { 0 }, *c, b[1];
  41. b[0] = 3;
  42. int flag = 0, i = 0;
  43. if (dx == 0)
  44. {
  45. for (int i = 1; i < dy; i++)
  46. {
  47. if (api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - i) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - i) == THUAI6::PlaceType::Window)
  48. {
  49. flag = 1; break;
  50. }
  51. else a[++i]=2;
  52. }
  53. if (flag == 1) return b;
  54. else return a;
  55. }
  56. flag = 0;
  57. if (dy == 0)
  58. {
  59. for (int i = 0; i < dx; i++)
  60. {
  61. if (api.GetPlaceType(api.GridToCell(x) - i, api.GridToCell(y)) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x) - i, api.GridToCell(y)) == THUAI6::PlaceType::Window)
  62. {
  63. flag = 1; break;
  64. }
  65. else a[++i]=1;
  66. }
  67. if (flag == 1) return b;
  68. else return a;
  69. }
  70. if (*(UpLeft(dx, dy - 1, x, y - 1000, api)) != 3 && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - 1) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - 1) != THUAI6::PlaceType::Window)
  71. {
  72. c = UpLeft(dx, dy - 1, x, y - 1000, api);
  73. for (int i = 0; i < ArrayLen(c); i++)
  74. a[i] = c[i];
  75. a[ArrayLen(c)] = 2;
  76. return a;
  77. }
  78. if (*(UpLeft(dx - 1, dy, x - 1000, y, api)) != 3 && api.GetPlaceType(api.GridToCell(x) - 1, api.GridToCell(y)) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x) - 1, api.GridToCell(y)) != THUAI6::PlaceType::Window)
  79. {
  80. c = UpLeft(dx - 1, dy, x - 1000, y, api);
  81. for (int i = 0; i < ArrayLen(c); i++)
  82. a[i] = c[i];
  83. a[ArrayLen(c)] = 1;
  84. return a;
  85. }
  86. else return b;
  87. }
  88. /*
  89. long long UpRight(int dx, int dy, int x, int y, IStudentAPI& api) //会输出一串形如101000111的数字(数字应有dx+dy-1位,若不足,则在高位自动补足0)//
  90. { //从右往左每个数字代表一步,0代表向上一步,1代表向右一步//
  91. int a = 0, flag = 0;
  92. if (dx == 0)
  93. {
  94. for (int i = 1; i < dy; i++)
  95. {
  96. if (api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + i) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + i) == THUAI6::PlaceType::Window)
  97. {
  98. flag = 1; break;
  99. }
  100. else a = a * 10 + 1;
  101. }
  102. if (flag == 1) return 2;
  103. else return a;
  104. }
  105. flag = 0;
  106. if (dy == 0)
  107. {
  108. for (int i = 0; i < dx; i++)
  109. {
  110. if (api.GetPlaceType(api.GridToCell(x) - i, api.GridToCell(y)) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x) - i, api.GridToCell(y)) == THUAI6::PlaceType::Window)
  111. {
  112. flag = 1; break;
  113. }
  114. else a = a * 10 + 0;
  115. }
  116. if (flag == 1) return 2;
  117. else return a;
  118. }
  119. if (UpLeft(dx, dy - 1, x, y + 1000, api) != 2 && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + 1) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + 1) != THUAI6::PlaceType::Window)
  120. {
  121. return 10 * UpLeft(dx, dy - 1, x, y + 1000, api) + 1;
  122. }
  123. if (UpLeft(dx - 1, dy, x - 1000, y, api) != 2 && api.GetPlaceType(api.GridToCell(x) - 1, api.GridToCell(y)) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x) - 1, api.GridToCell(y)) != THUAI6::PlaceType::Window)
  124. {
  125. return 10 * UpLeft(dx - 1, dy, x - 1000, y, api);
  126. }
  127. else return 2;
  128. }
  129. long long DownLeft(int dx, int dy, int x, int y, IStudentAPI& api) //会输出一串形如101000111的数字(数字应有dx+dy-1位,若不足,则在高位自动补足0)//
  130. { //从右往左每个数字代表一步,0代表向下一步,1代表向左一步//
  131. int a = 0, flag = 0;
  132. if (dx == 0)
  133. {
  134. for (int i = 1; i < dy; i++)
  135. {
  136. if (api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - i) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - i) == THUAI6::PlaceType::Window)
  137. {
  138. flag = 1; break;
  139. }
  140. else a = a * 10 + 1;
  141. }
  142. if (flag == 1) return 2;
  143. else return a;
  144. }
  145. flag = 0;
  146. if (dy == 0)
  147. {
  148. for (int i = 0; i < dx; i++)
  149. {
  150. if (api.GetPlaceType(api.GridToCell(x) + i, api.GridToCell(y)) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x) + i, api.GridToCell(y)) == THUAI6::PlaceType::Window)
  151. {
  152. flag = 1; break;
  153. }
  154. else a = a * 10 + 0;
  155. }
  156. if (flag == 1) return 2;
  157. else return a;
  158. }
  159. if (UpLeft(dx, dy - 1, x, y - 1000, api) != 2 && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - 1) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) - 1) != THUAI6::PlaceType::Window)
  160. {
  161. return 10 * UpLeft(dx, dy - 1, x, y - 1000, api) + 1;
  162. }
  163. if (UpLeft(dx - 1, dy, x + 1000, y, api) != 2 && api.GetPlaceType(api.GridToCell(x) + 1, api.GridToCell(y)) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x) + 1, api.GridToCell(y)) != THUAI6::PlaceType::Window)
  164. {
  165. return 10 * UpLeft(dx - 1, dy, x + 1000, y, api);
  166. }
  167. else return 2;
  168. }
  169. long long DownRight(int dx, int dy, int x, int y, IStudentAPI& api) //会输出一串形如101000111的数字(数字应有dx+dy-1位,若不足,则在高位自动补足0)//
  170. { //从右往左每个数字代表一步,0代表向下一步,1代表向右一步//
  171. int a = 0, flag = 0;
  172. if (dx == 0)
  173. {
  174. for (int i = 1; i < dy; i++)
  175. {
  176. if (api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + i) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + i) == THUAI6::PlaceType::Window)
  177. {
  178. flag = 1; break;
  179. }
  180. else a = a * 10 + 1;
  181. }
  182. if (flag == 1) return 2;
  183. else return a;
  184. }
  185. flag = 0;
  186. if (dy == 0)
  187. {
  188. for (int i = 0; i < dx; i++)
  189. {
  190. if (api.GetPlaceType(api.GridToCell(x) + i, api.GridToCell(y)) == THUAI6::PlaceType::Wall || api.GetPlaceType(api.GridToCell(x) + i, api.GridToCell(y)) == THUAI6::PlaceType::Window)
  191. {
  192. flag = 1; break;
  193. }
  194. else a = a * 10 + 0;
  195. }
  196. if (flag == 1) return 2;
  197. else return a;
  198. }
  199. if (UpLeft(dx, dy - 1, x, y + 1000, api) != 2 && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + 1) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x), api.GridToCell(y) + 1) != THUAI6::PlaceType::Window)
  200. {
  201. return 10 * UpLeft(dx, dy - 1, x, y + 1000, api) + 1;
  202. }
  203. if (UpLeft(dx - 1, dy, x + 1000, y, api) != 2 && api.GetPlaceType(api.GridToCell(x) + 1, api.GridToCell(y)) != THUAI6::PlaceType::Wall && api.GetPlaceType(api.GridToCell(x) + 1, api.GridToCell(y)) != THUAI6::PlaceType::Window)
  204. {
  205. return 10 * UpLeft(dx - 1, dy, x + 1000, y, api);
  206. }
  207. else return 2;
  208. }
  209. //可以在AI.cpp内部声明变量与函数
  210. */
  211. void MoveTo(int des_x, int des_y, IStudentAPI& api, double speed, int a)//走到cell坐标为(des_x,des_y)的函数,speed是api每秒移动的速度
  212. {
  213. if (a == 0)
  214. {
  215. auto p = api.GetSelfInfo();
  216. int x_cell = api.GridToCell(p->x);
  217. int y_cell = api.GridToCell(p->y);
  218. int* step;//用于记录走到目的地所需要的步骤
  219. double time_ms = (1000.0 / (speed)) * 1000;
  220. int len = abs((x_cell - des_x)/2) + abs((y_cell - des_y)/2) - 2;
  221. if (x_cell > des_x && y_cell > des_y)
  222. {
  223. step = UpLeft(abs((x_cell - des_x) / 2), abs((y_cell - des_y) / 2), p->x, p->y, api);
  224. //std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms*20)));
  225. while(len>=0)
  226. {
  227. if (step[len] == 1)
  228. {
  229. //std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms)));
  230. api.MoveUp(time_ms);
  231. }
  232. if (step[len] == 2)
  233. {
  234. //std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms)));
  235. api.MoveLeft(time_ms);
  236. }
  237. len--;
  238. }
  239. }
  240. //MoveTo(des_x, des_y, api, 2880,1);
  241. }
  242. else
  243. {
  244. auto p = api.GetSelfInfo();
  245. int x_cell = api.GridToCell(p->x);
  246. int y_cell = api.GridToCell(p->y);
  247. int* step;//用于记录走到目的地所需要的步骤
  248. double time_ms = (1000.0 / (speed)) * 1000;
  249. int len = abs(x_cell - des_x) + abs(y_cell - des_y) - 2;
  250. step = UpLeft(abs(x_cell - des_x), abs(y_cell - des_y), p->x, p->y, api);
  251. if (x_cell > des_x && y_cell > des_y)
  252. {
  253. while (len >= 0)
  254. {
  255. if (step[len] == 1)
  256. {
  257. api.MoveUp(time_ms);
  258. std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms)));
  259. }
  260. if (step[len] == 2)
  261. {
  262. api.MoveLeft(time_ms);
  263. std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms)));
  264. }
  265. len--;
  266. }
  267. }
  268. }
  269. //else if(x_cell > des_x && y_cell < des_y) step = UpRight(abs(x_cell - des_x), abs(y_cell - des_y), x_cell, y_cell,api);
  270. //else if (x_cell < des_x && y_cell > des_y) step = DownLeft(abs(x_cell - des_x), abs(y_cell - des_y), x_cell, y_cell, api);
  271. //else if (x_cell< des_x && y_cell < des_y) step = DownRight(abs(x_cell - des_x), abs(y_cell - des_y), x_cell, y_cell, api);
  272. }
  273. void DoHomework(int a, int b, IStudentAPI& api)//写作业函数,这部分可能会有问题 @@@(需要测试)
  274. {
  275. auto p1 = api.GetSelfInfo();
  276. int x1 = api.GridToCell(p1->x);
  277. int y1 = api.GridToCell(p1->y);
  278. auto judge1 = api.GetPlaceType(x1 - 1, y1);
  279. auto judge2 = api.GetPlaceType(x1 + 1, y1);
  280. auto judge3 = api.GetPlaceType(x1, y1 - 1);
  281. auto judge4 = api.GetPlaceType(x1, y1 + 1);
  282. if (((judge1 == THUAI6::PlaceType::ClassRoom) || (judge2 == THUAI6::PlaceType::ClassRoom) || (judge3 == THUAI6::PlaceType::ClassRoom) || (judge4 == THUAI6::PlaceType::ClassRoom)) && (api.GetClassroomProgress(a, b) < 10000000))
  283. {
  284. api.StartLearning();
  285. }
  286. if (((judge1 == THUAI6::PlaceType::ClassRoom) || (judge2 == THUAI6::PlaceType::ClassRoom) || (judge3 == THUAI6::PlaceType::ClassRoom) || (judge4 == THUAI6::PlaceType::ClassRoom)) && (api.GetClassroomProgress(a, b) >= 10000000))
  287. {
  288. api.EndAllAction();
  289. api.Wait();
  290. }
  291. }
  292. void Opendoor(int a, int b, IStudentAPI& api)//开大门函数,这部分可能会有问题 @@@(需要测试)
  293. {
  294. auto p1 = api.GetSelfInfo();
  295. int x1 = api.GridToCell(p1->x);
  296. int y1 = api.GridToCell(p1->y);
  297. auto judge1 = api.GetPlaceType(x1 - 1, y1);
  298. auto judge2 = api.GetPlaceType(x1 + 1, y1);
  299. auto judge3 = api.GetPlaceType(x1, y1 - 1);
  300. auto judge4 = api.GetPlaceType(x1, y1 + 1);
  301. if (((judge1 == THUAI6::PlaceType::Gate) || (judge2 == THUAI6::PlaceType::Gate) || (judge3 == THUAI6::PlaceType::Gate) || (judge4 == THUAI6::PlaceType::Gate)) && (api.GetGateProgress(a, b) < 18000))
  302. {
  303. api.StartOpenGate();
  304. }
  305. if (((judge1 == THUAI6::PlaceType::ClassRoom) || (judge2 == THUAI6::PlaceType::ClassRoom) || (judge3 == THUAI6::PlaceType::ClassRoom) || (judge4 == THUAI6::PlaceType::ClassRoom)) && (api.GetGateProgress(a, b) >= 18000))
  306. {
  307. api.EndAllAction();
  308. api.Wait();
  309. api.Graduate();
  310. }
  311. }
  312. void GetToTheNearestHomework(IStudentAPI& api)//找到离自己最近的未完成作业并且走到作业
  313. {
  314. auto p1 = api.GetSelfInfo();
  315. int x1 = api.GridToCell(p1->x);
  316. int y1 = api.GridToCell(p1->y);
  317. int distance[10][3];
  318. distance[0][0] = { (1000 * homework_19_6 + abs(x1 - 19) + abs(y1 - 6)) }; distance[0][1] = 19; distance[0][2] = 6;
  319. distance[1][0] = { 1000 * homework_31_8 + abs(x1 - 31) + abs(y1 - 8) }; distance[1][1] = 31; distance[1][2] = 8;
  320. distance[2][0] = { 1000 * homework_23_19 + abs(x1 - 23) + abs(y1 - 19) }; distance[2][1] = 23; distance[2][2] = 19;
  321. distance[3][0] = { 1000 * homework_9_30 + abs(x1 - 9) + abs(y1 - 30) }; distance[3][1] = 9; distance[3][2] = 30;
  322. distance[4][0] = { 1000 * homework_11_39 + abs(x1 - 11) + abs(y1 - 39) }; distance[4][1] = 11; distance[4][2] = 39;
  323. distance[5][0] = { 1000 * homework_20_42 + abs(x1 - 20) + abs(y1 - 42) }; distance[5][1] = 20; distance[5][2] = 42;
  324. distance[6][0] = { 1000 * homework_29_27 + abs(x1 - 29) + abs(y1 - 27) }; distance[6][1] = 29; distance[6][2] = 27;
  325. distance[7][0] = { 1000 * homework_34_41 + abs(x1 - 34) + abs(y1 - 41) }; distance[7][1] = 34; distance[7][2] = 41;
  326. distance[8][0] = { 1000 * homework_41_13 + abs(x1 - 41) + abs(y1 - 13) }; distance[8][1] = 41; distance[8][2] = 13;
  327. distance[9][0] = { 1000 * homework_46_33 + abs(x1 - 46) + abs(y1 - 33) }; distance[9][1] = 46; distance[9][2] = 33;
  328. //这边需要个冒泡排序求出distance[i][0]的最大值 @@@
  329. //移动到(distance[i][1],distance[i][2]) @@@
  330. }
  331. void RunAway(IStudentAPI& api)//逃离监管者函数
  332. {
  333. auto self = api.GetSelfInfo();
  334. int x1 = api.GridToCell(self->x); int y1 = api.GridToCell(self->y);
  335. auto Trick = api.GetTrickers();
  336. int x2 = 0, y2 = 0;
  337. if (!Trick.empty())
  338. {
  339. x2 = Trick[0]->x; y2 = Trick[0]->y;
  340. }
  341. else
  342. {
  343. x2 = x1; y2 = y1;
  344. }
  345. //这边写一个反向逃离Tricker的Move函数进去,前面x1,y1是自己的位置,x2,y2是Tricker的位置,但是极坐标这里我不太熟 @@@
  346. }
  347. void PlayerCarryOut(IStudentAPI& api)
  348. {
  349. auto self = api.GetSelfInfo();
  350. int x = api.GridToCell(self->x); int y = api.GridToCell(self->y);
  351. if (((x <= 17) && (y <= 5)) || ((x <= 10) && (y >= 5) && (y <= 12))) //一号区,去(6,7)看门的情况
  352. {
  353. auto gameinfo = api.GetGameInfo();
  354. if (gameinfo->subjectFinished < 7)//门未达到开启条件
  355. {
  356. GetToTheNearestHomework(api);
  357. }
  358. else//门达到了开启条件
  359. {
  360. if (api.GetGateProgress(6, 7) < 18000)
  361. {
  362. //写一个走到(6,7)的函数 @@@
  363. Opendoor(6, 7, api);
  364. }
  365. else
  366. {
  367. //写一个走到(6,7)的函数 @@@
  368. api.EndAllAction();
  369. api.Graduate();
  370. }
  371. }
  372. }
  373. if ((x <= 6) && (y > 13) && (y <= 26)) //二号区,去开箱,此处还没完成捡道具;
  374. {
  375. //走到(5,16) @@@
  376. if (api.GetChestProgress(5, 16) < 10000000)
  377. {
  378. api.StartOpenChest();
  379. }
  380. else
  381. {
  382. GetToTheNearestHomework(api);
  383. }
  384. }
  385. if ((x > 6) && (x <= 12) && (y > 13) && (y <= 26))//三号区,走到(12,21)翻入3教
  386. {
  387. //走到(12,21) @@@
  388. if (api.GetPlaceType(x + 1, y) == THUAI6::PlaceType::Window)
  389. {
  390. api.SkipWindow();
  391. }
  392. }
  393. if ((x <= 6) && (y >= 27) && (y <= 41))//四号区,翻墙进入五教
  394. {
  395. //走到(5,33) @@@
  396. if (api.GetPlaceType(x + 1, y) == THUAI6::PlaceType::Window)
  397. {
  398. api.SkipWindow();
  399. }
  400. }
  401. if (((x <= 6) && (y >= 42) && (y <= 50)) || ((x >= 7) && (x <= 9) && (y >= 45) && (y <= 50)))//五号区,开箱,问题同二号区
  402. {
  403. //走到(5,46) @@@
  404. if (api.GetChestProgress(5, 46) < 10000000)
  405. {
  406. api.StartOpenChest();
  407. }
  408. else
  409. {
  410. GetToTheNearestHomework(api);
  411. }
  412. }
  413. if (((x >= 13) && (x <= 14) && (y >= 24) && (y <= 35)) || ((x >= 15) && (x <= 19) && (y >= 24) && (y <= 31)) || ((x >= 20) && (x <= 21) && (y >= 21) && (y <= 28)))
  414. //六号区,翻入五教
  415. {
  416. //走到(18,30) @@@
  417. if (api.GetPlaceType(x, y + 1) == THUAI6::PlaceType::Window)
  418. {
  419. api.SkipWindow();
  420. }
  421. }
  422. if (((x >= 22) && (x <= 23) && (y >= 22) && (y <= 29)) || ((x >= 24) && (x <= 27) && (y >= 22) && (y <= 40)))
  423. //七号区,翻到六教
  424. {
  425. //走到(26,35) @@@
  426. if (api.GetPlaceType(x + 1, y) == THUAI6::PlaceType::Window)
  427. {
  428. api.SkipWindow();
  429. }
  430. }
  431. if (((x >= 10) && (x <= 21) && (y >= 47) && (y <= 50)) || ((x >= 22) && (x <= 29) && (y >= 41) && (y <= 50)) || ((x >= 30) && (x <= 38) && (y >= 45) && (y <= 50)))
  432. {
  433. //八号区,走到(29,40)附近
  434. if (api.IsDoorOpen(29, 40) == true)
  435. {
  436. //走到(29,38) @@@
  437. }
  438. else
  439. {
  440. //走到(39,43) @@@
  441. if (api.GetPlaceType(x - 1, y) == THUAI6::PlaceType::Window)
  442. {
  443. api.SkipWindow();
  444. }
  445. }
  446. }
  447. if (((x > 39) && (x <= 43) && (y >= 33) && (y <= 39)) || ((x >= 39) && (x <= 50) && (y >= 40) && (y <= 50)))//第九区,看门(47,46)
  448. {
  449. auto gameinfo = api.GetGameInfo();
  450. if (gameinfo->subjectFinished < 7)//门未达到开启条件
  451. {
  452. GetToTheNearestHomework(api);
  453. }
  454. else//门达到了开启条件
  455. {
  456. if (api.GetGateProgress(47, 46) < 18000)//此处对于GetGateProgress的使用存疑
  457. {
  458. //写一个走到(47,46)的函数 @@@
  459. Opendoor(47, 46, api);
  460. }
  461. else
  462. {
  463. //写一个走到(47,46)的函数 @@@
  464. api.EndAllAction();
  465. api.Graduate();
  466. }
  467. }
  468. }
  469. if (((x >= 28) && (x <= 31) && (y >= 11) && (y <= 21)) || ((x >= 32) && (x <= 33) && (y >= 11) && (y <= 28)) || ((x >= 34) && (x <= 38) && (y >= 9) && (y <= 17)))
  470. //第十区,走到(27,11)翻墙进入三教
  471. {
  472. //走到(28,11) @@@
  473. if (api.GetPlaceType(x - 1, y) == THUAI6::PlaceType::Window)
  474. {
  475. api.SkipWindow();
  476. }
  477. }
  478. if ((x >= 33) && (x <= 39) && (y >= 0) && (y <= 8))//第十一区,走到(38,3)开箱
  479. {
  480. //走到(38,3)附近 @@@
  481. if (api.GetChestProgress(38, 3) < 10000000)
  482. {
  483. api.StartOpenChest();
  484. }
  485. else
  486. {
  487. GetToTheNearestHomework(api);
  488. }
  489. }
  490. if (((x >= 40) && (x <= 43) && (y >= 0) && (y <= 8)) || ((x >= 44) && (x <= 50) && (y >= 0) && (y <= 18)))
  491. //第十二区,翻(42,18)进入三教
  492. {
  493. //走到(43,18) @@@
  494. if (api.GetPlaceType(x - 1, y) == THUAI6::PlaceType::Window)
  495. {
  496. api.SkipWindow();
  497. }
  498. }
  499. if ((x >= 48) && (x <= 50) && (y >= 21) && (y <= 34))//第十三区,翻(47,27)进入三教
  500. {
  501. //走到(48,27) @@@
  502. if (api.GetPlaceType(x - 1, y) == THUAI6::PlaceType::Window)
  503. {
  504. api.SkipWindow();
  505. }
  506. }
  507. if (((x >= 12) && (x <= 17) && (y >= 5) && (y <= 12)) || ((x >= 18) && (x <= 21) && (y >= 0) && (y <= 12)))
  508. //作业一区,到(19,6)做作业
  509. {
  510. //走到(19,6) @@@
  511. if (homework_19_6 == 0)
  512. {
  513. DoHomework(19, 6, api);
  514. if (api.GetClassroomProgress(19, 6) >= 10000000)
  515. {
  516. homework_19_6 = 1;
  517. }
  518. }
  519. else
  520. {
  521. GetToTheNearestHomework(api);
  522. }
  523. }
  524. if (((x >= 22) && (x <= 32) && (y >= 4) && (y <= 10)) || ((x >= 22) && (x <= 27) && (y >= 10) && (y <= 12)))
  525. //作业二区,到(31,8)做作业
  526. {
  527. //走到(31,8) @@@
  528. if (homework_31_8 == 0)
  529. {
  530. DoHomework(31, 8, api);
  531. if (api.GetClassroomProgress(31, 8) >= 10000000)
  532. {
  533. homework_31_8 = 1;
  534. }
  535. }
  536. else
  537. {
  538. GetToTheNearestHomework(api);
  539. }
  540. }
  541. if (((x >= 13) && (x <= 27) && (y >= 13) && (y <= 21)))
  542. //作业三区,到(23,19)做作业
  543. {
  544. //走到(23,19) @@@
  545. if (homework_23_19 == 0)
  546. {
  547. DoHomework(23, 19, api);
  548. if (api.GetClassroomProgress(23, 19) >= 10000000)
  549. {
  550. homework_23_19 = 1;
  551. }
  552. }
  553. else
  554. {
  555. GetToTheNearestHomework(api);
  556. }
  557. }
  558. if (((x >= 7) && (x <= 11) && (y >= 27) && (y <= 35)))
  559. //作业四区,到(9,30)做作业
  560. {
  561. //走到(9,30) @@@
  562. if (homework_9_30 == 0)
  563. {
  564. DoHomework(9, 30, api);
  565. if (api.GetClassroomProgress(9, 30) >= 10000000)
  566. {
  567. homework_9_30 = 1;
  568. }
  569. }
  570. else
  571. {
  572. GetToTheNearestHomework(api);
  573. }
  574. }
  575. if (((x >= 7) && (x <= 15) && (y >= 36) && (y <= 43)) || ((x >= 11) && (x <= 13) && (y >= 44) && (y <= 48)))
  576. //作业五区,到(11,39)做作业
  577. {
  578. //走到(11,39) @@@
  579. if (homework_11_39 == 0)
  580. {
  581. DoHomework(11, 39, api);
  582. if (api.GetClassroomProgress(11, 39) >= 10000000)
  583. {
  584. homework_11_39 = 1;
  585. }
  586. }
  587. else
  588. {
  589. GetToTheNearestHomework(api);
  590. }
  591. }
  592. if (((x >= 16) && (x <= 21) && (y >= 31) && (y <= 44)))
  593. //作业六区,到(20,42)做作业
  594. {
  595. //走到(20,42) @@@
  596. if (homework_20_42 == 0)
  597. {
  598. DoHomework(20, 42, api);
  599. if (api.GetClassroomProgress(20, 42) >= 10000000)
  600. {
  601. homework_20_42 = 1;
  602. }
  603. }
  604. else
  605. {
  606. GetToTheNearestHomework(api);
  607. }
  608. }
  609. if (((x >= 27) && (x <= 31) && (y >= 25) && (y <= 36)))
  610. //作业七区,到(29,27)做作业
  611. {
  612. //走到(29,27) @@@
  613. if (homework_29_27 == 0)
  614. {
  615. DoHomework(29, 27, api);
  616. if (api.GetClassroomProgress(29, 27) >= 10000000)
  617. {
  618. homework_29_27 = 1;
  619. }
  620. }
  621. else
  622. {
  623. GetToTheNearestHomework(api);
  624. }
  625. }
  626. if (((x >= 28) && (x <= 31) && (y >= 37) && (y <= 40)) || ((x >= 32) && (x <= 37) && (y >= 28) && (y <= 44)))
  627. //作业八区,到(34,41)做作业
  628. {
  629. //走到(34,41) @@@
  630. if (homework_34_41 == 0)
  631. {
  632. DoHomework(34, 41, api);
  633. if (api.GetClassroomProgress(34, 41) >= 10000000)
  634. {
  635. homework_34_41 = 1;
  636. }
  637. }
  638. else
  639. {
  640. GetToTheNearestHomework(api);
  641. }
  642. }
  643. if (((x >= 38) && (x <= 42) && (y >= 12) && (y <= 17)) || ((x >= 32) && (x <= 42) && (y >= 18) && (y <= 27)) || ((x >= 43) && (x <= 47) && (y >= 25) && (y <= 27)))
  644. //作业九区,到(41,13)做作业
  645. {
  646. //走到(41,13) @@@
  647. if (homework_41_13 == 0)
  648. {
  649. DoHomework(41, 13, api);
  650. if (api.GetClassroomProgress(41, 13) >= 10000000)
  651. {
  652. homework_41_13 = 1;
  653. }
  654. }
  655. else
  656. {
  657. GetToTheNearestHomework(api);
  658. }
  659. }
  660. if (((x >= 39) && (x <= 43) && (y >= 28) && (y <= 33)) || ((x >= 44) && (x <= 49) && (y >= 28) && (y <= 39)))
  661. //作业十区,到(46,33)做作业
  662. {
  663. //走到(46,33) @@@
  664. if ((homework_46_33 == 0))
  665. {
  666. DoHomework(46, 33, api);
  667. if (api.GetClassroomProgress(46, 33) >= 10000000)
  668. {
  669. homework_46_33 = 1;
  670. }
  671. }
  672. else
  673. {
  674. GetToTheNearestHomework(api);
  675. }
  676. }
  677. }
  678. int pi = 3.1415926;
  679. void AI::play(IStudentAPI& api)
  680. {
  681. /* 防撞墙1.0(仅作记录,插入新的寻路后可删除)
  682. auto p = api.GetSelfInfo();
  683. double x_grid = p->x;
  684. double y_grid = p->y;
  685. double pi_2 = 2 * 3.1415926;
  686. double changeangle = 3.1415926 / 2;
  687. int x_cell_later = x_grid / 1000 + cos(angle);
  688. int y_cell_later = y_grid / 1000 + sin(angle);
  689. if (api.GetPlaceType(x_cell_later, y_cell_later) != THUAI6::PlaceType::Wall)
  690. {
  691. api.Move(1000, angle);
  692. if (api.GetPlaceType(x_cell_later, y_cell_later) == THUAI6::PlaceType::Window)
  693. {
  694. api.SkipWindow();
  695. }
  696. }
  697. else angle = angle + changeangle;*/
  698. /*作业尝试1.0,仅记录,Dohomework函数完成后可删除
  699. auto p1 = api.GetSelfInfo();
  700. if (flag == 0) api.MoveRight(1000);
  701. int x1 = api.GridToCell(p1->x);
  702. int y1 = api.GridToCell(p1->y);
  703. auto judge = api.GetPlaceType(x1 - 1, y1);
  704. if ((judge == THUAI6::PlaceType::ClassRoom) && (api.GetClassroomProgress(23, 19) < 10000000))
  705. {
  706. flag = 1;
  707. api.StartLearning();
  708. }
  709. if ((judge == THUAI6::PlaceType::ClassRoom) && (api.GetClassroomProgress(23, 19) >= 10000000))
  710. {
  711. api.EndAllAction();
  712. api.Wait();
  713. api.MoveLeft(1000);
  714. }
  715. */
  716. // 公共操作
  717. if (this->playerID == 0)
  718. {
  719. if (flag == 0)
  720. {
  721. api.MoveRight(7 * 347.22222222222222);
  722. std::this_thread::sleep_for(std::chrono::milliseconds(347 * 7));
  723. flag = 1;
  724. }
  725. if (flag == 1)
  726. {
  727. api.StartLearning();
  728. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  729. api.MoveLeft(11 * 347.22222222222222);
  730. std::this_thread::sleep_for(std::chrono::milliseconds(12*347));
  731. flag++;
  732. }
  733. if (flag == 2)
  734. {
  735. api.MoveDown(7 * 347.222222222222);
  736. std::this_thread::sleep_for(std::chrono::milliseconds(7 * 347));
  737. api.StartLearning();
  738. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  739. flag++;
  740. }
  741. if (flag == 3)
  742. {
  743. api.MoveUp(11 * 347.222222222222);
  744. std::this_thread::sleep_for(std::chrono::milliseconds(11 * 347));
  745. flag++;
  746. }
  747. if (flag == 4)
  748. {
  749. api.MoveLeft(4 * 347.222222222222);
  750. std::this_thread::sleep_for(std::chrono::milliseconds(4 * 347));
  751. api.StartLearning();
  752. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  753. flag++;
  754. }
  755. if (flag == 5)
  756. {
  757. auto p = api.GetSelfInfo();
  758. double x_grid = p->x;
  759. double y_grid = p->y;
  760. double changeangle = 3.1415926 / 2;
  761. int x_cell_later = x_grid / 1000 + cos(angle);
  762. int y_cell_later = y_grid / 1000 + sin(angle);
  763. if (api.GetPlaceType(x_cell_later, y_cell_later) == THUAI6::PlaceType::Land )//判断下一个方块是不是墙或者是窗户
  764. {
  765. api.Move(1000, angle);
  766. }
  767. else angle = angle + changeangle;//转角90度
  768. }
  769. /* auto Trick = api.GetTrickers();
  770. if (!Trick.empty())//如果周围有Tricker,进行躲避
  771. {
  772. RunAway(api);
  773. }
  774. if (Trick.empty())//如果没有Tricker,调用原策略,分区进行
  775. {
  776. auto gameinfo1 = api.GetGameInfo();
  777. if (gameinfo1->subjectFinished < 7)
  778. {
  779. PlayerCarryOut(api);
  780. }
  781. else
  782. {
  783. //走到门(6,7)或(47,46) @@@(选一个就好)
  784. PlayerCarryOut(api);
  785. }
  786. }*/
  787. }
  788. if (this->playerID == 1)
  789. {
  790. if (flaggg == 0)
  791. {
  792. api.MoveUp(10 * 347);
  793. std::this_thread::sleep_for(std::chrono::milliseconds(3472*2));
  794. api.MoveLeft(4 * 347);
  795. std::this_thread::sleep_for(std::chrono::milliseconds(4 * 347));
  796. flaggg++;
  797. }
  798. if (flaggg == 1)
  799. {
  800. api.SkipWindow();
  801. std::this_thread::sleep_for(std::chrono::milliseconds(3472*3));
  802. flaggg++;
  803. }
  804. if (flaggg == 2)
  805. {
  806. api.MoveDown(7 * 347);
  807. std::this_thread::sleep_for(std::chrono::milliseconds(7 * 347));
  808. flaggg++;
  809. }
  810. if (flaggg == 3)
  811. {
  812. api.StartLearning();
  813. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  814. api.MoveUp(9.5 * 347.2222222222);
  815. std::this_thread::sleep_for(std::chrono::milliseconds(10 * 347));
  816. api.MoveLeft(4 * 347);
  817. std::this_thread::sleep_for(std::chrono::milliseconds(4 * 347));
  818. api.StartLearning();
  819. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  820. flaggg++;
  821. }
  822. if (flaggg == 4)
  823. {
  824. api.MoveUp(2 * 347);
  825. std::this_thread::sleep_for(std::chrono::milliseconds(3 * 347));
  826. api.MoveLeft(7 * 347);
  827. std::this_thread::sleep_for(std::chrono::milliseconds(8 * 347));
  828. api.StartLearning();
  829. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  830. flaggg++;
  831. }
  832. if (flagg == 5)
  833. {
  834. auto p = api.GetSelfInfo();
  835. double x_grid = p->x;
  836. double y_grid = p->y;
  837. double changeangle = 3.1415926 / 2;
  838. int x_cell_later = x_grid / 1000 + cos(angle);
  839. int y_cell_later = y_grid / 1000 + sin(angle);
  840. if (api.GetPlaceType(x_cell_later, y_cell_later) == THUAI6::PlaceType::Land)//判断下一个方块是不是墙或者是窗户
  841. {
  842. api.Move(1000, angle);
  843. }
  844. else angle = angle + changeangle;//转角90度
  845. }
  846. } // 玩家1执行操作
  847. else if (this->playerID == 2)
  848. {
  849. if (flagggg == 0)
  850. {
  851. api.MoveDown(20 * 347.222222222222);
  852. std::this_thread::sleep_for(std::chrono::milliseconds(25 * 347));
  853. api.MoveRight(8 * 347.2222222222);
  854. std::this_thread::sleep_for(std::chrono::milliseconds(8 * 347));
  855. flagggg++;
  856. }
  857. if (flagggg == 1)
  858. {
  859. api.SkipWindow();
  860. std::this_thread::sleep_for(std::chrono::milliseconds(3472 * 2));
  861. api.MoveDown(6 * 347.2222222222);
  862. std::this_thread::sleep_for(std::chrono::milliseconds(8 * 347));
  863. api.MoveRight(14 * 347.2222222222);
  864. std::this_thread::sleep_for(std::chrono::milliseconds(15 * 347));
  865. api.StartLearning();
  866. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  867. api.MoveLeft(5 * 347.2222222222);
  868. std::this_thread::sleep_for(std::chrono::milliseconds(6 * 347));
  869. api.MoveUp(5 * 347.2222222222);
  870. std::this_thread::sleep_for(std::chrono::milliseconds(6 * 347));
  871. api.MoveLeft(14 * 347.2222222222);
  872. std::this_thread::sleep_for(std::chrono::milliseconds(15 * 347));
  873. api.StartLearning();
  874. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  875. flagggg++;
  876. }
  877. if (flagggg == 2)
  878. {
  879. auto p = api.GetSelfInfo();
  880. double x_grid = p->x;
  881. double y_grid = p->y;
  882. double changeangle = 3.1415926 / 2;
  883. int x_cell_later = x_grid / 1000 + cos(angle);
  884. int y_cell_later = y_grid / 1000 + sin(angle);
  885. if (api.GetPlaceType(x_cell_later, y_cell_later) == THUAI6::PlaceType::Land)//判断下一个方块是不是墙或者是窗户
  886. {
  887. api.Move(1000, angle);
  888. }
  889. else angle = angle + changeangle;//转角90度
  890. }
  891. //std::this_thread::sleep_for(std::chrono::milliseconds(10000));
  892. //MoveTo(5, 6, api, 2880, 0);
  893. /*
  894. double dx, dy, aa;
  895. //std::this_thread::sleep_for(std::chrono::milliseconds(810));
  896. dx = x-4000;
  897. dy = y-21000;
  898. ddx = abs(api.GridToCell(dx));
  899. ddy = abs(api.GridToCell(dy));
  900. c= UpLeft(ddx, ddy, x, y, api);
  901. ii = abs(ddx) + abs(ddy) - 2;
  902. while (ii>=0 && c[0] != 3)
  903. {
  904. if (c[ii]==1)
  905. {
  906. api.MoveUp(347.222222);
  907. std::this_thread::sleep_for(std::chrono::milliseconds(347));
  908. }
  909. if (c[ii] == 2)
  910. {
  911. api.MoveLeft(347.222222);
  912. std::this_thread::sleep_for(std::chrono::milliseconds(347));
  913. }
  914. ii--;
  915. }*/
  916. // flag1 = 1;
  917. }
  918. /*long long step;//用于记录走到目的地所需要的步骤
  919. step = UpLeft(x_cell - 10, y_cell - 21, x_cell, y_cell, api);;
  920. double time_ms = (1000.0 / (2880)) * 1000;
  921. int len = x_cell - 10 + y_cell - 21-1;
  922. if (len>0)
  923. {
  924. if (step % 10 == 0)
  925. {
  926. api.MoveUp(time_ms);
  927. std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms)));
  928. }
  929. else
  930. {
  931. api.MoveLeft(time_ms);
  932. std::this_thread::sleep_for(std::chrono::milliseconds(int(time_ms)));
  933. }
  934. step /= 10;
  935. len--;
  936. }*/// 玩家2执行操作
  937. else if (this->playerID == 3)
  938. {
  939. if (flagg == 0)
  940. {
  941. api.Move(3472 * 2, pi / 4.0);
  942. std::this_thread::sleep_for(std::chrono::milliseconds(3472 * 2));
  943. api.StartLearning();
  944. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  945. api.MoveUp(347 * 4.5);
  946. std::this_thread::sleep_for(std::chrono::milliseconds(347 * 5));
  947. flagg++;
  948. }
  949. if (flagg == 1)
  950. {
  951. api.MoveLeft(347 * 30);
  952. std::this_thread::sleep_for(std::chrono::milliseconds(3472 * 3));
  953. api.StartLearning();
  954. std::this_thread::sleep_for(std::chrono::milliseconds(75000));
  955. }
  956. if (flagg == 2)
  957. {
  958. auto p = api.GetSelfInfo();
  959. double x_grid = p->x;
  960. double y_grid = p->y;
  961. double changeangle = 3.1415926 / 2;
  962. int x_cell_later = x_grid / 1000 + cos(angle);
  963. int y_cell_later = y_grid / 1000 + sin(angle);
  964. if (api.GetPlaceType(x_cell_later, y_cell_later) == THUAI6::PlaceType::Land)//判断下一个方块是不是墙或者是窗户
  965. {
  966. api.Move(1000, angle);
  967. }
  968. else angle = angle + changeangle;//转角90度
  969. }
  970. } // 玩家3执行操作
  971. //当然可以写成if (this->playerID == 2||this->playerID == 3)之类的操作
  972. // 公共操作
  973. }
  974. void AI::play(ITrickerAPI& api)
  975. {
  976. auto self = api.GetSelfInfo();
  977. api.PrintSelfInfo();
  978. }