aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2011-06-19 23:16:53 +0200
committerThibaut Horel <thibaut.horel@gmail.com>2011-06-19 23:16:53 +0200
commitcc3691c8bbba75c279d94c400be7c17b6e3f5be0 (patch)
tree29cf37cf2ff56cbef1321f77c737f0fd0ee80e17 /src
parent4f62d5ce18765a5f7376a508a45bdb021e5ca5b8 (diff)
downloadicfp2011-cc3691c8bbba75c279d94c400be7c17b6e3f5be0.tar.gz
Basic strategyHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/ltg.ml38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/ltg.ml b/src/ltg.ml
index c3b7637..fafc09a 100644
--- a/src/ltg.ml
+++ b/src/ltg.ml
@@ -1,4 +1,5 @@
open Game
+let _ = Random.self_init()
let _ = if Array.length Sys.argv < 2 then begin
Printf.printf "You must specify the player number\n";
@@ -7,9 +8,9 @@ end
let me = int_of_string Sys.argv.(1)
-let opponent = match me with
- | 0 -> 1
- | 1 -> 0
+let opponent, my_array, opponent_array = match me with
+ | 0 -> 1, player0, player1
+ | 1 -> 0, player1, player0
| _ -> failwith "Wrong player_number"
let read_move () = Scanf.scanf "%d\n" (fun d -> match d with
@@ -20,13 +21,34 @@ let read_move () = Scanf.scanf "%d\n" (fun d -> match d with
| _ -> failwith "Wrong move number"
)
+let strategy = Array.make 256 false
+
(* important print newline to flush output *)
let play_move () =
- Printf.printf "2";
- print_newline ();
- Printf.printf "1";
- print_newline();
- Printf.printf "zero";
+ (*let alive = ref 0 in
+ for i = 0 to 255 do
+ if opponent_array.(i).vitality > 0 then
+ incr alive
+ done;
+ let number = ref (1+Random.int !alive) in
+ let slot = ref 0 in
+ while !number > 0 do
+ if opponent_array.(!slot).vitality > 0 then
+ decr number;
+ incr slot;
+ done;
+ match opponent_array.(!slot).field with
+ | Lambda f ->
+ begin
+ Printf.printf "2\n%d\nzero" (!slot-1);
+ print_newline ()
+ end
+ | Const n ->
+ begin
+ Printf.printf "1\ndec\n%d" (!slot-1);
+ print_newline ()
+ end*)
+ Printf.printf "1\nI\n0";
print_newline ()
let automatic player =