-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerio.sml
49 lines (44 loc) · 1.63 KB
/
playerio.sml
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
structure PlayerIO = struct
open LTGParse
fun err x = TextIO.output (TextIO.stdErr, x ^ "\n")
fun debug x = () (* TextIO.output (TextIO.stdErr, x ^ "\n") *)
val x = ref ""
fun continue (turn, state) =
let in
debug ("Sending in player " ^ !x)
; send TextIO.stdOut turn
; debug ("Receiving in player " ^ !x)
; continue (Player.round (rcv TextIO.stdIn, state))
end
(* Start *)
val () =
let
val args = Params.docommandline ()
val seed =
case args of
[ "0" ] => (debug "Player 0"
; x := "0"
; Player.init NONE)
| [ "1" ] => (debug "Player 1"
; x := "1"
; Player.init (SOME (rcv TextIO.stdIn)))
| [] =>
(err ("No main argument given!")
; err ("Usage: " ^ CommandLine.name () ^ " {0, 1}")
; err ("0 is the first player, 1 is the second player")
; OS.Process.exit OS.Process.failure)
| [ s ] =>
(err ("Bad argument: " ^ s)
; err ("Usage: " ^ CommandLine.name () ^ " {0, 1}")
; err ("0 is the first player, 1 is the second player")
; OS.Process.exit OS.Process.failure)
| _ =>
(err ("Bad argument or too many arguments given!")
; err ("Usage: " ^ CommandLine.name () ^ " {0, 1}")
; err ("0 is the first player, 1 is the second player")
; OS.Process.exit OS.Process.failure)
in
continue seed
end handle LTGIO s => (err ("Error: " ^ s)
; OS.Process.exit OS.Process.failure)
end