Skip to content

Commit c1069db

Browse files
committed
---
yaml --- r: 20855 b: refs/heads/snap-stage3 c: b0cf106 h: refs/heads/master i: 20853: 05ed00d 20851: 8977a05 20847: 8079c71 v: v3
1 parent b4f1a37 commit c1069db

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: cfc78694cba2366b413750db17b54b767792beaf
4+
refs/heads/snap-stage3: b0cf106e9abd5960fe95d7e44638a89861dbf8af
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/// Map representation
2+
3+
use std;
4+
5+
import io::reader_util;
6+
7+
enum square {
8+
bot,
9+
wall,
10+
rock,
11+
lambda,
12+
closed_lift,
13+
open_lift,
14+
earth,
15+
empty
16+
}
17+
18+
impl of to_str::to_str for square {
19+
fn to_str() -> ~str {
20+
alt self {
21+
bot { ~"R" }
22+
wall { ~"#" }
23+
rock { ~"*" }
24+
lambda { ~"\\" }
25+
closed_lift { ~"L" }
26+
open_lift { ~"O" }
27+
earth { ~"." }
28+
empty { ~" " }
29+
}
30+
}
31+
}
32+
33+
fn square_from_char(c: char) -> square {
34+
alt c {
35+
'R' { bot }
36+
'#' { wall }
37+
'*' { rock }
38+
'\\' { lambda }
39+
'L' { closed_lift }
40+
'O' { open_lift }
41+
'.' { earth }
42+
' ' { empty }
43+
_ {
44+
#error("invalid square: %?", c);
45+
fail
46+
}
47+
}
48+
}
49+
50+
fn read_board_grid<rdr: owned io::reader>(+in: rdr) -> ~[~[square]] {
51+
let in = in as io::reader;
52+
let mut grid = ~[];
53+
for in.each_line |line| {
54+
let mut row = ~[];
55+
for line.each_char |c| {
56+
vec::push(row, square_from_char(c))
57+
}
58+
vec::push(grid, row)
59+
}
60+
let width = grid[0].len();
61+
for grid.each |row| { assert row.len() == width }
62+
grid
63+
}
64+
65+
mod test {
66+
#[test]
67+
fn trivial_to_str() {
68+
assert lambda.to_str() == "\\"
69+
}
70+
71+
#[test]
72+
fn read_simple_board() {
73+
let s = #include_str("./maps/contest1.map");
74+
read_board_grid(io::str_reader(s));
75+
}
76+
}
77+
78+
fn main() {}

0 commit comments

Comments
 (0)