Advertisement
Guest User

The Accountant, Aveuh

a guest
Oct 16th, 2016
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.82 KB | None | 0 0
  1. #pragma GCC optimize "O3,omit-frame-pointer,inline"
  2. #include <chrono>
  3. #include <iostream>
  4. #include <cmath>
  5. #include <string>
  6. #include <cstring>
  7.  
  8. // Constants
  9. #define WIDTH         16000
  10. #define HEIGHT         9000
  11. #define MAX_DP          100
  12. #define MAX_EN          100
  13. #define EN_VEL          500
  14. #define MY_VEL         1000
  15. #define MIN_DIST       2000 // Death distance
  16. #define MIN_DIST2   4000000 // Same, squared
  17. #define THRESHOLD   4000000
  18. #define INF       337000000 // W*W*H*H
  19.  
  20. // State of a playout
  21. #define STATE_GAME_OVER 0
  22. #define STATE_ONGOING   1
  23. #define STATE_FINISHED  2
  24.  
  25. // AI Mode (useless, was put there in case I wished to use another AI algorithm)
  26. #define AI_MODE_MC 0
  27.  
  28. // Random moves around (0, 0)
  29. #define N_RANDOM 225
  30. const int rand_x[N_RANDOM] = {-10, -80, -151, -222, -292, -363, -434, -504, -575, -646, -717, -787, -858, -929, -1000, -9, -72, -136, -200, -263, -327, -391, -454, -518, -582, -646, -709, -773, -837, -900, -6, -50, -94, -138, -182, -226, -270, -314, -358, -403, -447, -491, -535, -579, -623, -2, -17, -33, -49, -65, -80, -96, -112, -128, -143, -159, -175, -191, -206, -222, 2, 17, 33, 49, 65, 80, 96, 112, 128, 143, 159, 175, 191, 206, 222, 6, 50, 94, 138, 182, 226, 270, 314, 358, 403, 447, 491, 535, 579, 623, 9, 72, 136, 200, 263, 327, 391, 454, 518, 582, 646, 709, 773, 837, 900, 10, 80, 151, 222, 292, 363, 434, 504, 575, 646, 717, 787, 858, 929, 1000, 9, 72, 136, 200, 263, 327, 391, 454, 518, 582, 646, 709, 773, 837, 900, 6, 50, 94, 138, 182, 226, 270, 314, 358, 403, 447, 491, 535, 579, 623, 2, 17, 33, 49, 65, 80, 96, 112, 128, 143, 159, 175, 191, 206, 222, -2, -17, -33, -49, -65, -80, -96, -112, -128, -143, -159, -175, -191, -206, -222, -6, -50, -94, -138, -182, -226, -270, -314, -358, -403, -447, -491, -535, -579, -623, -9, -72, -136, -200, -263, -327, -391, -454, -518, -582, -646, -709, -773, -837, -900, -10, -80, -151, -222, -292, -363, -434, -504, -575, -646, -717, -787, -858, -929, -1000};
  31. const int rand_y[N_RANDOM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, -35, -65, -96, -127, -157, -188, -219, -249, -280, -311, -341, -372, -403, -433, -7, -63, -118, -173, -228, -284, -339, -394, -450, -505, -560, -615, -671, -726, -781, -9, -78, -147, -216, -285, -354, -423, -492, -561, -630, -699, -768, -837, -905, -974, -9, -78, -147, -216, -285, -354, -423, -492, -561, -630, -699, -768, -837, -905, -974, -7, -63, -118, -173, -228, -284, -339, -394, -450, -505, -560, -615, -671, -726, -781, -4, -35, -65, -96, -127, -157, -188, -219, -249, -280, -311, -341, -372, -403, -433, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 35, 65, 96, 127, 157, 188, 219, 249, 280, 311, 341, 372, 403, 433, 7, 63, 118, 173, 228, 284, 339, 394, 450, 505, 560, 615, 671, 726, 781, 9, 78, 147, 216, 285, 354, 423, 492, 561, 630, 699, 768, 837, 905, 974, 9, 78, 147, 216, 285, 354, 423, 492, 561, 630, 699, 768, 837, 905, 974, 7, 63, 118, 173, 228, 284, 339, 394, 450, 505, 560, 615, 671, 726, 781, 4, 35, 65, 96, 127, 157, 188, 219, 249, 280, 311, 341, 372, 403, 433, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  32.  
  33. #define DMG_THRESHOLD 12
  34. // Probabiity to one-shot an enemy
  35. #define PROB_OS        90
  36.  
  37. // Cumulated probabilities for every strategy (sums to 150 ... sorry)
  38. #define PROB_GO_DP     25
  39. #define PROB_GO_EN     50
  40. #define PROB_GO_RD     75
  41. #define PROB_SHOOT    150
  42.  
  43. // Macros
  44. //#define DEBUG
  45. #define min(a, b) (a < b ? a : b)
  46. #define max(a, b) (a > b ? a : b)
  47. #define RAND(x)   ((int)(rand() / (float)RAND_MAX * x))
  48.  
  49. // Timing
  50. using time_point = std::chrono::time_point<std::chrono::system_clock>;
  51. using duration = std::chrono::duration<float>;
  52. #define now std::chrono::system_clock::now
  53. #define TIME_LIMIT 0.096f
  54. #define LARGE_TIME_LIMIT 0.996f
  55.  
  56. // Player actions
  57. #define ACTION_MOVE  0
  58. #define ACTION_SHOOT 1
  59. #define ACTION_NONE  2
  60.  
  61. struct Action {
  62.   int type;   // if type == MOVE, p1 = x, p2 = y; if SHOOT; p1 = id, p2 = unused
  63.   int p1, p2;
  64. };
  65.  
  66. #define SOL_SIZE 200 // Maybe too much ?
  67. struct Solution {
  68.   int nactions;
  69.   int final_state;
  70.   int dist_from_killer;
  71.   Action actions[SOL_SIZE];
  72.   int score;
  73. };
  74.  
  75. // Distances
  76. inline int dist2(int x1, int y1, int x2, int y2) {
  77.   int dx = x1-x2;
  78.   int dy = y1-y2;
  79.   return dx*dx+dy*dy;
  80. }
  81.  
  82. // Moving an entity, /\ x and y are modified
  83. inline void move(int &x, int &y, int tx, int ty, int velocity) {
  84.   int dx = tx - x;
  85.   int dy = ty - y;
  86.  
  87.   if (dx != 0 || dy != 0) {
  88.     float L = sqrt(dx*dx+dy*dy);
  89.  
  90.     if (L < velocity) {
  91.       x = tx;
  92.       y = ty;
  93.     }
  94.     else {
  95.       float d = velocity / L;
  96.       x += dx*d;
  97.       if (x < 0)
  98.     x = 0;
  99.       else if (x >= WIDTH)
  100.     x = WIDTH-1;
  101.  
  102.       y += dy * d;
  103.       if (y < 0)
  104.     y = 0;
  105.       else if (y >= HEIGHT)
  106.     y = HEIGHT-1;
  107.     }
  108.   }
  109. }
  110.  
  111. // On squared distances
  112. inline int damage_dealt(int d2) {
  113.   if (d2 <= 4082821)
  114.     return 14;
  115.   if (d2 <= 4641588)
  116.     return 13;
  117.   if (d2 <= 5333598)
  118.     return 12;
  119.   if (d2 <= 6206801)
  120.     return 11;
  121.   if (d2 <= 7333489)
  122.     return 10;
  123.   if (d2 <= 8827108)
  124.     return 9;
  125.   if (d2 <= 10874632)
  126.     return 8;
  127.   if (d2 <= 13803665)
  128.     return 7;
  129.   if (d2 <= 18235270)
  130.     return 6;
  131.   if (d2 <= 25477833)
  132.     return 5;
  133.   if (d2 <= 38732002)
  134.     return 4;
  135.   if (d2 <= 67860440)
  136.     return 3;
  137.   if (d2 <= 158988089)
  138.     return 2;
  139.   else
  140.     return 1;
  141. }
  142.  
  143. // Game constants
  144. int n_dp;
  145. int n_enemies;
  146. int total_life;
  147. int dp_x[MAX_DP];
  148. int dp_y[MAX_DP];
  149. int ai_mode;
  150. int turn;
  151. Solution current_solution;
  152. int turn_in_sol;
  153. time_point start;
  154. duration elapsed;
  155.  
  156. // Game state
  157. struct State {
  158.   int en_alive;
  159.   int dp_alive;
  160.   int shots;
  161.   int x, y;
  162.   int en_x[MAX_EN];
  163.   int en_y[MAX_EN];
  164.   int en_l[MAX_EN]; // Life
  165.   int en_t[MAX_EN]; // Target DP
  166.   int dp_a[MAX_DP];
  167.   int dist2[MAX_EN];
  168.  
  169.   // Additional info in casae of death
  170.   int killer;           // Which enemy killed us
  171.   int dist_from_killer; // At what distance were we
  172.  
  173.   State() {
  174.     en_alive = 0;
  175.     dp_alive = 0;
  176.     shots = 0;
  177.     x = 0;
  178.     y = 0;
  179.     killer = -1;
  180.   }
  181. };
  182.  
  183. // Gives us a random alive enemy on the map
  184. inline int random_enemy(State &s) {
  185.   int eids[MAX_EN];
  186.   int n_en = 0;
  187.   for (int eid=0; eid < n_enemies; ++eid) {
  188.     if (s.en_l[eid] > 0)
  189.       eids[n_en++] = eid;
  190.   }
  191.   if (n_en == 0)
  192.     return -1;
  193.   return eids[RAND(n_en)];
  194. }
  195.  
  196. // Reading the turn state on stdin
  197. void read_state_from_stdin(State &s, bool first) {
  198.   std::cin >> s.x >> s.y;
  199.  
  200.   // Reset
  201.   memset(s.en_x, 0, MAX_EN*sizeof(int));
  202.   memset(s.en_y, 0, MAX_EN*sizeof(int));
  203.   memset(s.en_l, 0, MAX_EN*sizeof(int));
  204.   memset(s.dp_a, 0, MAX_EN*sizeof(int));
  205.  
  206.   // Data points
  207.   int tmp;
  208.   std::cin >> tmp;
  209.   s.dp_alive = (int8_t)tmp;
  210.   for (int i=0; i < s.dp_alive; ++i) {
  211.     int id, x, y;
  212.     std::cin >> id >> x >> y;
  213.  
  214. #ifdef DEBUG
  215.     std::cerr <<  "Data point #" << id << " at position : " << x << " " << y << std::endl;
  216. #endif
  217.  
  218.     s.dp_a[id] = 1;
  219.     dp_x[id] = x;
  220.     dp_y[id] = y;
  221.   }
  222.  
  223.   if (first)
  224.     n_dp = s.dp_alive;
  225.  
  226.   // Enemies
  227.   int t = 0;
  228.   std::cin >> tmp;
  229.   s.en_alive = (int)tmp;
  230.   for(int i=0; i < s.en_alive; ++i) {
  231.     int id, x, y, life;
  232.     std::cin >> id >> x >> y >> life;
  233.  
  234.     s.en_x[id] = x;
  235.     s.en_y[id] = y;
  236.     s.en_l[id] = life;
  237.  
  238.     // Distance to Wolff
  239.     int d = dist2(s.en_x[id], s.en_y[id], s.x, s.y);
  240.     s.dist2[id] = d;
  241.  
  242.     // Current target
  243.     int best_dist = INF;
  244.     for (int pid=0; pid < n_dp; ++pid) {
  245.       if (s.dp_a[pid]) {
  246.     int d = dist2(dp_x[pid], dp_y[pid], s.en_x[id], s.en_y[id]);
  247.  
  248.     if (d < best_dist) {
  249.       best_dist = d;
  250.       s.en_t[id] = pid;
  251.     }
  252.       }
  253.     }
  254.  
  255. #ifdef DEBUG
  256.     std::cerr <<  "Enemy #" << id << " at position : " << x << " " << y << "; Life left : "
  257.           << life << "; Target = " << s.en_t[id] << std::endl;
  258. #endif
  259.    
  260.     t += life;
  261.   }
  262.  
  263.   // First turn info to store as globals
  264.   if (first) {
  265.     n_enemies = s.en_alive;
  266.     total_life = t;
  267.  
  268. #ifdef DEBUG
  269.     std::cerr << "First turn init :" << std::endl;
  270.     std::cerr << " - " << n_enemies << " enemies" << std::endl;
  271.     std::cerr << " - Cumulating " << total_life << " life" << std::endl;
  272.     std::cerr << " - Trying to capture " << n_dp << " data points " << std::endl;
  273. #endif
  274.  
  275.   }
  276. }
  277.  
  278. // One step evolution of the game state
  279. // Here things have been reorganized to speed up the whole process :
  280. // In particular, Wolff's position is computed BEFORE the enemies.
  281. // This allows us to compute the distance to the enemy in the same loop as their new
  282. // position, and thus detecting Wolff's death much faster in only one loop.
  283. int evolve(State &s, const Action &a, bool check_for_death) {
  284.   // 1- Moving Wolff
  285.   if (a.type == ACTION_MOVE)
  286.     move(s.x, s.y, a.p1, a.p2, MY_VEL);
  287.  
  288.   // 2- Moving enemies + checking for death
  289.   for (int eid=0; eid < n_enemies; ++eid) {
  290.  
  291.     // Alive ?
  292.     if (s.en_l[eid] > 0) {
  293.  
  294.       // No target or target collected ? We find a new one
  295.       int tid;
  296.       if (s.en_t[eid] == -1 || !s.dp_a[s.en_t[eid]]) {
  297.     int best_dist = INF;
  298.     tid = -1;
  299.  
  300.     // Looking for the closest DP
  301.     for (int pid=0; pid < n_dp; ++pid) {
  302.       if (s.dp_a[pid]) {
  303.         int d = dist2(dp_x[pid], dp_y[pid], s.en_x[eid], s.en_y[eid]);
  304.         if (d < best_dist) {
  305.           best_dist = d;
  306.           tid = pid;
  307.         }
  308.       }
  309.     }
  310.     s.en_t[eid] = tid;
  311.       }
  312.       else
  313.     tid = s.en_t[eid];
  314.  
  315.       // Moving the enemy
  316.       move(s.en_x[eid], s.en_y[eid], dp_x[tid], dp_y[tid], EN_VEL);
  317.  
  318.       // Storing the distance, and checking for death
  319.       s.dist2[eid] = dist2(s.en_x[eid], s.en_y[eid], s.x, s.y);
  320.    
  321.       if (check_for_death && s.dist2[eid] <= MIN_DIST2) {
  322.     s.killer = eid;
  323.     s.dist_from_killer = s.dist2[eid];
  324.     return STATE_GAME_OVER;
  325.       }
  326.     }
  327.   }
  328.  
  329.   // 3- Shooting
  330.   if (a.type == ACTION_SHOOT) {
  331.     s.en_l[a.p1] -= damage_dealt(s.dist2[a.p1]);
  332.     s.shots++;
  333.     if (s.en_l[a.p1] <= 0 && --s.en_alive == 0)
  334.       return STATE_FINISHED;
  335.   }            
  336.  
  337.   // 4- DP collection
  338.   for (int eid=0; eid < n_enemies; ++eid) {
  339.     if (s.en_l[eid] > 0) {
  340.       int tid = s.en_t[eid];
  341.       if (s.dp_a[tid] && s.en_x[eid] == dp_x[tid] && s.en_y[eid] == dp_y[tid]) {
  342.     s.dp_a[tid] = false;
  343.     if (--s.dp_alive == 0) {
  344.       return (s.en_alive < n_enemies ? STATE_FINISHED : STATE_GAME_OVER);
  345.     }
  346.       }
  347.     }
  348.   }
  349.  
  350.   return STATE_ONGOING;
  351. }
  352.  
  353. // Score at the end of the game
  354. int game_score(State &s) {
  355.   return s.dp_alive * (100 + max(0, total_life - 3*s.shots) * 3) + 10*(n_enemies - s.en_alive);
  356. }
  357.  
  358. // Util function to output the initial conditions of a case in a C++ fashion
  359. // Used to debug locally
  360. #define IC_OUT(k, v) (std::cerr << k << " = " << v << ";" << std::endl)
  361. void output_ICs(State &s) {
  362.   IC_OUT("n_enemies", n_enemies);
  363.   IC_OUT("n_dp", n_dp);
  364.   IC_OUT("s.dp_alive", s.dp_alive);
  365.   IC_OUT("s.en_alive", s.en_alive);
  366.   IC_OUT("s.x", s.x);
  367.   IC_OUT("s.y", s.y);
  368.   for (int i=0; i < n_enemies; ++i) {
  369.     IC_OUT("s.en_x["+std::to_string(i)+"]", s.en_x[i]);
  370.     IC_OUT("s.en_y["+std::to_string(i)+"]", s.en_y[i]);
  371.     IC_OUT("s.en_l["+std::to_string(i)+"]", s.en_l[i]);
  372.     IC_OUT("s.en_t["+std::to_string(i)+"]", -1);
  373.   }
  374.   for (int i=0; i < n_dp; ++i) {
  375.     IC_OUT("dp_x["+std::to_string(i)+"]", dp_x[i]);
  376.     IC_OUT("dp_y["+std::to_string(i)+"]", dp_y[i]);
  377.     IC_OUT("s.dp_a["+std::to_string(i)+"]", s.dp_a[i]);
  378.   }
  379. }
  380.  
  381. // Comparing two solutions
  382. bool operator>(Solution &s1, Solution &s2) {
  383.   // If same final state
  384.   if (s1.final_state == s2.final_state) {
  385.     // If both finished
  386.     if (s1.final_state == STATE_FINISHED) {
  387.       // If same score, we keep the one that finished early
  388.       if (s1.score == s2.score)
  389.     return s1.nactions < s2.nactions;
  390.       // Otherwise, best score
  391.       else
  392.     return s1.score > s2.score;
  393.     }
  394.     // If both losing solutions
  395.     else {
  396.       // If same number of turns played
  397.       if (s1.nactions == s2.nactions) {
  398.     // We keep the death that is the farthest from the killer
  399.     return s1.dist_from_killer > s2.dist_from_killer;
  400.       }
  401.       // Otherwise we keep the solution that survives the longest
  402.       else
  403.     return s1.nactions > s2.nactions;
  404.     }
  405.   }
  406.   // Different states, we keep the one that is not game over
  407.   else
  408.     return s1.final_state == STATE_FINISHED;
  409. }
  410.  
  411. // Playing the turn, high level function
  412. void play_turn(State &s) {
  413.   // First turn = 1s, rest of the time 100ms
  414.   float time_limit = (turn == 1 ? LARGE_TIME_LIMIT : TIME_LIMIT);
  415.   switch(ai_mode) {
  416.   case AI_MODE_MC: play_mc(s, time_limit); break;
  417.   }
  418. }
  419.  
  420. // Playing a monte carlo move
  421. int play_mc(State &s, float time_limit) {
  422.   start = now();
  423.   bool done = false;
  424.   int ite = 0;
  425.   int nbok = 0;
  426.   Solution sol;
  427.  
  428.   // Looping while we have time
  429.   while (!done) {
  430.     ite++;
  431.  
  432.     // Generating a new solution
  433.     State ns(s);
  434.     generate_random_solution(ns, sol, time_limit);
  435.  
  436.     // Comparing the solution with the best one up until now
  437.     if (sol > current_solution) {
  438.       current_solution = sol;
  439.       turn_in_sol = 0;
  440.     }
  441.  
  442.     // Counting how many solutions survive
  443.     if (sol.final_state == STATE_FINISHED)
  444.       nbok++;
  445.    
  446.     elapsed = now() - start;
  447.     done = elapsed.count() > time_limit;
  448.   }
  449.  
  450.   // Stats/Debug
  451.   std::cerr << "Enemies alive : " << s.en_alive << std::endl;
  452.   std::cerr << "DP alive : " << s.dp_alive << std::endl;
  453.   std::cerr << "MC, score expected : " << current_solution.score << std::endl;
  454.   std::cerr << "MC, state expected : ";
  455.   switch(current_solution.final_state) {
  456.   case STATE_ONGOING: std::cerr << "On going ...... ?!!" << std::endl; break;
  457.   case STATE_GAME_OVER: std::cerr << "Lost !" << std::endl; break;
  458.   case STATE_FINISHED: std::cerr << "Finished !" << std::endl; break;
  459.   }
  460.  
  461.   std::cerr << ite << " solutions ; " << nbok << " solutions that survive" << std::endl;
  462.  
  463.   // Output
  464.   Action best_action = current_solution.actions[turn_in_sol];
  465.   if (best_action.type == ACTION_MOVE)
  466.     std::cout << "MOVE " << best_action.p1 << " " << best_action.p2 << " " << ite << std::endl;
  467.   else {
  468.     std::cout << "SHOOT " << best_action.p1 << " " << ite << std::endl;
  469.     s.shots++;
  470.   }
  471.   turn_in_sol++;
  472.  
  473.   // State after playing
  474.   int res = (turn_in_sol < current_solution.nactions ? STATE_ONGOING : current_solution.final_state);
  475.   return res;
  476. }
  477.  
  478. // The main piece of code : Generating a random solution
  479. void generate_random_solution(State &s, Solution &sol, float time_limit) {
  480.   int state = STATE_ONGOING;
  481.   int t = 0;
  482.   Action a;
  483.  
  484.   // Iterating until the end of the playout
  485.   while (state == STATE_ONGOING) {
  486.  
  487.     // Looking for a viable enemy to one shot
  488.     int best_id      = -1;
  489.     int best_dist    =  INF;
  490.     int best_life    =  0;
  491.     int closest_id   = -1;
  492.     int closest_dist = INF;
  493.     bool can_os   = false;
  494.  
  495.     // We get the position of every enemy next turn
  496.     State ns(s);
  497.     a.type=ACTION_NONE;
  498.     evolve(ns, a, false);
  499.    
  500.     // For every enemy
  501.     for (int eid=0; eid < n_enemies; ++eid) {
  502.       if (s.en_l[eid] > 0) {
  503.     int d = ns.dist2[eid];
  504.     int dmg = damage_dealt(d);
  505.  
  506.     // Can we one shot /
  507.     if (dmg >= s.en_l[eid]) {
  508.       can_os = true;
  509.      
  510.       // Closest enemy is preferrable to avoid death
  511.       if (d < best_dist) {
  512.         best_id = eid;
  513.         best_dist = d;
  514.         best_life = s.en_l[eid];
  515.       }
  516.       else if (d == best_dist && s.en_l[eid] > best_life) {
  517.         best_id = eid;
  518.         best_dist = d;
  519.         best_life = s.en_l[eid];  
  520.       }
  521.     }
  522.  
  523.     // We also use this loop to store the closest enemy
  524.     if (d < closest_dist) {
  525.       closest_dist = d;
  526.       closest_id   = eid;
  527.     }
  528.       }
  529.     }
  530.  
  531.     // If we can one-shot we have a 90% probability to shoot
  532.     if (can_os && RAND(100) < PROB_OS) {
  533.       a = Action{ACTION_SHOOT, best_id, 0};
  534.       sol.actions[t++] = a;
  535.       state = evolve(s, a, true);
  536.       continue;
  537.     }
  538.  
  539.     // Si no one-shot, we find a random strategy between the following :
  540.     //  1- Go towards a random DP (full speed)
  541.     //  2- Go towards an enemy (full speed)
  542.     //  3- Random move
  543.     //  4- Kill an enemy (shoot until it's dead)
  544.    
  545.     int prob = 150; // Rescaling ... ugly but work
  546.     int action = RAND(prob);
  547.     int nreps = RAND(4) + 1;  // How many repetitions ? (up to 5)
  548.     int ite = 0;
  549.  
  550.     // 1- DP
  551.     if (action <= PROB_GO_DP) {
  552.       int pids[MAX_DP];
  553.       int ndp=0;
  554.       for (int i=0; i < n_dp; ++i)
  555.     if (s.dp_a[i])
  556.       pids[ndp++] = i;
  557.        
  558.       int tid = pids[RAND(ndp)];
  559.       while (state == STATE_ONGOING && ite < nreps) {          
  560.     a = Action{ACTION_MOVE, dp_x[tid], dp_y[tid]};
  561.     sol.actions[t++] = a;
  562.     state = evolve(s, a, true);
  563.     ite++;
  564.       }
  565.     }
  566.    
  567.     // 2- Enemy
  568.     else if (action <= PROB_GO_EN) {      
  569.       int eid = random_enemy(s);
  570.      
  571.       while (state == STATE_ONGOING && ite < nreps) {    
  572.     int x = s.x;
  573.     int y = s.y;
  574.     move(x, y, s.en_x[eid], s.en_y[eid], MY_VEL);
  575.    
  576.     a = Action{ACTION_MOVE, x, y};
  577.     sol.actions[t++] = a;
  578.     state = evolve(s, a, true);
  579.     ite++;
  580.       }
  581.     }
  582.    
  583.     // 3- Random move
  584.     else if (action <= PROB_GO_RD) {
  585.       int move = RAND(N_RANDOM);
  586.       int rx = rand_x[move];
  587.       int ry = rand_y[move];
  588.    
  589.       while (state == STATE_ONGOING && ite < nreps) {
  590.     a = Action{ACTION_MOVE, s.x + rx, s.y + ry};
  591.     sol.actions[t++] = a;
  592.     state = evolve(s, a, true);
  593.     ite++;
  594.       }
  595.     }
  596.    
  597.     // 4- Shooting the closest enemy
  598.     else {
  599.       a = Action{ACTION_SHOOT, closest_id, 0};
  600.       while (state == STATE_ONGOING && s.en_l[closest_id] > 0) {
  601.     sol.actions[t++] = a;
  602.     state = evolve(s, a, true);
  603.       }
  604.     }
  605.   }
  606.  
  607.   // Copying final state, and filling in the info
  608.   sol.final_state = state;
  609.   sol.score = game_score(s);
  610.   if (state == STATE_GAME_OVER)
  611.     sol.dist_from_killer = s.dist_from_killer;
  612.   sol.nactions = t;
  613. }
  614.  
  615. // Main, obvious
  616. int main() {
  617.   srand(26111996);
  618.   turn = 0;
  619.   ai_mode = AI_MODE_MC;
  620.  
  621.   State s;
  622.   turn_in_sol = 0;
  623.   current_solution.score = -INF;
  624.  
  625.   while (true) {
  626.     read_state_from_stdin(s, turn==0);
  627.     turn++;
  628.     play_turn(s);
  629.   }
  630. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement