Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. int laps, cpCount;
  2.  
  3. // function that gives a score to the result of simulating moves
  4. float Evaluate(Pod* pods)
  5. {
  6. float score = 0;
  7. for (int p = 0; p < 4; p++)
  8. {
  9.  
  10. int podCpsPassed = pods[p].lap*cpCount + pods[p].target->prev->id;
  11. int owner = p < 2 ? 1 : -1;
  12. //if (owner==1) {
  13. //score += (podCpsPassed * 50000 - dist(pods[p].target->loc, pods[p].loc)); // scoring race completion by all pods, multiplying enemy score by -1
  14. score += (podCpsPassed * 50000 - dist(pods[p].target->loc, pods[p].loc))*owner; // scoring race completion by all pods, multiplying enemy score by -1
  15. //}
  16. }
  17.  
  18. //score += dist(pods[0].loc, pods[1].loc); // our pods love each other. they want to stay together
  19. return score;
  20. }
  21.  
  22. int main()
  23. {
  24. char latestLap='a';
  25. int latestTargetId=-1;
  26. Pod podToStop;
  27.  
  28. cin >> laps >> cpCount;
  29.  
  30. Checkpoint cps[cpCount];
  31.  
  32. for (int i = 0; i < cpCount; i++)
  33. {
  34. cps[i].id = i;
  35. cin >> cps[i].loc;
  36. cps[i].prev = &cps[(i + cpCount - 1) % cpCount];
  37. cps[i].next = &cps[(i + 1) % cpCount];
  38. }
  39.  
  40. Pod pods[4];
  41.  
  42. for (int i = 0; i < 4; i++) {
  43. pods[i].target = &cps[1];
  44. }
  45. for (int i = 2; i <=4; i++) {
  46. pods[i].boostUsed = true;
  47. }
  48.  
  49.  
  50. int podToStop_nextTargetId;// = podToStop.target->next->id;
  51. vec2d podToStop_nextTarget;// = podToStop.target->next->loc;
  52.  
  53. while (1)
  54. {
  55. for (int i = 0; i < 4; i++)
  56. {
  57. int ncp = 0;
  58. cin >> pods[i].loc >> pods[i].vel >> pods[i].view.angle >> ncp;
  59. if (ncp == -1)
  60. {
  61. cout << "0 0 0\n0 0 0\nEnemy is dead!";
  62. exit(0);
  63. }
  64. while (ncp != pods[i].target->id)
  65. pods[i].ValidateCP();
  66.  
  67. if (pods[i].view.angle != -1)
  68. pods[i].view.angle *= toRad;
  69. else pods[i].view.angle = getAbsoluteAngle(cps[1].loc - pods[i].loc);
  70.  
  71. if ((int)pods[i].lap > (int)latestLap && i >= 2) {
  72. if (pods[i].target->id > latestTargetId || pods[i].target->id==0) {
  73. latestTargetId=pods[i].target->id;
  74. latestLap=pods[i].lap;
  75. podToStop=pods[i];
  76. }
  77. } else {
  78. if (i >= 2) {
  79. if (pods[i].target->id > latestTargetId || pods[i].target->id==0) {
  80. latestTargetId=pods[i].target->id;
  81. latestLap=pods[i].lap;
  82. podToStop=pods[i];
  83. }
  84. }
  85. }
  86. if (i >= 2) {
  87. cerr << "Target id: " << pods[i].target->id << endl;
  88. cerr << "Lap: " << (int)pods[i].lap << endl;
  89.  
  90. }
  91. }
  92. cerr << "LatestTargetId: " << latestTargetId << endl;
  93. cerr << "LatestLap: " << (int)latestLap << endl;
  94. cerr << "PodToStop.targetId: " << podToStop.target->id << endl;
  95. cerr << "PodToStop.lap: " << (int)podToStop.lap << endl;
  96.  
  97. GameMove bestMoves[2];
  98. float bestScore = -10000000000;
  99. for (int i = 0; i < 2000; i++)
  100. {
  101. Pod testPods[4];
  102. memcpy(testPods, pods, sizeof(pods));
  103.  
  104. GameMove moves[2];
  105. for (int m = 0; m < 2; m++)
  106. //moves[m] = GameMove(frand(-36 * toRad, 36 * toRad), frand(-100, maxThrust+100));
  107. moves[m] = GameMove(frand(-45 * toRad, 45 * toRad), frand(-50, maxThrust+50));
  108.  
  109. GameMove FirstTurnMoves[2];
  110. memcpy(FirstTurnMoves, moves, sizeof(FirstTurnMoves));
  111.  
  112. for (int turn = 0; turn < 20; turn++)
  113. {
  114. testPods[0].Apply(moves[0]);
  115. testPods[1].Apply(moves[1]);
  116.  
  117. testPods[2].Apply(testPods[2].GetMoveAction(testPods[2].target->loc - testPods[2].vel * 3, 100));
  118. testPods[3].Apply(testPods[3].GetMoveAction(testPods[3].target->loc - testPods[3].vel * 3, 100));
  119.  
  120. play(testPods);
  121.  
  122. for (int m = 0; m < 2; m++)
  123. moves[m] = GameMove(
  124. moves[m].angle + pow(frand(-3, 3), 3)*toRad,
  125. moves[m].thrust + pow(frand(-3, 9), 3)*6
  126. );
  127. }
  128.  
  129. float score = Evaluate(testPods);
  130.  
  131. if (score > bestScore)
  132. {
  133. bestScore = score;
  134. memcpy(bestMoves, FirstTurnMoves, sizeof(FirstTurnMoves));
  135. }
  136. }
  137.  
  138. pods[0].PrintAction(bestMoves[0]);
  139. //pods[1].PrintAction(bestMoves[1]);
  140.  
  141.  
  142. /*if (!podToStop_nextTargetId && podToStop.target->next->id) {
  143. podToStop_nextTargetId = podToStop.target->next->id;
  144. }
  145. if (podToStop_nextTargetId != 0 ) {
  146. if (podToStop_nextTargetId == podToStop_nextTargetId+2) {
  147.  
  148. }
  149. }*/
  150.  
  151. cout << podToStop.target->next->loc << " 100" << endl;
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement