File tree Expand file tree Collapse file tree 2 files changed +79
-1
lines changed
branches/snap-stage3/src/test/run-pass Expand file tree Collapse file tree 2 files changed +79
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: cfc78694cba2366b413750db17b54b767792beaf
4
+ refs/heads/snap-stage3: b0cf106e9abd5960fe95d7e44638a89861dbf8af
5
5
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Original file line number Diff line number Diff line change
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( ) { }
You can’t perform that action at this time.
0 commit comments