diff options
Diffstat (limited to 'judge/player.ml')
-rw-r--r-- | judge/player.ml | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/judge/player.ml b/judge/player.ml index 8f74fe7..1d89fe8 100644 --- a/judge/player.ml +++ b/judge/player.ml @@ -4,10 +4,26 @@ module type IA = sig module G : GAME - val play : G.game -> string + val play : G.game -> float -> string end +let expect mgs = + let l = read_line () in + begin try + let (s, f) = List.find + (fun (s, _) -> + String.length l >= String.length s + && String.sub l 0 (String.length s) = s) + mgs + in f (String.sub l (String.length s) + (String.length l - String.length s)) + with + Not_found -> + Format.eprintf "Unexpected '%s'.@." l; + exit 1 + end + module P (W : IA) : sig val run : unit -> unit @@ -16,30 +32,14 @@ end = struct module G = W.G - let expect mgs = - let l = read_line () in - begin try - let (s, f) = List.find - (fun (s, _) -> - String.length l >= String.length s - && String.sub l 0 (String.length s) = s) - mgs - in f (String.sub l (String.length s) - (String.length l - String.length s)) - with - Not_found -> - Format.eprintf "Unexpected '%s'.@." l; - exit 1 - end - let finished _ = print_string "Fair enough\n" let rec turn g _ = expect [ "Your turn", - (fun _ -> - let act = W.play g in + (fun time -> + let act = W.play g (float_of_string time) in Format.printf "Play %s@." act; let g' = G.play g act in expect [ "OK", turn g' ]); |