aboutsummaryrefslogtreecommitdiffstats
path: root/src/ltg.ml
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2011-06-19 17:25:59 +0200
committerThibaut Horel <thibaut.horel@gmail.com>2011-06-19 17:25:59 +0200
commit4f62d5ce18765a5f7376a508a45bdb021e5ca5b8 (patch)
tree49e8d4c2ac262f760f75422012b477a49a2b0511 /src/ltg.ml
parent338891c519fba83ccd6c61492082abfa2bb1cf22 (diff)
downloadicfp2011-4f62d5ce18765a5f7376a508a45bdb021e5ca5b8.tar.gz
Organise the directory so that it is compliant with the submission rules
Diffstat (limited to 'src/ltg.ml')
-rw-r--r--src/ltg.ml56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/ltg.ml b/src/ltg.ml
new file mode 100644
index 0000000..c3b7637
--- /dev/null
+++ b/src/ltg.ml
@@ -0,0 +1,56 @@
+open Game
+
+let _ = if Array.length Sys.argv < 2 then begin
+ Printf.printf "You must specify the player number\n";
+ exit 1
+end
+
+let me = int_of_string Sys.argv.(1)
+
+let opponent = match me with
+ | 0 -> 1
+ | 1 -> 0
+ | _ -> failwith "Wrong player_number"
+
+let read_move () = Scanf.scanf "%d\n" (fun d -> match d with
+ | 1 -> Scanf.scanf "%s\n%d\n" (fun s d ->
+ Game.left_apply opponent (card_of_string s) d)
+ | 2 -> Scanf.scanf "%d\n%s\n" (fun d s ->
+ Game.right_apply opponent (card_of_string s) d)
+ | _ -> failwith "Wrong move number"
+)
+
+(* important print newline to flush output *)
+let play_move () =
+ Printf.printf "2";
+ print_newline ();
+ Printf.printf "1";
+ print_newline();
+ Printf.printf "zero";
+ print_newline ()
+
+let automatic player =
+ let aux i slot =
+ if slot.vitality = -1 then begin
+ Game.right_apply_bis player I i;
+ slot.vitality <- 0;
+ slot.field <- id
+ end
+ in
+ if player = 0 then
+ Array.iteri aux player0
+ else
+ Array.iteri aux player1
+
+let do_round =
+ if me = 0
+ then fun () -> automatic 0; play_move (); automatic 1; read_move ()
+ else fun () -> automatic 0; read_move (); automatic 1; play_move ()
+
+
+let _ =
+ let round = ref 1 in
+ while !round <= 100000 do
+ do_round ();
+ incr round
+ done \ No newline at end of file