aboutsummaryrefslogtreecommitdiff
path: root/morpion_rec
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-11-10 11:47:53 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-11-10 11:47:53 +0100
commit053f2090ebccd14f875b806c578e0f5467d68f5a (patch)
tree8850247e9f5b662d73edda57d6c43098958eb2c4 /morpion_rec
parent5900fdb76595b2eb9bf3168cd3ac84d7c52bad0c (diff)
downloadCompetIA-053f2090ebccd14f875b806c578e0f5467d68f5a.tar.gz
CompetIA-053f2090ebccd14f875b806c578e0f5467d68f5a.zip
Add Amane Suzuha, a minimal IA.
Diffstat (limited to 'morpion_rec')
-rw-r--r--morpion_rec/AmaneSuzuha/_tags2
-rw-r--r--morpion_rec/AmaneSuzuha/amane.ml41
l---------morpion_rec/AmaneSuzuha/lib1
-rw-r--r--morpion_rec/FeirisuNyanNyan/feirisu.ml4
4 files changed, 46 insertions, 2 deletions
diff --git a/morpion_rec/AmaneSuzuha/_tags b/morpion_rec/AmaneSuzuha/_tags
new file mode 100644
index 0000000..c653205
--- /dev/null
+++ b/morpion_rec/AmaneSuzuha/_tags
@@ -0,0 +1,2 @@
+"lib": include
+true: use_unix, use_graphics
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()
diff --git a/morpion_rec/AmaneSuzuha/lib b/morpion_rec/AmaneSuzuha/lib
new file mode 120000
index 0000000..e834a2a
--- /dev/null
+++ b/morpion_rec/AmaneSuzuha/lib
@@ -0,0 +1 @@
+../../judge \ No newline at end of file
diff --git a/morpion_rec/FeirisuNyanNyan/feirisu.ml b/morpion_rec/FeirisuNyanNyan/feirisu.ml
index be6cc63..e15e1d1 100644
--- a/morpion_rec/FeirisuNyanNyan/feirisu.ml
+++ b/morpion_rec/FeirisuNyanNyan/feirisu.ml
@@ -1,5 +1,5 @@
-module Mayushii : Player.IA = struct
+module Feirisu : Player.IA = struct
module G = Morpion_rec.G
@@ -10,7 +10,7 @@ module Mayushii : Player.IA = struct
end
-module P = Player.P(Mayushii)
+module P = Player.P(Feirisu)
let () =
Random.self_init();