Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include "math.h"
  6.  
  7. using namespace std;
  8.  
  9. struct Vector2f
  10. {
  11. Vector2f()
  12. : x(0)
  13. , y(0) {}
  14.  
  15. Vector2f(float anX, float anY)
  16. : x (anX)
  17. , y (anY) {}
  18.  
  19. float x;
  20. float y;
  21.  
  22. // Returns the length of the vector
  23. float Length()
  24. {
  25. return sqrt(x * x + y * y);
  26. }
  27.  
  28. // Normalizes the vector
  29. Vector2f Normalize()
  30. {
  31. Vector2f vector;
  32. float length = this->Length();
  33.  
  34. if(length != 0)
  35. {
  36. vector.x = x/length;
  37. vector.y = y/length;
  38. }
  39.  
  40. return vector;
  41. }
  42. };
  43.  
  44. float Dot(const Vector2f& aFirst, const Vector2f& aSecond)
  45. {
  46. return (aFirst.x * aSecond.x) + (aFirst.y * aSecond.y);
  47. }
  48.  
  49. class Wreck
  50. {
  51. public:
  52. Wreck(int aRadius, Vector2f aPosition, int anId, int aWaterAmount)
  53. : myRadius(aRadius)
  54. , myPosition(aPosition)
  55. , myId(anId)
  56. , myWaterAmount(aWaterAmount) {}
  57.  
  58. const int myRadius;
  59. const Vector2f myPosition;
  60. const int myId;
  61. const int myWaterAmount;
  62. };
  63.  
  64. class Vehicle
  65. {
  66. public:
  67. Vehicle(int aMass, int aRadius, Vector2f aPosition, Vector2f aVelocity, int aType, int aPlayerId)
  68. : myMass(aMass)
  69. , myRadius(aRadius)
  70. , myPosition(aPosition)
  71. , myVelocity(aVelocity)
  72. , myType(aType)
  73. , myPlayerId(aPlayerId) {}
  74.  
  75. const int myMass;
  76. const int myRadius;
  77. const Vector2f myPosition;
  78. const Vector2f myVelocity;
  79. const int myType;
  80. const int myPlayerId;
  81. };
  82.  
  83. class PlayerVehicle
  84. {
  85. public:
  86. PlayerVehicle(int aMass, int aRadius, Vector2f aPosition, Vector2f aVelocity, int aType)
  87. : myMass(aMass)
  88. , myRadius(aRadius)
  89. , myPosition(aPosition)
  90. , myVelocity(aVelocity)
  91. , myType(aType)
  92. , myTargetId(-1) {}
  93.  
  94. void Update(
  95. const vector<Vehicle>& someEnemyVehicles,
  96. const vector<Wreck>& someWrecks,
  97. const vector<Vehicle>& someTankers,
  98. int aIdOnEnemyHighestScore,
  99. int aPlayerRage,
  100. const vector<PlayerVehicle> somePlayerVehicles)
  101. {
  102. Vector2f closestPosition;
  103. int closestLength = 100000;
  104. int closestRadius = 0;
  105. int speed = 300;
  106. Vector2f toClosest;
  107.  
  108. if(myType == 0)
  109. {
  110. //if we have a target, continue towards it. If we cant find our target, find new
  111. int foundTarget = false;
  112. for(int i = 0; i < someWrecks.size(); ++i)
  113. {
  114. const Wreck& wreck = someWrecks[i];
  115. if(wreck.myId == myTargetId)
  116. {
  117. foundTarget = true;
  118. closestPosition = wreck.myPosition;
  119. closestPosition = wreck.myPosition;
  120. closestRadius = wreck.myRadius;
  121. myTargetId = wreck.myId;
  122. }
  123. }
  124.  
  125. if(!foundTarget)
  126. {
  127. myTargetId = -1;
  128. int mostWaterAmount = 0;
  129. for(int i = 0; i < someWrecks.size(); ++i)
  130. {
  131. const Wreck& wreck = someWrecks[i];
  132. Vector2f toThis(wreck.myPosition.x - myPosition.x, wreck.myPosition.y - myPosition.y);
  133. const int lengthToThis = toThis.Length();
  134. //if(wreck.myWaterAmount > mostWaterAmount)
  135. if(lengthToThis < closestLength)
  136. {
  137. closestLength = lengthToThis;
  138. closestPosition = wreck.myPosition;
  139. closestRadius = wreck.myRadius;
  140. toClosest = toThis;
  141. myTargetId = wreck.myId;
  142. mostWaterAmount = wreck.myWaterAmount;
  143. }
  144. }
  145.  
  146. //if(someWrecks.size() == 0)
  147. //{
  148. // const PlayerVehicle& destroyer = somePlayerVehicles[1];
  149. // closestPosition = destroyer.myPosition;
  150. //}
  151. }
  152.  
  153. //cerr << "Closest Position: " << closestPosition.x << " " << closestPosition.y << endl;
  154. //cerr << "Length To Closest: " << closestLength << endl;
  155. //cerr << "Velocity Length: " << myVelocity.Length() << endl;
  156.  
  157. Vector2f targetPosition = closestPosition;
  158. targetPosition.x = int(targetPosition.x - (myVelocity.x * 1.5f));
  159. targetPosition.y = int(targetPosition.y - (myVelocity.y * 1.5f));
  160.  
  161. cout << targetPosition.x << " " << targetPosition.y << " " << speed << endl;
  162. }
  163. else if(myType == 1) //destroyer
  164. {
  165. for(int i = 0; i < someTankers.size(); ++i)
  166. {
  167. const Vehicle& tanker = someTankers[i];
  168.  
  169. Vector2f fromMiddle(tanker.myPosition.x - 0, tanker.myPosition.y - 0);
  170. if(fromMiddle.Length() > 6000)
  171. continue;
  172.  
  173. Vector2f toThis(tanker.myPosition.x - myPosition.x, tanker.myPosition.y - myPosition.y);
  174. const int lengthToThis = toThis.Length();
  175. if(lengthToThis < closestLength)
  176. {
  177. closestLength = lengthToThis;
  178. closestPosition = tanker.myPosition;
  179. closestRadius = tanker.myRadius;
  180. }
  181. }
  182.  
  183. bool shouldGrenade = false;
  184. //if(someTankers.size() == 0)
  185. {
  186. for(int i = 0; i < someEnemyVehicles.size(); ++i)
  187. {
  188. const Vehicle& enemy = someEnemyVehicles[i];
  189.  
  190. if(enemy.myType != 0)
  191. continue;
  192.  
  193. if(enemy.myPlayerId != aIdOnEnemyHighestScore)
  194. continue;
  195.  
  196. Vector2f toThis(enemy.myPosition.x - myPosition.x, enemy.myPosition.y - myPosition.y);
  197. const int lengthToThis = toThis.Length();
  198. if(lengthToThis < 2000)
  199. {
  200. closestPosition = enemy.myPosition;
  201. shouldGrenade = true;
  202. }
  203. }
  204. }
  205.  
  206. if(shouldGrenade && aPlayerRage >= 60)
  207. cout << "SKILL " << closestPosition.x << " " << closestPosition.y << endl;
  208. else
  209. cout << closestPosition.x << " " << closestPosition.y << " " << speed << endl;
  210.  
  211. }
  212. else if(myType == 2)
  213. {
  214. cerr << "amount of enemies for Doof:" << someEnemyVehicles.size() << endl;
  215. for(int i = 0; i < someEnemyVehicles.size(); ++i)
  216. {
  217. const Vehicle& enemy = someEnemyVehicles[i];
  218.  
  219. if(enemy.myType != 0)
  220. continue;
  221.  
  222. if(enemy.myPlayerId != aIdOnEnemyHighestScore)
  223. continue;
  224.  
  225. Vector2f toThis(enemy.myPosition.x - myPosition.x, enemy.myPosition.y - myPosition.y);
  226. const int lengthToThis = toThis.Length();
  227. if(lengthToThis < closestLength)
  228. {
  229. closestLength = lengthToThis;
  230. closestPosition = enemy.myPosition;
  231. closestRadius = enemy.myRadius;
  232. }
  233. }
  234.  
  235. cout << closestPosition.x << " " << closestPosition.y << " " << speed << endl;
  236. }
  237.  
  238. //cerr << "Closest Position: " << closestPosition.x << " " << closestPosition.y << endl;
  239. //cerr << "Length To Closest: " << closestLength << endl;
  240. //cerr << "Closest radius: " << closestRadius << endl;
  241. //cerr << "Player Radius: " << myRadius << endl;
  242. //cerr << "Velocity Length: " << myVelocity.Length() << endl;
  243. }
  244.  
  245. int myTargetId;
  246.  
  247. int myMass;
  248. int myRadius;
  249. Vector2f myPosition;
  250. Vector2f myVelocity;
  251. int myType;
  252. };
  253.  
  254. int main()
  255. {
  256. vector<PlayerVehicle> playerVehicles;
  257. vector<Vehicle> enemyVehicles;
  258.  
  259. vector<Vehicle> tankers;
  260. vector<Wreck> wrecks;
  261.  
  262. int isFirstFrame = true;
  263.  
  264. while (1)
  265. {
  266. int myScore;
  267. cin >> myScore; cin.ignore();
  268.  
  269. int enemyScore1;
  270. cin >> enemyScore1; cin.ignore();
  271. int enemyScore2;
  272. cin >> enemyScore2; cin.ignore();
  273.  
  274. int myRage;
  275. cin >> myRage; cin.ignore();
  276.  
  277. int enemyRage1;
  278. cin >> enemyRage1; cin.ignore();
  279. int enemyRage2;
  280. cin >> enemyRage2; cin.ignore();
  281.  
  282. int unitCount;
  283. cin >> unitCount; cin.ignore();
  284.  
  285. const int idOnHighestEnemyScore = enemyScore1 > enemyScore2 ? 1 : 2;
  286. for (int i = 0; i < unitCount; i++)
  287. {
  288. int unitId;
  289. int unitType;
  290. int player;
  291. float mass;
  292. int radius;
  293. Vector2f position;
  294. Vector2f velocity;
  295. int extra;
  296. int extra2;
  297. cin >> unitId >> unitType >> player >> mass >> radius >> position.x >> position.y >> velocity.x >> velocity.y >> extra >> extra2; cin.ignore();
  298.  
  299. if(unitType <= 2)
  300. {
  301. if(player == 0)
  302. {
  303. if(isFirstFrame)
  304. {
  305. PlayerVehicle vehicle(mass, radius, position, velocity, unitType);
  306. playerVehicles.push_back(vehicle);
  307. }
  308. else
  309. {
  310. PlayerVehicle& vehicle = playerVehicles[unitId];
  311. vehicle.myMass = mass;
  312. vehicle.myRadius = radius;
  313. vehicle.myPosition = position;
  314. vehicle.myVelocity = velocity;
  315. }
  316. }
  317. else
  318. {
  319. Vehicle vehicle(mass, radius, position, velocity, unitType, player);
  320. enemyVehicles.push_back(vehicle);
  321.  
  322. cerr << "enemy id: " << unitId << " type: " << unitType << " mass: " << mass << " radius: " << radius << " position: " << position.x << " " << position.y << endl;
  323. }
  324. }
  325. else if(unitType == 3)
  326. {
  327. Vehicle tanker(mass, radius, position, velocity, unitType, -1);
  328. tankers.push_back(tanker);
  329. }
  330. else if(unitType == 4)
  331. {
  332. Wreck wreck(radius, position, unitId, extra);
  333. wrecks.push_back(wreck);
  334. }
  335. }
  336.  
  337. for(int j = 0; j < enemyVehicles.size(); ++j)
  338. cerr << enemyVehicles[j].myType << endl;
  339.  
  340. for(int i = 0; i < playerVehicles.size(); ++i)
  341. playerVehicles[i].Update(enemyVehicles, wrecks, tankers, idOnHighestEnemyScore, myRage, playerVehicles);
  342.  
  343. //playerVehicles.clear();
  344. enemyVehicles.clear();
  345. tankers.clear();
  346. wrecks.clear();
  347.  
  348. if(isFirstFrame)
  349. isFirstFrame = false;
  350. }
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement