Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- /**
- * This code automatically collects game data in an infinite loop.
- * It uses the standard input to place data into the game variables such as x and y.
- * YOU DO NOT NEED TO MODIFY THE INITIALIZATION OF THE GAME VARIABLES.
- **/
- int main()
- {
- int prev_x = 0;
- int prev_y = 0;
- int frame = 0;
- int last_ram_frame = 0;
- // game loop
- while (1) {
- int ship_x, ship_y;
- int cp_x, cp_y, cp_dist, cp_angle;
- int opp_x, opp_y;
- scanf("%d%d%d%d%d%d%d%d", &ship_x, &ship_y, &cp_x, &cp_y, &cp_dist, &cp_angle, &opp_x, &opp_y);
- // Don't care about which direction we're rotated
- cp_angle = abs(cp_angle);
- // Opponent distance from me
- int opp_dx_me = opp_x - ship_x;
- int opp_dy_me = opp_y - ship_y;
- int opp_dist_me = sqrt(opp_dx_me*opp_dx_me + opp_dy_me*opp_dy_me);
- // Opponent distance from my next checkpoint
- int opp_dx_cp = opp_x - cp_x;
- int opp_dy_cp = opp_y - cp_y;
- int opp_dist_cp = sqrt(opp_dx_cp*opp_dx_cp + opp_dy_cp*opp_dy_cp);
- // My ship's velocity
- int vx = ship_x - prev_x;
- int vy = ship_y - prev_y;
- int vel2 = vx*vx + vy*vy;
- int cp_radius = 600; // Checkpoint radius
- int slow_zone_radius = 1500; // how close to next checkpoint to slow down
- int boost_zone_radius = 10000; // how far from next checkpoint to boost
- bool on_course_slow_zone = cp_angle < 10; // max angle to consider my ship head on when in slow zone
- bool on_course_far_away = cp_angle < 30; // max angle to consider my ship head on when far away
- bool slow_zone = cp_dist < slow_zone_radius;
- bool boost_zone = cp_dist > boost_zone_radius;
- bool going_too_fast = vel2 > 300*300; // empirical velocity "too fast" in slow zone (slow down to make turning around easier)
- int target_x = cp_x;
- int target_y = cp_y;
- int thrust;
- if (slow_zone) {
- float slow_zone_scale = (float)cp_dist / (slow_zone_radius - cp_radius);
- if (slow_zone_scale < 0.0f) slow_zone_scale = 0.0f;
- if (on_course_slow_zone) {
- if (going_too_fast) {
- thrust = 15;
- } else {
- float by_dist = 30.0f + 30.0f * slow_zone_scale;
- thrust = (int)by_dist;
- }
- } else {
- float by_dist = 10.0f + 10.0f * slow_zone_scale;
- thrust = (int)by_dist;
- }
- } else if (boost_zone && on_course_far_away) {
- thrust = -1;
- } else {
- #if 0
- // RAM the opponent ship if:
- // 1) I'm facing away from my next checkpoint
- // 2) Enemy is within ram radius from me
- // 3) Enemy is measurably farther away from next checkpoint than me
- // 4) We haven't rammed opponent recently
- bool opp_farther_away = opp_dist_cp > cp_dist;
- if (frame - last_ram_frame > 2000 && opp_farther_away) {
- target_x = opp_x;
- target_y = opp_y;
- thrust = 100;
- fprintf(stderr, "!!! RAM !!!");
- last_ram_frame = frame;
- } else {
- thrust = on_course_far_away ? 100 : 50;
- }
- #else
- thrust = on_course_far_away ? 100 : 50;
- #endif
- }
- if (thrust >= 0) {
- printf("%d %d %d\n", target_x, target_y, thrust);
- } else {
- printf("%d %d BOOST\n", target_x, target_y);
- }
- prev_x = ship_x;
- prev_y = ship_y;
- frame++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement