aboutsummaryrefslogtreecommitdiffstats
path: root/game.ml
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2011-06-19 13:45:28 +0200
committerThibaut Horel <thibaut.horel@gmail.com>2011-06-19 13:45:28 +0200
commit43f6aa6e9b6dfe4faebbd1bfcf2098fb8f32a1da (patch)
tree7c902cd7dc0263f65980a6b5b11ce8d8a5890623 /game.ml
parentf4e6664361f2eaf10f2bd3c81916acc57c547037 (diff)
downloadicfp2011-43f6aa6e9b6dfe4faebbd1bfcf2098fb8f32a1da.tar.gz
Add exception filtering in left and right apply
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 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;;