aboutsummaryrefslogtreecommitdiff
path: root/judge/morpion_rec.ml
diff options
context:
space:
mode:
Diffstat (limited to 'judge/morpion_rec.ml')
-rw-r--r--judge/morpion_rec.ml65
1 files changed, 22 insertions, 43 deletions
diff --git a/judge/morpion_rec.ml b/judge/morpion_rec.ml
index 15af169..d2b1c14 100644
--- a/judge/morpion_rec.ml
+++ b/judge/morpion_rec.ml
@@ -3,22 +3,7 @@ open Main
let ( |> ) x f = f x
-module Morpion_rec : sig
-
- type game (* immutable structure *)
-
- val name : string
- val id : string
-
- val new_game : game
-
- val possibilities : game -> string list
- val play : game -> player -> string -> game
- val s : game -> game_status
-
- val display_game : game -> (string * string) -> unit
-
-end = struct
+module G = struct
exception Invalid_pos
@@ -126,28 +111,28 @@ end = struct
| l when List.exists ((=) Empty) l -> Empty
| _ -> T
- let play (gs, m, pgo) player act =
- let elim = (Eliminated player, m, pgo) in
- let op = other_player player in
+ let play (gs, m, pgo) act =
let (pg, pp) = decode act in
- if
- gs = TurnOf player
- && (match pgo with
- | None -> true
- | Some x when full_pm (getp1 m x) -> true
- | Some x when pg = x -> true
- | _ -> false)
- && getp m (pg, pp) = Empty
- then
- let new_m = setp m (pg, pp) (match player with P1 -> X | P2 -> O) in
- let new_s = match reduce_m (reduce_m (fun x -> x)) new_m with
- | Empty -> TurnOf op
- | X -> Won P1
- | O -> Won P2
- | T -> Tie
- in
- (new_s, new_m, Some pp)
- else elim
+ match gs with
+ | TurnOf player when
+ (match pgo with
+ | None -> true
+ | Some x when full_pm (getp1 m x) -> true
+ | Some x when pg = x -> true
+ | _ -> false)
+ && getp m (pg, pp) = Empty
+ ->
+ let op = other_player player in
+ let new_m = setp m (pg, pp) (match player with P1 -> X | P2 -> O) in
+ let new_s = match reduce_m (reduce_m (fun x -> x)) new_m with
+ | Empty -> TurnOf op
+ | X -> Won P1
+ | O -> Won P2
+ | T -> Tie
+ in
+ (new_s, new_m, Some pp)
+ | TurnOf x -> (Eliminated x, m, pgo)
+ | _ -> raise (Eliminated_ex "not someone's turn!")
let s (s, _, _) = s
@@ -158,9 +143,3 @@ end = struct
end
-module C = Core(Morpion_rec)
-module Main = Juge(C)
-
-let () = Main.run ()
-
-