aboutsummaryrefslogtreecommitdiffstats
path: root/game.ml
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 /game.ml
parent2acffa283e52a449a72539377851ddc8c43d63e8 (diff)
parent43f6aa6e9b6dfe4faebbd1bfcf2098fb8f32a1da (diff)
downloadicfp2011-25b56ebd2bee7ea8f2a6fecb11335d9ecb34fe1b.tar.gz
Merge branch 'master' of github.com:Zaran/icfp2011
Diffstat (limited to 'game.ml')
-rw-r--r--game.ml26
1 files changed, 19 insertions, 7 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;;