diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-11-10 10:46:37 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-11-10 10:46:37 +0100 |
commit | 80e625a9c8d33c71fe69a375c211868fcc1938a5 (patch) | |
tree | f516d701cc8cb50e9a1d003afe6e7d1f05b457ca /judge/core.ml | |
parent | d343fcb803e955504b0d6b5c9c852620886c2994 (diff) | |
download | CompetIA-80e625a9c8d33c71fe69a375c211868fcc1938a5.tar.gz CompetIA-80e625a9c8d33c71fe69a375c211868fcc1938a5.zip |
Start work on players!
Diffstat (limited to 'judge/core.ml')
-rw-r--r-- | judge/core.ml | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/judge/core.ml b/judge/core.ml index 8ffdc47..dd6c31c 100644 --- a/judge/core.ml +++ b/judge/core.ml @@ -4,6 +4,8 @@ open Protocol (* Description of data structures *) +exception Eliminated_ex of string + type player = P1 | P2 let other_player = function P1 -> P2 | P2 -> P1 @@ -28,7 +30,7 @@ module type GAME = sig val new_game : game - val play : game -> player -> string -> game + val play : game -> string -> game val s : game -> game_status val display_game : game -> (string * string) -> unit @@ -65,8 +67,6 @@ end module Core (G: GAME) : CORE = struct module G : GAME = G - exception Eliminated_ex of string - type player = { name: string; binary: string; @@ -84,7 +84,9 @@ module Core (G: GAME) : CORE = struct mutable s: player_proc_status; } let send_m pp m = - output_string pp.o (encode m ^ "\n"); + let m = encode m in + Format.printf ">%s< %s@." pp.p.name m; + output_string pp.o (m ^ "\n"); flush pp.o type game = { @@ -282,12 +284,17 @@ module Core (G: GAME) : CORE = struct let pi = if Unix.descr_of_in_channel g.p1.i = fd then P1 else P2 in let p = match pi with P1 -> g.p1 | P2 -> g.p2 in let op = match pi with P1 -> g.p2 | P2 -> g.p1 in - begin try match decode (input_line p.i), p.s with + begin try + let l = input_line p.i in + Format.printf "<%s> %s@." p.p.name l; + match decode l, p.s with | Hello x, Loading when x = G.id -> p.s <- StandBy !game_time; | Play act, Thinking (time, beg_r) -> let end_r = Unix.gettimeofday () in - let new_g = G.play (List.hd g.hist) pi act in + if G.s (List.hd g.hist) <> TurnOf pi then + raise (Eliminated_ex "not your turn (assert failed)"); + let new_g = G.play (List.hd g.hist) act in let new_s = G.s new_g in send_m p OK; send_m op (Play act); |