diff options
Diffstat (limited to 'judge/dummy_player.ml')
-rw-r--r-- | judge/dummy_player.ml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/judge/dummy_player.ml b/judge/dummy_player.ml new file mode 100644 index 0000000..fe19b48 --- /dev/null +++ b/judge/dummy_player.ml @@ -0,0 +1,42 @@ + + +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; + print_string "Play this_is_a_word\n"; + 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 "") + ]; |