comparison src/sim.tp @ 48:365c83ea7658

merge and test
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 18:32:22 -0700
parents ccaecf1d6425 5d2e59cbbc7c
children 186fce0c98ee b0d89ee419c1
comparison
equal deleted inserted replaced
47:ccaecf1d6425 48:365c83ea7658
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 _ended <- false 132 _ended <- 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
181 getRobot <- { _robot } 191 getRobot <- { _robot }
182 updatePos <- :obj Index { 192 updatePos <- :obj Index {
183 obj x!: (calcX: Index) 193 obj x!: (calcX: Index)
184 obj y!: (calcY: Index) 194 obj y!: (calcY: Index)
185 } 195 }
186 lambdaCount <- {_lambdaCount} 196 lambdaCount <- 0
187 water <- 0 197 water <- 0
188 flooding <- 0 198 flooding <- 0
189 waterproof <- 10 199 waterproof <- 10
190 moves <- 0 200 moves <- #[]
201 score <- 0
202 maxScore <- { score + (lambdaCount - (_robot collected)) * 25 + lambdaCount * 50 }
203 addPoints <- :points { score <- score + points }
191 ended <- {_ended} 204 ended <- {_ended}
192 succeeded <- {_succeeded} 205 succeeded <- {_succeeded}
193 succeeded! <- :newval { 206 succeeded! <- {
194 _ended <- newval 207 _ended <- true
195 _succeeded <- newval 208 _succeeded <- true
209 addPoints: lambdaCount * 50
196 } 210 }
197 doUpdate <- { 211 doUpdate <- {
198 foreach: grid :index value { 212 foreach: grid :index value {
199 nextValue <- value 213 nextValue <- value
200 if: (value eq: (cellTypes rock)) { 214 if: (value eq: (cellTypes rock)) {
220 } else: { if: (below eq: (cellTypes lambda)) { 234 } else: { if: (below eq: (cellTypes lambda)) {
221 fallToSide: 1 235 fallToSide: 1
222 }}} // end if 236 }}} // end if
223 } else: { 237 } else: {
224 if: (value eq: (cellTypes closedLift)) { 238 if: (value eq: (cellTypes closedLift)) {
225 if: (_robot collected) = _lambdaCount { 239 if: (_robot collected) = lambdaCount {
226 nextValue <- (cellTypes openLift) 240 nextValue <- (cellTypes openLift)
227 } 241 }
228 } 242 }
229 } 243 }
230 _nextGrid set: index nextValue 244 _nextGrid set: index nextValue
235 _nextGrid <- tmp 249 _nextGrid <- tmp
236 } 250 }
237 swapGrids: 251 swapGrids:
238 } 252 }
239 advance <- :roboCmd { 253 advance <- :roboCmd {
240 _ended <- roboCmd = "A" 254 if: roboCmd = "A" {
255 _ended <- true
256 moves append: roboCmd
257 addPoints: (_robot collected) * 25
258 }
259
241 if: (not: _ended) { 260 if: (not: _ended) {
242 _robot doCmd: roboCmd 261 _robot doCmd: roboCmd
243 moves <- moves + 1 262 score <- score - 1
263 moves append: roboCmd
244 doUpdate: 264 doUpdate:
245 } 265 }
246 self 266 self
247 } 267 }
248 printGrid <- { 268 printGrid <- {
256 col <- 0 276 col <- 0
257 cur <- cur - (width + width) 277 cur <- cur - (width + width)
258 os write: 2 "\n" 278 os write: 2 "\n"
259 } 279 }
260 } 280 }
281 os write: 2 "score: " . score . "\n"
282 os write: 2 "collected: " . (_robot collected) . "\n"
283 os write: 2 "moves: "
284 foreach: moves :idx m {
285 os write: 2 m
286 }
287 os write: 2 "\n"
261 } 288 }
262 clone <- { 289 clone <- {
263 cgrid <- #[] 290 cgrid <- #[]
264 foreach: grid :idx el { 291 foreach: grid :idx el {
265 if: (el isrobot) { 292 if: (el isrobot) {
266 cgrid append: (cellTypes robot) 293 cgrid append: (el clone)
267 } else: { 294 } else: {
268 cgrid append: el 295 cgrid append: el
269 } 296 }
270 } 297 }
271 myclone <- state new: cgrid width height 298 myclone <- state new: cgrid width height
272 myclone water!: water 299 myclone water!: water
273 myclone flooding!: flooding 300 myclone flooding!: flooding
274 myclone waterproof!: waterproof 301 myclone waterproof!: waterproof
275 myclone moves!: moves 302 movesclone <- #[]
303 foreach: moves :idx el {
304 movesclone append: el
305 }
306 myclone moves!: movesclone
307 myclone score!: score
308 myclone lambdaCount!: lambdaCount
276 myclone 309 myclone
277 } 310 }
278 } 311 }
279 foreach: in_grid :index el{ 312 foreach: in_grid :index el{
280 _nextGrid append: el 313 _nextGrid append: el
282 _robot <- el 315 _robot <- el
283 _robot mine!: ret 316 _robot mine!: ret
284 ret updatePos: _robot index 317 ret updatePos: _robot index
285 } else: { 318 } else: {
286 if: (el eq: (cellTypes lambda)) { 319 if: (el eq: (cellTypes lambda)) {
287 _lambdaCount <- _lambdaCount + 1 320 ret lambdaCount!: (ret lambdaCount) + 1
288 } 321 }
289 } 322 }
290 } 323 }
291 ret 324 ret
292 } 325 }