-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaprun.rs
45 lines (44 loc) · 1.46 KB
/
maprun.rs
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
import io::{reader,reader_util,writer_util};
import state::{state, cont, died, toolong, won};
fn main(argv: ~[str]) {
let in = io::stdin();
let out = io::stdout();
let mut lines = ~[];
let fh = io::file_reader(argv[1]).get();
for fh.each_line |line| { lines += ~[copy line]; }
let mut state = state::parse(lines);
loop {
for state.print().each |line| { out.write_line(line); }
out.write_line(#fmt("Lambdas: %?/%? Rolling: %?",
state.lgot, state.c.lamb, state.rolling));
out.write_line("-- ");
let ch : char;
let res = if in.eof() {
none
} else if {ch = in.read_char(); ch == 'A'} {
none
} else {
alt state::cmd_opt_of_char(ch) {
none { again }
some(cmd) {
let (res,nstate) = state.step(cmd);
state = nstate;
some(res)
}
}
};
if (res != some(cont)) {
for state.print().each |line| { out.write_line(line); }
let msg = alt res {
none { "Successfully aborted." }
some(died) { "YOU DIED." }
some(toolong) { "You took too long." }
some(won) { "You won!" }
some(cont) { fail }
};
out.write_line(#fmt("*** %s\nScore: %?", msg,
state.score(res)));
break;
}
}
}