challenge-codinggame/coders-strike-back/code2.ml
Glenn Y. Rolland 23b6693ef3 Up.
2016-07-28 02:44:57 +02:00

65 lines
2.5 KiB
OCaml

(* Auto-generated code below aims at helping you parse *)
(* the standard input according to the problem statement. *)
let open Printf in
let debug = fprintf stderr in
(* game loop *)
while true do
(* nextcheckpointx: x position of the next check point *)
(* nextcheckpointy: y position of the next check point *)
(* nextcheckpointdist: distance to the next checkpoint *)
(* nextcheckpointangle: angle between your pod orientation and the direction of the next checkpoint *)
let line = input_line stdin in
let x, y, nextcheckpointx, nextcheckpointy, nextcheckpointdist, nextcheckpointangle =
Scanf.sscanf line "%d %d %d %d %d %d" (fun x y nextcheckpointx nextcheckpointy nextcheckpointdist nextcheckpointangle -> (x, y, nextcheckpointx, nextcheckpointy, nextcheckpointdist, nextcheckpointangle))
in
let line = input_line stdin in
let opponentx, opponenty = Scanf.sscanf line "%d %d" (fun opponentx opponenty -> (opponentx, opponenty)) in
(* Write an action using print_endline *)
(* To debug: prerr_endline "Debug message"; *)
(* You have to output the target position *)
(* followed by the power (0 <= thrust <= 100) *)
(* i.e.: "x y thrust" *)
let is_far = nextcheckpointdist > 2000 in
let is_near = nextcheckpointdist < 200 in
let is_very_near = nextcheckpointdist < 100 in
let is_aligned = nextcheckpointangle > -5 && nextcheckpointangle < 5 in
let is_near_aligned = nextcheckpointangle > -15 && nextcheckpointangle < 15 in
let is_wide_aligned = nextcheckpointangle > -30 && nextcheckpointangle < 30 in
let is_aside = nextcheckpointangle > 90 || nextcheckpointangle < -90 in
let use_boost = is_aligned && is_far in
debug "angle = %d\n%!" nextcheckpointangle ;
let thrust =
if is_aligned && (nextcheckpointdist > 100) then 100
else if is_aligned && (nextcheckpointdist <= 100) then 50
else if is_near_aligned && (nextcheckpointdist > 150) then 80
else if is_near_aligned && (nextcheckpointdist <= 150) then 40
else if is_wide_aligned && (nextcheckpointdist > 200) then 60
else if is_wide_aligned && (nextcheckpointdist <= 200) then 30
else if is_aside && (nextcheckpointdist > 250) then 5
else if is_aside && (nextcheckpointdist <= 250) then 2
else 100
in
let power_str = match use_boost with
| false -> string_of_int thrust
| true -> "BOOST"
in
printf "%d %d %s\n%!" nextcheckpointx nextcheckpointy power_str ;
();
done;