-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestseq_driver.rs
50 lines (40 loc) · 1.1 KB
/
testseq_driver.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
46
47
48
49
50
import io::reader_util;
import state::*;
fn main(args: ~[str]) {
import result::*;
let map;
let moveseq;
if (args.len() < 3) {
fail #fmt("%s: usage: %s board moveseq", args[0], args[0]);
}
alt (io::read_whole_file_str(args[1])) {
ok (mm) { map = mm; }
err(msg) { fail msg; }
}
moveseq = args[2];
let mut state = state::read_board(io::str_reader(map));
signal::init();
do str::chars_iter(moveseq) |c| {
let move = alt c {
'R' { state::R }
'L' { state::L }
'U' { state::U }
'D' { state::D }
'A' { state::A }
'W' { state::W }
_ { fail }
};
alt state.step(move, false) {
state::stepped(s) { state = state::extract_step_result(s); }
state::endgame(_, points) {
io::print(#fmt("%d", points));
libc::exit(0)
}
_ { fail }
}
}
alt state.step(state::A, false) {
state::endgame(_, points) { io::print(#fmt("%d", points)); }
_ { fail }
}
}