Mercurial > repos > icfp2012
annotate src/sim.tp @ 28:7a274d6026c8
Use built-in true and false.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 14 Jul 2012 19:33:35 -0700 |
parents | a224dc43877f |
children | d9f1a063a466 |
rev | line source |
---|---|
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
1 { |
12 | 2 eachbyte <- :string action { |
3 strLen <- string byte_length: | |
4 index <- 0 | |
5 while: {index < strLen} do: { | |
6 element <- (string byte: index) | |
7 action: index element | |
8 index <- index + 1 | |
9 } | |
10 } | |
11 | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
12 debugLog <- :str { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
13 os write: 2 str |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
14 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
15 |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
16 makeCellTypes <- { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
17 allid <- #[] |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
18 allobj <- #[] |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
19 new <- :idStr { |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
20 ret <- #{ |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
21 id <- (idStr byte: 0) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
22 str <- idStr |
10 | 23 isrobot <- { false } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
24 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
25 allobj append: ret |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
26 allid append: (ret id) |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
27 ret |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
28 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
29 #{ |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
30 find <- :id { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
31 if: id = ("R" byte: 0) { robot: } else: { |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
32 index <- 0 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
33 while: { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
34 if: index < (allid length) { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
35 (allid get: index) != id |
23 | 36 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
37 } do: { |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
38 index <- index + 1 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
39 } |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
40 if: index < (allid length) { |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
41 allobj get: index |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
42 } else: { |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
43 empty |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
44 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
45 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
46 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
47 wall <- new: "#" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
48 empty <- new: " " |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
49 earth <- new: "." |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
50 rock <- new: "*" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
51 lambda <- new: "\\" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
52 closedlift <- new: "L" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
53 openlift <- new: "O" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
54 newline <- new: "\n" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
55 robot <- { |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
56 #{ |
23 | 57 id <- ("R" byte: 0) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
58 str <- "R" |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
59 isrobot <- { true } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
60 heldBreath <- 0 |
23 | 61 x <- 0 |
62 y <- 0 | |
63 move <- :cmd mine { | |
64 writeMove <- :xPrime yPrime { | |
65 mine setCell: xPrime yPrime self | |
66 mine setCell: x y empty | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
67 x <- xPrime |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
68 y <- yPrime |
23 | 69 } |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
70 writeMove: x (y + 1) |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
71 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
72 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
73 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
74 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
75 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
76 #{ |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
77 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
78 cellTypes <- makeCellTypes: |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
79 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
80 state <- #{ |
6 | 81 new <- :in_grid in_width in_height { |
10 | 82 nextGrid <- #[] |
83 robot <- false | |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
84 endreached <- false |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
85 ret <- #{ |
8 | 86 grid <- in_grid |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
87 width <- in_width |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
88 height <- in_height |
23 | 89 calcIndex <- :x y { x + y * width } |
90 calcX <- :index {index % width} | |
91 calcY <- :index {index / width} | |
10 | 92 setCell <- :x y val { |
23 | 93 grid set: (calcIndex: x y) val |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
94 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
95 getCell <- :x y { |
23 | 96 grid get: (calcIndex: x y) |
97 } | |
98 updatePos <- :obj Index { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
99 obj x!: (calcX: Index) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
100 obj y!: (calcY: Index) |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
101 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
102 water <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
103 flooding <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
104 waterproof <- 10 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
105 collected <- 0 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
106 moves <- 0 |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
107 ended <- {endreached} |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
108 doUpdate <- { |
12 | 109 true |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
110 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
111 advance <- :roboCmd { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
112 endreached <- roboCmd = "A" |
23 | 113 robot move: roboCmd self |
6 | 114 moves <- moves + 1 |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
115 doUpdate: |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
116 self |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
117 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
118 printGrid <- { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
119 grid foreach: :index value { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
120 os write: 2 (value str) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
121 if: index % width = width - 1 { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
122 os write: 2 "\n" |
23 | 123 } |
124 } | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
125 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
126 } |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
127 foreach: in_grid :index el{ |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
128 nextGrid append: el |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
129 if: (el isrobot) { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
130 robot <- el |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
131 ret updatePos: robot index |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
132 } else: { true } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
133 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
134 ret |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
135 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
136 fromStr <- :str { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
137 strLen <- str byte_length: |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
138 maxCol <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
139 col <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
140 rows <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
141 nl <- (cellTypes newline) id |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
142 blank <- cellTypes empty |
12 | 143 eachbyte: str :index element { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
144 if: element = nl { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
145 maxCol <- if: col > maxCol {col} else: {maxCol} |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
146 col <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
147 rows <- rows + 1 |
10 | 148 } else: { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
149 col <- col + 1 |
10 | 150 } |
151 } | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
152 col <- 0 |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
153 grid <- #[] |
12 | 154 eachbyte: str :index element { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
155 if: element = nl { |
10 | 156 // add spaces |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
157 while: { col < maxCol } do: { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
158 grid append: blank |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
159 col <- col + 1 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
160 } |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
161 col <- 0 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
162 } else: { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
163 grid append: (cellTypes find: element) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
164 col <- col + 1 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
165 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
166 } |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
167 new: grid maxCol rows |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
168 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
169 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
170 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
171 testMoves <- { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
172 myStep <- 0 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
173 { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
174 myStep <- myStep + 1 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
175 if: myStep > 5 {"A"} else: {"W"} |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
176 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
177 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
178 |
20
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
179 readFd <- :fd { |
8 | 180 if: fd < 0 { "" } else: { |
181 cur <- "" | |
182 part <- "" | |
183 while: { | |
184 part <- os read: fd 128 | |
185 part != "" | |
186 } do: { | |
187 cur <- cur . part | |
188 } | |
189 cur | |
190 } | |
191 } | |
192 | |
20
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
193 readFile <- :path { |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
194 fd <- os open: path (os O_RDONLY) |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
195 out <- readFd: fd |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
196 os close: fd |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
197 out |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
198 } |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
199 |
8 | 200 getMove <- { |
201 os read: 0 1 | |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
202 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
203 |
8 | 204 main <- :args { |
205 if: (args length) < 2 { | |
206 print: "usage: sim filename\n" | |
207 } else: { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
208 verbose <- true |
8 | 209 text <- readFile: (args get: 1) |
14 | 210 print: text |
17 | 211 os close: 1 |
8 | 212 simState <- state fromStr: text |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
213 derp <- simState ended: |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
214 while: { if: (simState ended: ) {false} else: {true} } do: { |
8 | 215 simState advance: (getMove: ) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
216 if: verbose { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
217 simState printGrid |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
218 } |
8 | 219 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
220 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
221 } |
8 | 222 |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
223 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
224 } |