blob: fafc09af37163c59e8d01530f1224431217615c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
open Game
let _ = Random.self_init()
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, 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
| 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"
)
let strategy = Array.make 256 false
(* important print newline to flush output *)
let play_move () =
(*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 =
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
|