challenge-codinggame/coders-strike-back/code1.ml

47 lines
1.7 KiB
OCaml
Raw Normal View History

2016-07-27 07:14:45 +00:00
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 *)
(* parse my data *)
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
(* parse opponent data *)
let line = input_line stdin in
let opponentx, opponenty = Scanf.sscanf line "%d %d" (fun opponentx opponenty -> (opponentx, opponenty)) in
let is_far = nextcheckpointdist > 4000 in
let is_near = nextcheckpointdist < 500 in
let is_aligned = nextcheckpointangle > -15 && nextcheckpointangle < 15 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_aside then 10
else if is_aligned && is_near then 30
else 100
in
let power_str = match use_boost with
| false -> string_of_int thrust
| true -> "BOOST"
in
(* output the target position + the power (0 <= thrust <= 100) *)
(* i.e.: "x y thrust" *)
printf "%d %d %s\n%!" nextcheckpointx nextcheckpointy power_str ;
();
done;