Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.33 KB | None | 0 0
  1. int up_down ;
  2. int left_right ;
  3.  
  4. int shipDistance[MAX_SHIPS];
  5.  
  6. int number_of_friends;
  7. int friendX[MAX_SHIPS];
  8. int friendY[MAX_SHIPS];
  9. int friendHealth[MAX_SHIPS];
  10. int friendFlag[MAX_SHIPS];
  11. int friendDistance[MAX_SHIPS];
  12. int friendType[MAX_SHIPS];
  13.  
  14. int CallumX;
  15. int CallumY;
  16. int JackX;
  17. int JackY;
  18. int ChloeX;
  19. int ChloeY;
  20. int leaderX;
  21. int leaderY;
  22. int Callumhealth;
  23. int Chloehealth;
  24. int Jackhealth;
  25. int callumDistance;
  26. int jackDistance;
  27. int chloeDistance;
  28. int commonX;
  29. int commonY;
  30. int Distance;
  31. bool foundFriends = false;
  32. bool moveFriends = false;
  33.  
  34. int leader;
  35.  
  36. int leftright; //right 1 left 0
  37. int updown; //up 1 down 0
  38.  
  39.  
  40. bool chloeL = false;
  41. bool jackL = false;
  42. bool calumL = false;
  43. bool nicL = false;
  44.  
  45. int counter = 0;
  46. long count = 0;
  47.  
  48. int number_of_enemies;
  49. int enemyX[MAX_SHIPS];
  50. int enemyY[MAX_SHIPS];
  51. int enemyHealth[MAX_SHIPS];
  52. int enemyFlag[MAX_SHIPS];
  53. int enemyDistance[MAX_SHIPS];
  54. int enemyType[MAX_SHIPS];
  55.  
  56.  
  57. //FREINDLY LOCATIONS
  58. bool IsaFriend(int index)
  59. {
  60. bool rc;
  61. rc = false;
  62. if (shipFlag[index] == 18035241) //callum
  63. {
  64. rc = true; // I have just seen my friend 123
  65. }
  66. if (shipFlag[index] == 18006332) //jack
  67. {
  68. rc = true; // I have just seen my friend 123
  69. }
  70. if (shipFlag[index] == 18012950) //Chloe
  71. {
  72. rc = true; // I have just seen my friend 123
  73. }
  74. return rc;
  75. }
  76.  
  77. //cite https://books.google.co.uk/books?id=Sz-Sqvm-hSYC&pg=PA7&lpg=PA7&dq=chase+algorithm+prey+predator&source=bl&ots=vOko5c6MjJ&sig=ACfU3U2KnVfBuICXEb36LpYmq20PdCGhlg&hl=en&sa=X&ved=2ahUKEwiBksHIlengAhW_QRUIHYhsA04Q6AEwA3oECAYQAQ#v=onepage&q=chase%20algorithm%20prey%20predator&f=false
  78. //MOVE TO X Y CORD
  79. void movement(int x, int y)
  80. {
  81. if (Distance < 3) {
  82. }
  83. else {
  84. if (myY == y) {
  85.  
  86. }
  87. else {
  88.  
  89. if (myY > y) {
  90. up_down = MOVE_DOWN * MOVE_FAST;
  91. }
  92. if (myY < y) {
  93. up_down = MOVE_UP * MOVE_FAST;
  94. }
  95.  
  96. }
  97. if (myX == x) {
  98.  
  99. }
  100. else {
  101. if (myX > x) {
  102. left_right = MOVE_LEFT * MOVE_FAST;
  103. }
  104. if (myX < x) {
  105. left_right = MOVE_RIGHT * MOVE_FAST;
  106. }
  107. }
  108. }
  109. }
  110.  
  111. //https://www.geeksforgeeks.org/cpp-program-for-bubble-sort/
  112. /////////////////////////////////////////////////////////////////////////////////////////
  113. void swap(int *xp, int *yp)
  114. {
  115. int temp = *xp;
  116. *xp = *yp;
  117. *yp = temp;
  118. }
  119. //SORTING TEAMS
  120. void bubbleSort(int e[], int s[], int n) {
  121. bool swapped = true;
  122. int j = 0;
  123. int tmp;
  124. while (swapped) {
  125. swapped = false;
  126. j++;
  127. for (int i = 0; i < n - j; i++) {
  128. if (e[i] > e[i + 1]) {
  129. tmp = e[i];
  130. e[i] = e[i + 1];
  131. e[i + 1] = tmp;
  132. tmp = s[i];
  133. s[i] = s[i + 1];
  134. s[i + 1] = tmp;
  135.  
  136. swapped = true;
  137. }
  138. }
  139. }
  140. }
  141. /*
  142.  
  143. ███████╗███████╗███╗ ██╗██████╗ ██╗███╗ ██╗ ██████╗ ███╗ ███╗███████╗███████╗███████╗ █████╗ ██████╗ ███████╗███████╗
  144. ██╔════╝██╔════╝████╗ ██║██╔══██╗██║████╗ ██║██╔════╝ ████╗ ████║██╔════╝██╔════╝██╔════╝██╔══██╗██╔════╝ ██╔════╝██╔════╝
  145. ███████╗█████╗ ██╔██╗ ██║██║ ██║██║██╔██╗ ██║██║ ███╗ ██╔████╔██║█████╗ ███████╗███████╗███████║██║ ███╗█████╗ ███████╗
  146. ╚════██║██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██║ ██║ ██║╚██╔╝██║██╔══╝ ╚════██║╚════██║██╔══██║██║ ██║██╔══╝ ╚════██║
  147. ███████║███████╗██║ ╚████║██████╔╝██║██║ ╚████║╚██████╔╝ ██║ ╚═╝ ██║███████╗███████║███████║██║ ██║╚██████╔╝███████╗███████║
  148. ╚══════╝╚══════╝╚═╝ ╚═══╝╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝
  149.  
  150. */
  151.  
  152. void freindlyMessaging() {
  153. char msg[100];
  154. sprintf_s(msg, "Im at %d %d %d %d %d %d", myX, myY, myHealth,leader,commonX,commonY);
  155.  
  156. if (counter == 0) {
  157. send_message("18035241", "18020971", msg); // send my co-ordinates to Calum
  158. }
  159. else if (counter == 1) {
  160. send_message("18006332", "18020971", msg); // send my co-ordinates to Jack
  161. }
  162. else if (counter == 2) {
  163. send_message("18012950", "18020971", msg); // send my co-ordinates to Chloe
  164. }
  165. counter++;
  166. if (counter == 3) {
  167. counter = 0;
  168. }
  169. }
  170. //MOVING TO THE TEAM
  171. void moveToTeam() {
  172. //commonX = JackX + ChloeX + CallumX + myX;
  173. //commonX = commonX / 4;
  174. //commonY = JackY + ChloeY + CallumY + myY;
  175. //commonY = commonY / 4;
  176.  
  177. commonX = 500;
  178. commonY = 500;
  179.  
  180. Distance = (int)sqrt((double)((commonX - myX)*(commonX - myX) + (commonY - myY)*(commonY - myY)));
  181.  
  182. if (Distance < 3){
  183.  
  184. }
  185. else {
  186. movement(commonX, commonY);
  187. }
  188. //printf("commonX =%d commonY = %d\r",commonX,commonY);
  189.  
  190. }
  191.  
  192. /*
  193.  
  194. ████████╗ █████╗ ██████╗████████╗██╗ ██████╗███████╗
  195. ╚══██╔══╝██╔══██╗██╔════╝╚══██╔══╝██║██╔════╝██╔════╝
  196. ██║ ███████║██║ ██║ ██║██║ ███████╗
  197. ██║ ██╔══██║██║ ██║ ██║██║ ╚════██║
  198. ██║ ██║ ██║╚██████╗ ██║ ██║╚██████╗███████║
  199. ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
  200.  
  201. */
  202. void tactics()
  203. {
  204. //RESSETTING
  205. int i;
  206. count++;
  207.  
  208. left_right = 0;
  209. up_down = 0 ;
  210.  
  211. ////////////////////////////////
  212. // FREINDLY DISTANCES
  213. ///////////////////////////////
  214. callumDistance = (int)sqrt((double)((CallumX - myX)*(CallumX - myX) + (CallumY - myY)*(CallumY - myY)));
  215. jackDistance = (int)sqrt((double)((JackX - myX)*(JackX - myX) + (JackY - myY)*(JackY - myY)));
  216. chloeDistance = (int)sqrt((double)((ChloeX - myX)*(ChloeX -myX) + (ChloeY - myY)*(ChloeY - myY)));
  217.  
  218. //SHIP DETECTION
  219. for (i = 0; i < number_of_ships; i++)
  220. {
  221. shipDistance[i] = (int)sqrt((double)((shipX[i] - shipX[0])*(shipX[i] - shipX[0]) + (shipY[i] - shipY[0])*(shipY[i] - shipY[0])));
  222. }
  223.  
  224. for (i = 0; i < 30; i++)
  225. {
  226. //Detection cancellation
  227. enemyX[i] = 0;
  228. enemyY[i] = 0;
  229. enemyHealth[i] = 0;
  230. enemyFlag[i] = 0;
  231. enemyDistance[i] = 0;
  232. enemyType[i] = 0;
  233.  
  234. }
  235.  
  236. number_of_friends = 0;
  237. number_of_enemies = 0;
  238.  
  239. if (number_of_ships > 1)
  240. {
  241. for (i = 1; i < number_of_ships; i++)
  242. {
  243. //FIND FREINDS AND MARK THEM
  244. if (IsaFriend(i))
  245. {
  246. friendX[number_of_friends] = shipX[i];
  247. friendY[number_of_friends] = shipY[i];
  248. friendHealth[number_of_friends] = shipHealth[i];
  249. friendFlag[number_of_friends] = shipFlag[i];
  250. friendDistance[number_of_friends] = shipDistance[i];
  251. friendType[number_of_friends] = shipType[i];
  252. number_of_friends++;
  253. }
  254. //FIND ENEMYS AND MARK THEM
  255. else
  256. {
  257. enemyX[number_of_enemies] = shipX[i];
  258. enemyY[number_of_enemies] = shipY[i];
  259. enemyHealth[number_of_enemies] = shipHealth[i];
  260. enemyFlag[number_of_enemies] = shipFlag[i];
  261. enemyDistance[number_of_enemies] = shipDistance[i];
  262. enemyType[number_of_enemies] = shipType[i];
  263. number_of_enemies++;
  264. }
  265. }
  266.  
  267.  
  268. }
  269.  
  270. //Kill FREINDS
  271. int f = number_of_friends;
  272. bubbleSort(friendHealth, friendX, f);
  273. bubbleSort(friendHealth, friendY, f);
  274. bubbleSort(friendHealth, friendFlag, f);
  275. bubbleSort(friendHealth, friendType, f);
  276. bubbleSort(friendHealth, friendDistance, f);
  277.  
  278. if (friendHealth[0] < 3) {
  279. fire_at_ship(friendX[0], friendY[0]);
  280. }
  281.  
  282. //FIRE CONTROL
  283. int n = number_of_enemies;
  284. bubbleSort(enemyDistance, enemyX, n);
  285. bubbleSort(enemyDistance, enemyY, n);
  286. bubbleSort(enemyDistance, enemyHealth, n);
  287. bubbleSort(enemyDistance, enemyFlag, n);
  288. bubbleSort(enemyDistance, enemyType, n);
  289.  
  290. if (number_of_enemies > 0)
  291. {
  292. fire_at_ship(enemyX[0], enemyY[0]);
  293. }
  294.  
  295. //FRENDLY MESSAGING
  296. freindlyMessaging();
  297.  
  298. //SHIP MODES
  299. f = number_of_friends;
  300. bubbleSort(friendDistance, friendX, f);
  301. bubbleSort(friendDistance, friendY, f);
  302. bubbleSort(friendDistance, friendFlag, f);
  303. bubbleSort(friendDistance, friendType, f);
  304. bubbleSort(friendDistance, friendHealth, f);
  305.  
  306. //LEADER
  307.  
  308. if (moveFriends == true) {
  309. if (myHealth == 10 && Chloehealth == 10 && Jackhealth == 10 && Callumhealth == 10)
  310. {
  311. leader = 2;
  312. }
  313. else {
  314. if (myHealth > Chloehealth && Jackhealth && Callumhealth) {
  315. leader = 1;
  316. }
  317. else if (Callumhealth > myHealth && Jackhealth && Chloehealth) {
  318. leader = 2;
  319. }
  320. else if (Jackhealth > myHealth && Chloehealth && Callumhealth) {
  321. leader = 3;
  322. }
  323. else if (Chloehealth > myHealth && Jackhealth && Callumhealth) {
  324. leader = 4;
  325. }
  326. }
  327.  
  328. }
  329.  
  330. //FIND FREINDS - AVOID OTHER SHIPS - DONT ENGAGE MULTIPLE SHIPS
  331.  
  332. if (jackDistance < 10 && chloeDistance< 10 && callumDistance < 10) {
  333. moveFriends = true;
  334.  
  335. }
  336.  
  337. if (jackDistance < 30 && chloeDistance < 30 && callumDistance < 30) {
  338. if (moveFriends == true) {
  339.  
  340. //MOVMENT AS A GROUP//
  341. if (leader == 1) {
  342. if (myHealth < 5 || Callumhealth < 5 || Jackhealth < 5 || Chloehealth < 5) {
  343.  
  344. //ROAMING NO ENEMYS
  345. if (number_of_enemies == 0) {
  346. if (myY > 900)
  347. {
  348. up_down = MOVE_DOWN * MOVE_SLOW;
  349. }
  350.  
  351. if (myX < 200)
  352. {
  353. left_right = MOVE_RIGHT * MOVE_SLOW;
  354. }
  355.  
  356. if (myY < 100)
  357. {
  358. up_down = MOVE_UP * MOVE_SLOW;
  359. }
  360.  
  361. if (myX > 800)
  362. {
  363. left_right = MOVE_LEFT * MOVE_SLOW;
  364. }
  365. }
  366. else {
  367. if (myY > 900)
  368. {
  369. up_down = MOVE_DOWN * MOVE_FAST;
  370. }
  371.  
  372. if (myX < 200)
  373. {
  374. left_right = MOVE_RIGHT * MOVE_FAST;
  375. }
  376.  
  377. if (myY < 100)
  378. {
  379. up_down = MOVE_UP * MOVE_FAST;
  380. }
  381.  
  382. if (myX > 800)
  383. {
  384. left_right = MOVE_LEFT * MOVE_FAST;
  385. }
  386. }
  387. //RUN AWAY from nearest enemy
  388. if (number_of_enemies > number_of_friends) {
  389.  
  390. }
  391. //OUTNUMBER ATTACK kill closest enemy
  392. if (number_of_friends > number_of_enemies) {
  393.  
  394. }
  395. //LOW HEALTH
  396. //SHIP TYPES
  397. }
  398. else if (leader == 2) {
  399. movement(CallumX, CallumY);
  400. }
  401. else if (leader == 3) {
  402. movement(JackX, JackY);
  403. }
  404. else if (leader == 4) {
  405. movement(ChloeX, ChloeY);
  406. }
  407. }
  408. }
  409.  
  410. }
  411.  
  412. //TEAM IS UNGROUPED
  413. if (jackDistance > 30 && chloeDistance > 30 && callumDistance > 30) {
  414. moveFriends = false;
  415. moveToTeam();
  416. }
  417.  
  418. //SEND MOVMENT TO SERVER
  419.  
  420. movement(500, 500);
  421.  
  422.  
  423. //running on even grid
  424.  
  425. if (myX % 2 == 0) {
  426. }
  427. else {
  428. left_right = MOVE_LEFT * MOVE_SLOW;
  429. }
  430.  
  431. if (myY % 2 == 0) {
  432. }
  433. else {
  434. up_down = MOVE_DOWN * MOVE_SLOW;
  435. }
  436.  
  437. move_in_direction(left_right, up_down);
  438.  
  439.  
  440. if (moveFriends == false) {
  441. leader = 0;
  442. }
  443.  
  444. //DISPLAY status
  445.  
  446. if ((count % 10) == 0) {
  447. printf("distance to target = %d X= %d Y=%d moveFriends = %d ", Distance, myX, myY, moveFriends);
  448. printf(" \r");
  449. }
  450. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement