From 0e83991e3f8739ec00d744f038fdfaea2b60c98e Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 15 Nov 2014 22:36:31 +0100 Subject: Nothing big... --- judge/morpion_rec.ml | 4 +++- judge/player.ml | 38 +++++++++++++++++----------------- morpion_rec/AmaneSuzuha/amane.ml | 2 +- morpion_rec/FeirisuNyanNyan/feirisu.ml | 2 +- morpion_rec/Mayushii/mayushii.ml | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/judge/morpion_rec.ml b/judge/morpion_rec.ml index cb23821..a46b7f9 100644 --- a/judge/morpion_rec.ml +++ b/judge/morpion_rec.ml @@ -90,9 +90,11 @@ module G = struct alors même si l'adversaire aligne trois cases dedans APRES, le petit morpion reste attribué à la même personne. *) + let setp1p (m, r) (px, py) v = + setp1 (m, r) (px, py) v (fun x -> x) (* setp : 'a morpion morpion -> loc2 -> 'a -> 'a morpion morpion *) let setp m (pg, pp) v = - let im = setp1 (getp1 m pg) pp v (fun x -> x) in + let im = setp1p (getp1 m pg) pp v in let om = setp1 m pg im reduct in om 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' ]); diff --git a/morpion_rec/AmaneSuzuha/amane.ml b/morpion_rec/AmaneSuzuha/amane.ml index 7ac321f..b8f20e2 100644 --- a/morpion_rec/AmaneSuzuha/amane.ml +++ b/morpion_rec/AmaneSuzuha/amane.ml @@ -10,7 +10,7 @@ module Amane : Player.IA = struct let won_game g = match G.s g with Won _ -> true | _ -> false - let play g = + let play g time = let cc = G.possibilities g in match List.partition (fun act -> won_game (G.play g act)) diff --git a/morpion_rec/FeirisuNyanNyan/feirisu.ml b/morpion_rec/FeirisuNyanNyan/feirisu.ml index e15e1d1..544a650 100644 --- a/morpion_rec/FeirisuNyanNyan/feirisu.ml +++ b/morpion_rec/FeirisuNyanNyan/feirisu.ml @@ -3,7 +3,7 @@ module Feirisu : Player.IA = struct module G = Morpion_rec.G - let play g = + let play g time = let cc = G.possibilities g in List.nth cc (Random.int (List.length cc)) diff --git a/morpion_rec/Mayushii/mayushii.ml b/morpion_rec/Mayushii/mayushii.ml index 57ec3aa..ec2771c 100644 --- a/morpion_rec/Mayushii/mayushii.ml +++ b/morpion_rec/Mayushii/mayushii.ml @@ -3,7 +3,7 @@ module Mayushii : Player.IA = struct module G = Morpion_rec.G - let play g = + let play g time = let cc = G.possibilities g in List.hd cc -- cgit v1.2.3