From 3a4782b32e4d291cf88ea0ad57c79b66b28a5ff7 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 27 Jul 2016 09:14:45 +0200 Subject: [PATCH] Up. --- coders-strike-back/Makefile | 1 + coders-strike-back/code1.ml | 46 +++++++++++++++++++++++++++++++++ coders-strike-back/code1.native | 1 + 3 files changed, 48 insertions(+) create mode 120000 coders-strike-back/Makefile create mode 100644 coders-strike-back/code1.ml create mode 120000 coders-strike-back/code1.native diff --git a/coders-strike-back/Makefile b/coders-strike-back/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/coders-strike-back/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/coders-strike-back/code1.ml b/coders-strike-back/code1.ml new file mode 100644 index 0000000..ab22524 --- /dev/null +++ b/coders-strike-back/code1.ml @@ -0,0 +1,46 @@ + +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; + diff --git a/coders-strike-back/code1.native b/coders-strike-back/code1.native new file mode 120000 index 0000000..e6c55a8 --- /dev/null +++ b/coders-strike-back/code1.native @@ -0,0 +1 @@ +/home/grolland/src/Glenux/codingame/coders-strike-back/_build/code1.native \ No newline at end of file