aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2011-06-19 10:06:36 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2011-06-19 10:06:36 -0400
commit25b56ebd2bee7ea8f2a6fecb11335d9ecb34fe1b (patch)
tree57cced5da32216390d31b8d6be406279277e5673
parent2acffa283e52a449a72539377851ddc8c43d63e8 (diff)
parent43f6aa6e9b6dfe4faebbd1bfcf2098fb8f32a1da (diff)
downloadicfp2011-25b56ebd2bee7ea8f2a6fecb11335d9ecb34fe1b.tar.gz
Merge branch 'master' of github.com:Zaran/icfp2011
-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 0313172..25eb096 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