Mercurial > repos > icfp2012
comparison src/sim.tp @ 44:0c09730c173e
Robot works on simple maps now
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jul 2012 17:21:27 -0700 |
parents | 20327ae2120b |
children | 9f1ca5ba2684 |
comparison
equal
deleted
inserted
replaced
41:20327ae2120b | 44:0c09730c173e |
---|---|
79 x <- xPrime | 79 x <- xPrime |
80 y <- yPrime | 80 y <- yPrime |
81 } | 81 } |
82 | 82 |
83 consequenceOf <- :cur { | 83 consequenceOf <- :cur { |
84 if: (cur eq: lambda) {collected <- collected + 1} | 84 if: (cur eq: lambda) { |
85 if: (cur eq: openLift) {mine succeeded!: true} | 85 collected <- collected + 1 |
86 mine addPoints: 25 | |
87 } | |
88 if: (cur eq: openLift) {mine succeeded!} | |
86 } | 89 } |
87 | 90 |
88 destination <- mine getCell: xPrime yPrime | 91 destination <- mine getCell: xPrime yPrime |
89 if: (destination navigable: ) { | 92 if: (destination navigable: ) { |
90 consequenceOf: destination | 93 consequenceOf: destination |
99 } | 102 } |
100 } | 103 } |
101 } | 104 } |
102 | 105 |
103 } | 106 } |
107 clone <- { | |
108 myclone <- robot | |
109 myclone collected!: collected | |
110 myclone heldBreath!: heldBreath | |
111 myclone razors!: razors | |
112 myclone | |
113 } | |
104 } | 114 } |
105 commands set: "L" {ret move: (-1) 0 } | 115 commands set: "L" {ret move: (-1) 0 } |
106 commands set: "R" {ret move: 1 0 } | 116 commands set: "R" {ret move: 1 0 } |
107 commands set: "U" {ret move: 0 1 } | 117 commands set: "U" {ret move: 0 1 } |
108 commands set: "D" {ret move: 0 (-1) } | 118 commands set: "D" {ret move: 0 (-1) } |
118 state <- #{ | 128 state <- #{ |
119 new <- :in_grid in_width in_height { | 129 new <- :in_grid in_width in_height { |
120 nextGrid <- #[] | 130 nextGrid <- #[] |
121 _robot <- null | 131 _robot <- null |
122 endreached <- false | 132 endreached <- false |
123 _lambdaCount <- 0 | 133 |
124 _succeeded <- false | 134 _succeeded <- false |
125 ret <- #{ | 135 ret <- #{ |
126 grid <- in_grid | 136 grid <- in_grid |
127 width <- in_width | 137 width <- in_width |
128 height <- in_height | 138 height <- in_height |
178 getRobot <- { _robot } | 188 getRobot <- { _robot } |
179 updatePos <- :obj Index { | 189 updatePos <- :obj Index { |
180 obj x!: (calcX: Index) | 190 obj x!: (calcX: Index) |
181 obj y!: (calcY: Index) | 191 obj y!: (calcY: Index) |
182 } | 192 } |
183 lambdaCount <- {_lambdaCount} | 193 lambdaCount <- 0 |
184 water <- 0 | 194 water <- 0 |
185 flooding <- 0 | 195 flooding <- 0 |
186 waterproof <- 10 | 196 waterproof <- 10 |
187 moves <- 0 | 197 moves <- #[] |
198 score <- 0 | |
199 addPoints <- :points { score <- score + points } | |
188 ended <- {endreached} | 200 ended <- {endreached} |
189 succeeded <- {_succeeded} | 201 succeeded <- {_succeeded} |
190 succeeded! <- :newval { | 202 succeeded! <- { |
191 endreached <- newval | 203 endreached <- true |
192 _succeeded <- newval | 204 _succeeded <- true |
205 addPoints: lambdaCount * 50 | |
193 } | 206 } |
194 doUpdate <- { | 207 doUpdate <- { |
195 foreach: grid :index value { | 208 foreach: grid :index value { |
196 if: (value eq: (cellTypes rock)) { | 209 if: (value eq: (cellTypes rock)) { |
197 x <- calcX: index | 210 x <- calcX: index |
201 setCell: x y (cellTypes empty) | 214 setCell: x y (cellTypes empty) |
202 setCell: x (y - 1) value | 215 setCell: x (y - 1) value |
203 } | 216 } |
204 } else: { | 217 } else: { |
205 if: (value eq: (cellTypes closedLift)) { | 218 if: (value eq: (cellTypes closedLift)) { |
206 if: (_robot collected) = _lambdaCount { | 219 if: (_robot collected) = lambdaCount { |
207 grid set: index (cellTypes openLift) | 220 grid set: index (cellTypes openLift) |
208 } | 221 } |
209 } | 222 } |
210 } | 223 } |
211 } | 224 } |
212 } | 225 } |
213 advance <- :roboCmd { | 226 advance <- :roboCmd { |
214 endreached <- roboCmd = "A" | 227 if: roboCmd = "A" { |
228 endreached <- true | |
229 moves append: roboCmd | |
230 addPoints: (_robot collected) * 25 | |
231 } | |
232 | |
215 if: (not: endreached) { | 233 if: (not: endreached) { |
216 _robot doCmd: roboCmd | 234 _robot doCmd: roboCmd |
217 moves <- moves + 1 | 235 score <- score - 1 |
236 moves append: roboCmd | |
218 doUpdate: | 237 doUpdate: |
219 } | 238 } |
220 self | 239 self |
221 } | 240 } |
222 printGrid <- { | 241 printGrid <- { |
230 col <- 0 | 249 col <- 0 |
231 cur <- cur - (width + width) | 250 cur <- cur - (width + width) |
232 os write: 2 "\n" | 251 os write: 2 "\n" |
233 } | 252 } |
234 } | 253 } |
254 os write: 2 "score: " . score . "\n" | |
255 os write: 2 "collected: " . (_robot collected) . "\n" | |
256 os write: 2 "moves: " | |
257 foreach: moves :idx m { | |
258 os write: 2 m | |
259 } | |
260 os write: 2 "\n" | |
235 } | 261 } |
236 clone <- { | 262 clone <- { |
237 cgrid <- #[] | 263 cgrid <- #[] |
238 foreach: grid :idx el { | 264 foreach: grid :idx el { |
239 if: (el isrobot) { | 265 if: (el isrobot) { |
240 cgrid append: (cellTypes robot) | 266 cgrid append: (el clone) |
241 } else: { | 267 } else: { |
242 cgrid append: el | 268 cgrid append: el |
243 } | 269 } |
244 } | 270 } |
245 myclone <- state new: cgrid width height | 271 myclone <- state new: cgrid width height |
246 myclone water!: water | 272 myclone water!: water |
247 myclone flooding!: flooding | 273 myclone flooding!: flooding |
248 myclone waterproof!: waterproof | 274 myclone waterproof!: waterproof |
249 myclone moves!: moves | 275 movesclone <- #[] |
276 foreach: moves :idx el { | |
277 movesclone append: el | |
278 } | |
279 myclone moves!: movesclone | |
280 myclone score!: score | |
281 myclone lambdaCount!: lambdaCount | |
250 myclone | 282 myclone |
251 } | 283 } |
252 } | 284 } |
253 foreach: in_grid :index el{ | 285 foreach: in_grid :index el{ |
254 nextGrid append: el | 286 nextGrid append: el |
256 _robot <- el | 288 _robot <- el |
257 _robot mine!: ret | 289 _robot mine!: ret |
258 ret updatePos: _robot index | 290 ret updatePos: _robot index |
259 } else: { | 291 } else: { |
260 if: (el eq: (cellTypes lambda)) { | 292 if: (el eq: (cellTypes lambda)) { |
261 _lambdaCount <- _lambdaCount + 1 | 293 ret lambdaCount!: (ret lambdaCount) + 1 |
262 } | 294 } |
263 } | 295 } |
264 | 296 |
265 | 297 |
266 // adding a 'new' method to robot and doing this instead | 298 // adding a 'new' method to robot and doing this instead |