aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--game.ml26
-rw-r--r--ltg.ml11
2 files changed, 27 insertions, 10 deletions
diff --git a/game.ml b/game.ml
index f1cbccf..de26555 100644
--- a/game.ml
+++ b/game.ml
@@ -4,13 +4,13 @@ type lambda =
|Const of int
|Lambda of (lambda -> lambda);;
-let unfold (Lambda x) = x
+let unfold l = match l with
+ | Lambda f -> f
+ | _ -> raise( Rule_error "wrong unfolding")
let id = Lambda(fun x -> x)
-let (@) a1 a2 = match a1 with
- | Lambda l1 -> l1 a2
- | _ -> raise( Rule_error "wrong application")
+let (@) a1 a2 = unfold a1 a2
type slot = {
mutable vitality: int;
@@ -227,7 +227,11 @@ let left_apply player card number =
opponent := player0
end;
let slot = !proponent.(number) in
- slot.field <- (cardfun_of_card card) @ slot.field
+ slot.field <-
+ try
+ (cardfun_of_card card) @ slot.field
+ with
+ | Rule_error _ | Invalid_argument _ -> (*TODO reset counter*) id
let right_apply player card number =
if player = 0 then begin
@@ -240,7 +244,11 @@ let right_apply player card number =
opponent := player0
end;
let slot = !proponent.(number) in
- slot.field <- slot.field @ (cardfun_of_card card)
+ slot.field <-
+ try
+ (cardfun_of_card card) @ slot.field
+ with
+ | Rule_error _ | Invalid_argument _ -> (*TODO reset counter*) id
let right_apply_bis player card number =
if player = 0 then begin
@@ -253,7 +261,11 @@ let right_apply_bis player card number =
opponent := player0
end;
let slot = !proponent.(number) in
- slot.field <- slot.field @ (cardfun_of_card_bis card)
+ slot.field <-
+ try
+ (cardfun_of_card card) @ slot.field
+ with
+ | Rule_error _ | Invalid_argument _ -> (*reset counter*) id
(*
right_apply !proponent.(0) Help;;
diff --git a/ltg.ml b/ltg.ml
index 1da6295..1b7c329 100644
--- a/ltg.ml
+++ b/ltg.ml
@@ -20,7 +20,14 @@ let read_move () = Scanf.scanf "%d\n" (fun d -> match d with
| _ -> failwith "Wrong move number"
)
-let play_move () = ()
+(* important print newline to flush output *)
+let play_move () =
+ Printf.printf "1";
+ print_newline ();
+ Printf.printf "I";
+ print_newline();
+ Printf.printf "1";
+ print_newline ()
let automatic player =
let aux i slot =
@@ -44,8 +51,6 @@ let do_round =
let _ =
let round = ref 1 in
while !round <= 100000 do
- Printf.printf "Round %d\n========" !round;
- print_newline ();
do_round ();
incr round
done \ No newline at end of file