It compiles !
This commit is contained in:
parent
1089f6cd49
commit
1b188c8cfd
1 changed files with 112 additions and 52 deletions
|
@ -51,21 +51,36 @@ let module Vector = struct
|
||||||
end in
|
end in
|
||||||
|
|
||||||
let module Pod = struct
|
let module Pod = struct
|
||||||
|
type orientation_t =
|
||||||
|
| Behind
|
||||||
|
| Aside
|
||||||
|
| WideAligned
|
||||||
|
| NearAligned
|
||||||
|
| Aligned
|
||||||
|
|
||||||
|
type distance_t =
|
||||||
|
| Touching
|
||||||
|
| Near
|
||||||
|
| Anywhere
|
||||||
|
| Far
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
mutable id : int ;
|
mutable id : int ;
|
||||||
mutable pos : Vector.t ;
|
mutable pos : Vector.t ;
|
||||||
mutable dir : Vector.t ;
|
mutable old_pos : Vector.t ;
|
||||||
mutable has_boost : bool ;
|
mutable dir : Vector.t ;
|
||||||
mutable checkpoint_pos : Vector.t ;
|
mutable has_boost : bool ;
|
||||||
mutable checkpoint_dist : int ;
|
mutable checkpoint_pos : Vector.t ;
|
||||||
|
mutable checkpoint_dist : int ;
|
||||||
mutable checkpoint_angle : int ;
|
mutable checkpoint_angle : int ;
|
||||||
mutable output_str : string
|
mutable output_str : string
|
||||||
}
|
}
|
||||||
|
|
||||||
let create () =
|
let create () =
|
||||||
{
|
{
|
||||||
id = 0 ;
|
id = 0 ;
|
||||||
pos = Vector.create 0 0 ;
|
pos = Vector.create 0 0 ;
|
||||||
|
old_pos = Vector.create 0 0 ;
|
||||||
dir = Vector.create 0 0 ;
|
dir = Vector.create 0 0 ;
|
||||||
has_boost = true ;
|
has_boost = true ;
|
||||||
checkpoint_pos = Vector.create 0 0 ;
|
checkpoint_pos = Vector.create 0 0 ;
|
||||||
|
@ -84,6 +99,45 @@ let module Pod = struct
|
||||||
pod.checkpoint_angle <- checkpoint_angle ;
|
pod.checkpoint_angle <- checkpoint_angle ;
|
||||||
pod
|
pod
|
||||||
|
|
||||||
|
let movement pod =
|
||||||
|
Vector.diff pod.pos pod.old_pos
|
||||||
|
|
||||||
|
let is_aligned pod =
|
||||||
|
pod.checkpoint_angle > -2 &&
|
||||||
|
pod.checkpoint_angle < 2
|
||||||
|
|
||||||
|
let is_near_aligned pod =
|
||||||
|
(pod.checkpoint_angle > -15 && pod.checkpoint_angle <= -2) ||
|
||||||
|
(pod.checkpoint_angle >= 2 && pod.checkpoint_angle < 15)
|
||||||
|
|
||||||
|
let is_wide_aligned pod =
|
||||||
|
(pod.checkpoint_angle > -45 && pod.checkpoint_angle <= -15) ||
|
||||||
|
(pod.checkpoint_angle >= 15 && pod.checkpoint_angle < 45)
|
||||||
|
|
||||||
|
let is_aside pod =
|
||||||
|
(pod.checkpoint_angle > -85 && pod.checkpoint_angle <= -45) ||
|
||||||
|
(pod.checkpoint_angle >= 45 && pod.checkpoint_angle < 85)
|
||||||
|
|
||||||
|
let is_behind pod =
|
||||||
|
pod.checkpoint_angle >= 85 || pod.checkpoint_angle <= -85
|
||||||
|
|
||||||
|
let is_checkpoint_far pod =
|
||||||
|
Vector.is_far pod.pos pod.checkpoint_pos
|
||||||
|
|
||||||
|
let target_orientation pod =
|
||||||
|
if is_aligned pod then Aligned
|
||||||
|
else if is_near_aligned pod then NearAligned
|
||||||
|
else if is_wide_aligned pod then WideAligned
|
||||||
|
else if is_aside pod then Aside
|
||||||
|
else Behind
|
||||||
|
|
||||||
|
let target_distance pod =
|
||||||
|
let dist = Vector.distance pod.pos pod.checkpoint_pos in
|
||||||
|
if dist <= (checkpoint_ray) then Touching
|
||||||
|
else if dist <= (checkpoint_ray * 3) then Near
|
||||||
|
else if dist > (checkpoint_ray * 2 * 3) then Far
|
||||||
|
else Anywhere
|
||||||
|
|
||||||
|
|
||||||
end in
|
end in
|
||||||
|
|
||||||
|
@ -123,57 +177,61 @@ end in
|
||||||
|
|
||||||
let module Game = struct
|
let module Game = struct
|
||||||
type t = {
|
type t = {
|
||||||
pods : Pod.t array ;
|
pods : Pod.t array ;
|
||||||
opponents : Pod.t array ;
|
opponents : Pod.t array ;
|
||||||
ticks : int ;
|
mutable turn : int ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let create () =
|
||||||
|
{
|
||||||
|
pods = Array.make 2 (Pod.create ()) ;
|
||||||
|
opponents = Array.make 2 (Pod.create ()) ;
|
||||||
|
turn = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_first_turn game = game.turn < 2
|
||||||
|
|
||||||
|
let save_pods game =
|
||||||
|
(* old_pod := pod ; *)
|
||||||
|
ignore game
|
||||||
|
|
||||||
|
let tick game =
|
||||||
|
game.turn <- game.turn + 1
|
||||||
|
|
||||||
end in
|
end in
|
||||||
|
|
||||||
let module Strategy = struct
|
let module Strategy = struct
|
||||||
let apply game pod =
|
let apply game pod =
|
||||||
if !first_turn then begin
|
if Game.is_first_turn game then begin
|
||||||
old_pod := pod ;
|
Game.save_pods game ;
|
||||||
first_turn := false
|
|
||||||
end ;
|
end ;
|
||||||
let movement = Vector.diff pod !old_pod in
|
let movement = Pod.movement in
|
||||||
|
|
||||||
|
(*
|
||||||
if (CheckpointList.inc !checkpoint_list checkpoint) then begin
|
if (CheckpointList.inc !checkpoint_list checkpoint) then begin
|
||||||
prerr_endline "List already includes this checkpoint" ;
|
prerr_endline "List already includes this checkpoint" ;
|
||||||
end else begin
|
end else begin
|
||||||
checkpoint_list := (CheckpointList.add !checkpoint_list checkpoint) ;
|
checkpoint_list := (CheckpointList.add !checkpoint_list checkpoint) ;
|
||||||
fprintf stderr "New checkpoint : %s\n%!" (Vector.to_string checkpoint);
|
fprintf stderr "New checkpoint : %s\n%!" (Vector.to_string checkpoint);
|
||||||
end ;
|
end ;
|
||||||
|
*)
|
||||||
|
|
||||||
(* output "x y thrust" : the target position + the power *)
|
|
||||||
let is_aligned = checkpoint_angle > -2 && checkpoint_angle < 2 in
|
|
||||||
let is_near_aligned =
|
|
||||||
(checkpoint_angle > -15 && checkpoint_angle <= -2) ||
|
|
||||||
(checkpoint_angle >= 2 && checkpoint_angle < 15)
|
|
||||||
in
|
|
||||||
let is_wide_aligned =
|
|
||||||
(checkpoint_angle > -45 && checkpoint_angle <= -15) ||
|
|
||||||
(checkpoint_angle >= 15 && checkpoint_angle < 45)
|
|
||||||
in
|
|
||||||
let is_aside =
|
|
||||||
(checkpoint_angle > -85 && checkpoint_angle <= -45) ||
|
|
||||||
(checkpoint_angle >= 45 && checkpoint_angle < 85)
|
|
||||||
in
|
|
||||||
let is_behind = checkpoint_angle >= 85 || checkpoint_angle <= -85 in
|
|
||||||
let use_boost =
|
let use_boost =
|
||||||
(!tick > 100) && is_aligned && (Vector.is_far pod checkpoint)
|
(game.turn > 100) &&
|
||||||
|
(Pod.is_aligned pod) &&
|
||||||
|
(Pod.is_checkpoint_far pod)
|
||||||
in
|
in
|
||||||
|
|
||||||
debug "angle = %d\n%!" checkpoint_angle ;
|
|
||||||
|
|
||||||
let thrust =
|
let thrust =
|
||||||
(* droit devant *)
|
(* droit devant *)
|
||||||
if is_behind && (Vector.is_touching pod opponent) then 20
|
match (Pod.target_orientation pod, Pod.target_distance pod) with
|
||||||
else if is_aside && (Vector.is_touching pod opponent) then 20
|
(* | (Behind, TouchingOpponent) -> 20
|
||||||
else if is_behind then 6
|
| (Aside, TouchingOpponent) -> 20 *)
|
||||||
else if is_aside && (Vector.is_near checkpoint pod) then 10
|
| (Behind, _) -> 6
|
||||||
else if is_wide_aligned && (Vector.is_near checkpoint pod) then 20
|
| (Aside, Near) -> 10
|
||||||
else if is_near_aligned && (Vector.is_near checkpoint pod) then 40
|
| (WideAligned, Near) -> 20
|
||||||
else 100
|
| (NearAligned, Near) -> 40
|
||||||
|
| (_, _) -> 100
|
||||||
in
|
in
|
||||||
|
|
||||||
let power_str = match use_boost with
|
let power_str = match use_boost with
|
||||||
|
@ -181,7 +239,10 @@ let module Strategy = struct
|
||||||
| true -> "BOOST"
|
| true -> "BOOST"
|
||||||
in
|
in
|
||||||
|
|
||||||
let target = Vector.add checkpoint (Vector.mult movement (-3)) in
|
let target =
|
||||||
|
Vector.mult (Pod.movement pod) (-3)
|
||||||
|
|> Vector.add pod.checkpoint_pos
|
||||||
|
in
|
||||||
|
|
||||||
printf "%d %d %s\n%!" target.x target.y power_str ;
|
printf "%d %d %s\n%!" target.x target.y power_str ;
|
||||||
|
|
||||||
|
@ -230,26 +291,25 @@ let parse_init () =
|
||||||
done
|
done
|
||||||
in
|
in
|
||||||
|
|
||||||
let pods = Array.make 2 (Pod.create ()) in
|
|
||||||
let game = Game.create () in
|
let game = Game.create () in
|
||||||
|
|
||||||
(* game loop *)
|
(* game loop *)
|
||||||
while true do
|
while true do
|
||||||
(* read pod1 line & update game data *)
|
(* read pod1 line & update game data *)
|
||||||
parse_pod_line () |> Pod.update game.pods.(0) ;
|
parse_pod_line () |> Pod.update game.pods.(0) |> ignore ;
|
||||||
parse_pod_line () |> Pod.update game.pods.(1) ;
|
parse_pod_line () |> Pod.update game.pods.(1) |> ignore ;
|
||||||
parse_pod_line () |> Pod.update game.opponents.(0) ;
|
parse_pod_line () |> Pod.update game.opponents.(0) |> ignore ;
|
||||||
parse_pod_line () |> Pod.update game.opponents.(1) ;
|
parse_pod_line () |> Pod.update game.opponents.(1) |> ignore ;
|
||||||
|
|
||||||
for i = 0 to 1 do
|
for i = 0 to 1 do
|
||||||
game.pods.(i)
|
game.pods.(i)
|
||||||
|> Pod.update pod1_data
|
(* |> Strategy.apply *)
|
||||||
|> Strategy.apply
|
|> (fun (pod : Pod.t) -> pod.output_str)
|
||||||
|> fun pod -> print_endline pod.output_str ;
|
|> print_endline
|
||||||
done
|
;
|
||||||
|
done ;
|
||||||
|
|
||||||
tick := !tick + 1 ;
|
Game.tick game ;
|
||||||
old_pod := pod ;
|
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue