Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.16 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text;
  4. using Pirates;
  5. namespace MyBot
  6. {
  7. public class TutorialBot : Pirates.IPirateBot
  8. {
  9. public int abs(int num)
  10. {
  11. if (num < 0)
  12. {
  13. num = num * -1;
  14. }
  15. return num;
  16. }
  17. public void radarattack(Pirate a, PirateGame game)
  18. {
  19. foreach (Aircraft b in game.GetEnemyLivingAircrafts())
  20. {
  21. if (b.Location.Col >= 2 && b.Location.Col <= 15 && b.Location.Row >= 15 && b.Location.Row <= 31)
  22. {
  23. if (doyouhaveatarget(a, game) != null)
  24. {
  25. attack(game, a, doyouhaveatarget(a, game));
  26. }
  27. else
  28. {
  29. Location loc = game.GetSailOptions(a, b)[0];
  30. if (a.GetLocation() != loc)
  31. {
  32. game.SetSail(a, loc);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. public void handleDrones(List<Drone> d, PirateGame game)
  39. {
  40. int mapX = game.GetColCount() - 1;
  41. int mapY = game.GetRowCount() - 1;
  42. City myCity = game.GetMyCities()[0];
  43. Location myLoc = myCity.Location;
  44. game.Debug(myLoc);
  45. int cityX = myLoc.Col; // X
  46. int cityY = myLoc.Row; // Y
  47. bool rahok = false;
  48. foreach (Drone dro in d)
  49. {
  50. if (dro.Location.Col != 0 && dro.Location.Row != 0 && dro.Location.Col != mapX && dro.Location.Row != cityY)
  51. {
  52. // LEVEL 1
  53. if (abs(cityX - mapX) < cityX)
  54. {
  55. // Rahok
  56. Location loc = new Location(dro.Location.Row, mapX);
  57. game.Debug(loc);
  58. game.SetSail(dro, game.GetSailOptions(dro, loc)[0]);
  59. }
  60. else
  61. {
  62. //Karov
  63. Location loc = new Location(dro.Location.Col, 0);
  64. game.Debug(loc);
  65. game.SetSail(dro, game.GetSailOptions(dro, loc)[0]);
  66. }
  67. }
  68. else if (dro.Location.Row == cityY)
  69. {
  70. // LEVEL 3 OVERRIDE
  71. game.Debug("BLA BLA");
  72. game.Debug(game.GetSailOptions(dro, new Location(cityY, dro.Location.Col))[0]);
  73. game.SetSail(dro, game.GetSailOptions(dro, new Location(dro.Location.Row, cityX))[0]);
  74. }
  75. else if ((dro.Location.Col == mapX || dro.Location.Col == 0) && dro.Location.Row != cityY)
  76. {
  77. // LEVEL 2
  78. game.Debug("ahaln ma nishma");
  79. Location loc = new Location(cityY, dro.Location.Col);
  80. game.SetSail(dro, game.GetSailOptions(dro, loc)[0]);
  81. }
  82. else
  83. {
  84. // LEVEL 3
  85. game.Debug("HEY");
  86. game.Debug(game.GetSailOptions(dro, new Location(cityY, dro.Location.Col))[0]);
  87. game.SetSail(dro, game.GetSailOptions(dro, new Location(dro.Location.Row, cityX))[0]);
  88. }
  89.  
  90. }
  91. }
  92. public int howmuchenemypiratesinthisisland(PirateGame game, Island a)
  93. {
  94. int count = 0;
  95. foreach (Pirate pirate in game.GetEnemyLivingPirates())
  96. {
  97. if (a.InControlRange(pirate))
  98. {
  99. count++;
  100. }
  101. }
  102. return count;
  103. }
  104. public void attack(PirateGame game, Pirate a, Aircraft enemy)
  105. {
  106. if (enemy.CurrentHealth > 0)
  107. game.Attack(a, enemy);
  108. }
  109. public Aircraft doyouhaveatarget(Pirate a, PirateGame game)
  110. {
  111. foreach (Aircraft enemy in game.GetEnemyLivingAircrafts())
  112. {
  113. if (a.InAttackRange(enemy))
  114. return enemy;
  115. }
  116. return null;
  117. }
  118. public Island fromwhichisland(Drone a, PirateGame game) // from which island do the drone start from?
  119. {
  120. foreach (Island b in game.GetAllIslands())
  121. {
  122. if (a.Distance(b) <= 3)
  123. {
  124. return b;
  125. }
  126. }
  127. return null;
  128. }
  129. public void DoTurn(PirateGame game)
  130. {
  131. foreach (Pirate pirate in game.GetMyLivingPirates())
  132. {
  133. City city = game.GetMyCities()[0]; // my city
  134. City city2 = game.GetEnemyCities()[0];//his cisy
  135. if (pirate.Id == 0) //coming to his city and attacking
  136. {
  137. Location loc = new Location(city2.GetLocation().Row - 2, city2.GetLocation().Col + 4);
  138. List<Location> sailOptions = game.GetSailOptions(pirate, loc);
  139. if (pirate.GetLocation() != sailOptions[0])
  140. {
  141. game.SetSail(pirate, sailOptions[0]);
  142. }
  143. radarattack(pirate, game);
  144. }
  145. else if (pirate.Id == 1) // coming to his city and attacking
  146. {
  147. Location loc = new Location(city2.GetLocation().Row + 3, city2.GetLocation().Col + 4);
  148. List<Location> sailOptions = game.GetSailOptions(pirate, loc);
  149. if (pirate.GetLocation() != sailOptions[0])
  150. {
  151. game.SetSail(pirate, sailOptions[0]);
  152. }
  153. radarattack(pirate, game);
  154. }
  155. // else if (pirate.Id == 2) // coming to my city and attacking
  156. // {
  157. // Location loc = new Location(city.GetLocation().Row, city.GetLocation().Col - 4);
  158. // List<Location> sailOptions = game.GetSailOptions(pirate, loc);
  159. // game.SetSail(pirate, sailOptions[0]);
  160. // foreach (Aircraft enemy in game.GetEnemyLivingAircrafts())
  161. // {
  162. // if (pirate.InAttackRange(enemy))
  163. // {
  164. // game.Attack(pirate, enemy);
  165. // game.Debug("pirate " + pirate + " attacks " + enemy);
  166. // }
  167. // }
  168. // }
  169. else if (pirate.Id == 3 || pirate.Id == 4 || pirate.Id == 2) // getting to the closest island, then attacking
  170. {
  171. Island closest = game.GetAllIslands()[0];
  172. int min = 999999999;
  173. List<Island> destinations = game.GetAllIslands();
  174. foreach (Island a in destinations)
  175. {
  176. if (pirate.Distance(a) < min && howmuchenemypiratesinthisisland(game, a) < 3 && a.Owner != game.GetMyself())
  177. {
  178. min = pirate.Distance(a);
  179. closest = a;
  180. }
  181. }
  182. List<Location> sailOptions = game.GetSailOptions(pirate, closest);
  183. if (doyouhaveatarget(pirate, game) != null)
  184. {
  185. attack(game, pirate, doyouhaveatarget(pirate, game));
  186. }
  187. else
  188. {
  189. if (pirate.GetLocation() != sailOptions[0])
  190. {
  191. game.SetSail(pirate, sailOptions[0]);
  192. }
  193. }
  194. }
  195. } // giant foreach
  196. handleDrones(game.GetMyLivingDrones(),game);
  197.  
  198. }//doturn
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement