aboutsummaryrefslogtreecommitdiff
path: root/judge/player.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-11-10 10:46:37 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-11-10 10:46:37 +0100
commit80e625a9c8d33c71fe69a375c211868fcc1938a5 (patch)
treef516d701cc8cb50e9a1d003afe6e7d1f05b457ca /judge/player.ml
parentd343fcb803e955504b0d6b5c9c852620886c2994 (diff)
downloadCompetIA-80e625a9c8d33c71fe69a375c211868fcc1938a5.tar.gz
CompetIA-80e625a9c8d33c71fe69a375c211868fcc1938a5.zip
Start work on players!
Diffstat (limited to 'judge/player.ml')
-rw-r--r--judge/player.ml61
1 files changed, 61 insertions, 0 deletions
diff --git a/judge/player.ml b/judge/player.ml
new file mode 100644
index 0000000..8f74fe7
--- /dev/null
+++ b/judge/player.ml
@@ -0,0 +1,61 @@
+open Core
+
+module type IA = sig
+
+ module G : GAME
+
+ val play : G.game -> string
+
+end
+
+module P (W : IA) : sig
+
+ val run : unit -> unit
+
+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
+ Format.printf "Play %s@." act;
+ let g' = G.play g act in
+ expect [ "OK", turn g' ]);
+ "Play ", (fun act -> turn (G.play g act) "");
+ "Tie", finished;
+ "You win", finished;
+ "You lose", finished;
+ "Eliminated", finished
+ ]
+
+ let run () =
+ Random.self_init ();
+ expect [
+ "Hello " ^ G.id,
+ (fun _ -> Format.printf "Hello %s@." G.id;
+ turn (G.new_game) "")
+ ];
+
+end