blob: 09b13aa4ee80cbd8813fe0aead91f900c1c72cc7 (
plain) (
blame)
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
|
let words = [|
"banane"; "hippopotame"; "povrion";
"pourquoi???"; "un ange passe"; "television";
"ceci n'est pas..."; "environ 12"; "septante";
"Philipp Glass"; "nyaaa"; "tu crois ?"; "hallo";
"mange ton muesli"; "va te coucher"; "MAMAAAAN!!";
"meme pas peur"; "python FTW"; "savanne!";
"le lion mange le lion"; "canard"; "tennis";
"sauve qui peut!"; "bref..."; "j'approuve.";
|]
let expect mgs =
let l = read_line () in
begin try
let (s, f) = List.find
(fun (s, _) ->
String.length l >= String.length s
&& String.sub l 0 (String.length s) = s)
mgs
in f (String.sub l (String.length s)
(String.length l - String.length s))
with
Not_found ->
Format.eprintf "Unexpected '%s'.@." l;
exit 1
end
let finished _ =
print_string "Fair enough\n"
let rec turn _ =
expect [
"Your turn",
(fun _ ->
if Random.int 2 = 0 then Unix.sleep 1;
Format.printf "Play %s@."
words.(Random.int (Array.length words));
expect [ "OK", turn ]);
"Play ", turn;
"Tie", finished;
"You win", finished;
"You lose", finished;
"Eliminated", finished
]
let () =
Random.self_init ();
expect [
"Hello dummy_game",
(fun _ -> print_string "Hello dummy_game\n";
turn "")
];
|