diff options
Diffstat (limited to 'morpion_rec/AmaneSuzuha/amane.ml')
-rw-r--r-- | morpion_rec/AmaneSuzuha/amane.ml | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/morpion_rec/AmaneSuzuha/amane.ml b/morpion_rec/AmaneSuzuha/amane.ml new file mode 100644 index 0000000..f96859b --- /dev/null +++ b/morpion_rec/AmaneSuzuha/amane.ml @@ -0,0 +1,41 @@ + +module Amane : Player.IA = struct + + module G = Morpion_rec.G + open Core + + let take_random cc = + List.nth cc + (Random.int (List.length cc)) + + let won_game g = match G.s g with Won _ -> true | _ -> false + + let play g = + let cc = G.possibilities g in + match List.partition + (fun act -> won_game (G.play g act)) + cc + with + | win::_, _ -> win + | [], other -> + let o' = List.filter + (fun act -> + let g' = G.play g act in + let adv_win = + G.possibilities g' + |> List.map (G.play g') + |> List.exists won_game + in not adv_win) + other + in match o', other with + | x::_, _ -> x + | _, a::_ -> a + | _ -> assert false + +end + +module P = Player.P(Amane) + +let () = + Random.self_init(); + P.run() |