aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--game.ml247
1 files changed, 133 insertions, 114 deletions
diff --git a/game.ml b/game.ml
index 25eb096..aa8c478 100644
--- a/game.ml
+++ b/game.ml
@@ -4,9 +4,9 @@ type lambda =
|Const of int
|Lambda of (lambda -> lambda);;
-let unfold l = match l with
- | Lambda f -> f
- | _ -> raise( Rule_error "wrong unfolding")
+let unfold x = match x with
+ | Lambda y -> y
+ | _ -> raise( Rule_error "wrong unfolding")
let id = Lambda(fun x -> x)
@@ -24,125 +24,145 @@ let card_count = ref(0)
let proponent = ref player0
let opponent = ref player1
-let zero = count:=!count+1;Const 0
-let succ = Lambda(fun a -> match a with
- |Const n -> if n < 65535 then count:=!count+1; Const (n+1) else count:=!count+1; Const n
- |_ -> raise( Rule_error "not an integer"))
-let dbl = Lambda(fun a -> match a with
- |Const n -> if n<32768 then count:=!count+1; Const(2*n) else count:=!count+1; Const n
- |_ -> raise( Rule_error "not an integer"))
-let get = Lambda(fun a -> match a with
- |(Const i) -> if !proponent.(i).vitality > 0 then !proponent.(i).field else raise( Rule_error "not a valid slot number")
- |_ -> raise( Rule_error "not an integer" ))
+let increase card_count =
+ if !card_count>=1000 then
+ raise( Rule_error "apply limit exceeded")
+ else
+ card_count:=!card_count+1
-let put = Lambda(fun x -> id)
-let s = Lambda(fun f -> Lambda(fun g -> Lambda(fun x -> (f @ x) @ (g @ x))))
-let k = Lambda(fun x -> Lambda(fun y -> x))
+let zero = increase card_count;Const 0
+let succ = increase card_count;
+ Lambda(fun a -> match a with
+ | Const n -> if n < 65535 then Const (n+1) else Const n
+ | _ -> raise( Rule_error "not an integer"))
+let dbl = increase card_count;
+ Lambda(fun a -> match a with
+ | Const n -> if n < 32768 then Const(2*n) else Const n
+ | _ -> raise( Rule_error "not an integer"))
+let get = increase card_count;
+ Lambda(fun a -> match a with
+ | (Const i) -> if !proponent.(i).vitality > 0 then !proponent.(i).field else raise( Rule_error "not a valid slot number")
+ | _ -> raise( Rule_error "not an integer" ))
-let inc = Lambda(fun a -> match a with
- |Const i -> let v = !proponent.(i) .vitality in
- if ( v < 65535 ) & ( v > 0 ) then
- !proponent.(i).vitality <- v + 1;
- id
- |_ -> raise( Rule_error "not an integer"))
+let put = increase card_count;Lambda(fun x -> id)
+let s = increase card_count;Lambda(fun f -> Lambda(fun g -> Lambda(fun x -> (f @ x) @ (g @ x))))
+let k = increase card_count;Lambda(fun x -> Lambda(fun y -> x))
-let inc_bis = Lambda(fun a -> match a with
- |Const i -> let v = !proponent.(i) .vitality in
- if ( v < 65535 ) & ( v > 0 ) then
- !proponent.(i).vitality <- v - 1;
- id
- |_ -> raise( Rule_error "not an integer"))
+let inc = increase card_count;
+ Lambda(fun a -> match a with
+ | Const i -> let v = !proponent.(i) .vitality in
+ if ( v < 65535 ) & ( v > 0 ) then
+ !proponent.(i).vitality <- v + 1;
+ id
+ | _ -> raise( Rule_error "not an integer"))
+let inc_bis = increase card_count;
+ Lambda(fun a -> match a with
+ | Const i -> let v = !proponent.(i) .vitality in
+ if ( v < 65535 ) & ( v > 0 ) then
+ !proponent.(i).vitality <- v - 1;
+ id
+ | _ -> raise( Rule_error "not an integer"))
-let dec = Lambda(fun a -> match a with
- | Const i -> let v = !opponent.(255-i).vitality in
- if v > 0 then
- !opponent.(255-1).vitality <- v - 1;
- id
- | _ -> raise( Rule_error "not an integer"))
-let dec_bis = Lambda(fun a -> match a with
- | (Const i) -> let v = !opponent.(255-i).vitality in
+let dec = increase card_count;
+ Lambda(fun a -> match a with
+ | Const i -> let v = !opponent.(255-i).vitality in
if v > 0 then
- !opponent.(255-1).vitality <- v + 1;
+ !opponent.(255-1).vitality <- v - 1;
id
- | _ -> raise( Rule_error "not an integer"))
+ | _ -> raise( Rule_error "not an integer"))
-let attack = Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
- | Const i, Const j, Const n ->
- let v = !proponent.(i).vitality in
- if v - n > 0 then
- !proponent.(i).vitality <- v - n
- else
- raise( Rule_error "not enough life left");
- let w = !opponent.(255-j).vitality in
- if w > 0 then
- !opponent.(255-j).vitality <- max 0 (w - 9/10 *n);
- id
- |_ -> raise( Rule_error "not an integer"))))
+let dec_bis = increase card_count;
+ Lambda(fun a -> match a with
+ | (Const i) -> let v = !opponent.(255-i).vitality in
+ if v > 0 then
+ !opponent.(255-1).vitality <- v + 1;
+ id
+ | _ -> raise( Rule_error "not an integer"))
-let attack_bis = Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
- | Const i, Const j, Const n ->
- let v = !proponent.(i).vitality in
- if v - n > 0 then
- !proponent.(i).vitality <- v - n
- else
- raise( Rule_error "not enought life left");
- let w = !opponent.(255-j).vitality in
- if w > 0 then
- !opponent.(255-j).vitality <- min 65535 (w + 9/10 *n);
- id
- | _ -> raise( Rule_error "not an integer"))))
+let attack = increase card_count;
+ Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
+ | Const i, Const j, Const n ->
+ let v = !proponent.(i).vitality in
+ if v - n > 0 then
+ !proponent.(i).vitality <- v - n
+ else
+ raise( Rule_error "not enough life left");
+ let w = !opponent.(255-j).vitality in
+ if w > 0 then
+ !opponent.(255-j).vitality <- max 0 (w - 9/10 *n);
+ id
+ | _ -> raise( Rule_error "not an integer"))))
-let help = Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
- | Const i, Const j, Const n ->
- let v = !proponent.(i).vitality in
- if v - n > 0 then
- !proponent.(i).vitality <- v - n
- else
+let attack_bis = increase card_count;
+ Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
+ | Const i, Const j, Const n ->
+ let v = !proponent.(i).vitality in
+ if v - n > 0 then
+ !proponent.(i).vitality <- v - n
+ else
+ raise( Rule_error "not enought life left");
+ let w = !opponent.(255-j).vitality in
+ if w > 0 then
+ !opponent.(255-j).vitality <- min 65535 (w + 9/10 *n);
+ id
+ | _ -> raise( Rule_error "not an integer"))))
+
+let help = increase card_count;
+ Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
+ | Const i, Const j, Const n ->
+ let v = !proponent.(i).vitality in
+ if v - n > 0 then
+ !proponent.(i).vitality <- v - n
+ else
+ raise( Rule_error "not enough life left");
+ let w = !proponent.(j).vitality in
+ if w > 0 then
+ !proponent.(j).vitality <- max (w - n*11/10) 0;
+ id
+ | _ -> raise( Rule_error "not an integer"))))
+
+let help_bis = increase card_count;
+ Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
+ | Const i, Const j, Const n ->
+ let v = !proponent.(i).vitality in
+ if v - n > 0 then
+ !proponent.(i).vitality <- v - n
+ else
raise( Rule_error "not enough life left");
- let w = !proponent.(j).vitality in
- if w > 0 then
- !proponent.(j).vitality <- max (w - n*11/10) 0;
- id
- | _ -> raise( Rule_error "not an integer"))))
+ let w = !proponent.(j).vitality in
+ if w > 0 then
+ !proponent.(j).vitality <- min (w + n*11/10) 65535;
+ id
+ | _ -> raise( Rule_error "not an integer"))))
-let help_bis = Lambda(fun a -> Lambda(fun b -> Lambda(fun c -> match a, b, c with
- | Const i, Const j, Const n ->
- let v = !proponent.(i).vitality in
- if v - n > 0 then
- !proponent.(i).vitality <- v - n
- else
- raise( Rule_error "not enough life left");
- let w = !proponent.(j).vitality in
- if w > 0 then
- !proponent.(j).vitality <- min (w + n*11/10) 65535;
- id
- | _ -> raise( Rule_error "not an integer"))))
-
-let copy = Lambda(fun a -> match a with
+let copy = increase card_count;
+ Lambda(fun a -> match a with
| Const i -> !opponent.(i).field
| _ -> raise( Rule_error "not an integer"))
-
-let revive = Lambda(fun a -> match a with
- | Const i -> let v = !proponent.(i).vitality in
- if v <= 0 then
- !proponent.(i).vitality <- 1;
- id
- | _ -> raise( Rule_error "not an integer"))
-
-let zombie = Lambda(fun a -> match a with
- | Const i -> Lambda(fun x ->
- let v = !opponent.(255-i).vitality in
- if v <= 0 then
- begin
- !opponent.(255-i).field <- x;
- !opponent.(255-i).vitality <- -1
- end
- else
- raise( Rule_error "slot is alive");
- id)
- |_ -> raise( Rule_error "not an integer"))
+
+let revive = increase card_count;
+ Lambda(fun a -> match a with
+ | Const i -> let v = !proponent.(i).vitality in
+ if v <= 0 then
+ !proponent.(i).vitality <- 1;
+ id
+ | _ -> raise( Rule_error "not an integer"))
+
+let zombie = increase card_count;
+ Lambda(fun a -> match a with
+ | Const i -> Lambda(fun x ->
+ let v = !opponent.(255-i).vitality in
+ if v <= 0 then
+ begin
+ !opponent.(255-i).field <- x;
+ !opponent.(255-i).vitality <- -1
+ end
+ else
+ raise( Rule_error "slot is alive");
+ id)
+ | _ -> raise( Rule_error "not an integer"))
type card =
| I
@@ -215,7 +235,6 @@ let cardfun_of_card_bis c = match c with
| Revive -> revive
| Zombie -> zombie
-
let left_apply player card number =
if player = 0 then begin
proponent := player0;
@@ -227,11 +246,11 @@ let left_apply player card number =
opponent := player0
end;
let slot = !proponent.(number) in
- slot.field <-
+ slot.field <-
try
(cardfun_of_card card) @ slot.field
with
- | Rule_error _ | Invalid_argument _ -> (*TODO reset counter*) id
+ | Rule_error _ | Invalid_argument _ -> card_count:=0; id
let right_apply player card number =
if player = 0 then begin
@@ -246,9 +265,9 @@ let right_apply player card number =
let slot = !proponent.(number) in
slot.field <-
try
- (cardfun_of_card card) @ slot.field
+ slot.field @ (cardfun_of_card card)
with
- | Rule_error _ | Invalid_argument _ -> (*TODO reset counter*) id
+ | Rule_error _ | Invalid_argument _ -> card_count:=0; id
let right_apply_bis player card number =
if player = 0 then begin
@@ -263,9 +282,9 @@ let right_apply_bis player card number =
let slot = !proponent.(number) in
slot.field <-
try
- (cardfun_of_card card) @ slot.field
+ slot.field @ (cardfun_of_card_bis card)
with
- | Rule_error _ | Invalid_argument _ -> (*reset counter*) id
+ | Rule_error _ | Invalid_argument _ -> card_count:=0; id
(*
right_apply !proponent.(0) Help;;