comparison code/dotScanner.lm @ 34:968705fcb4c6

Initial stab at taking fruit and ghost state into account
author Michael Pavone <pavone@retrodev.com>
date Sat, 26 Jul 2014 01:41:24 -0700
parents 934d03d42a7e
children 8c26981aae8c
comparison
equal deleted inserted replaced
32:934d03d42a7e 34:968705fcb4c6
258 if: (grid: grid inBounds?: myLoc) { 258 if: (grid: grid inBounds?: myLoc) {
259 if: (grid: visited get: myLoc) { 259 if: (grid: visited get: myLoc) {
260 } else: { 260 } else: {
261 atpos <- grid: grid get: myLoc 261 atpos <- grid: grid get: myLoc
262 if: (atpos = 2) + (atpos = 3) + (atpos = 4) { 262 if: (atpos = 2) + (atpos = 3) + (atpos = 4) {
263 //pellet, power pellet, fruit
263 ret <- #[1 (reverse: path)] 264 ret <- #[1 (reverse: path)]
264 } else: { 265 } else: {
265 visited <- grid: visited set: myLoc to: 1 266 visited <- grid: visited set: myLoc to: 1
266 if: atpos { 267 if: atpos {
268 //empty space
267 move <- 0 269 move <- 0
268 while: { move < 4 } do: { 270 while: { move < 4 } do: {
269 ret <- (makeContClos: grid (calcPos: move myLoc) move | path) | ret 271 ret <- (makeContClos: grid (calcPos: move myLoc) move | path) | ret
270 move <- move + 1 272 move <- move + 1
271 } 273 }
278 ret 280 ret
279 } 281 }
280 } 282 }
281 283
282 step <- :myState world { 284 step <- :myState world {
283 grid <- makeTree: (map: (world value) :row { makeTree: row })
284 lmState <- (world tail) value 285 lmState <- (world tail) value
285 myLoc <- (lmState tail) value 286 myLoc <- (lmState tail) value
287 ghostState <- ((world tail) tail) value
288 fruitState <- ((world tail) tail) tail
286 289
290 grid <- makeTree: (map: (world value) :row {
291 if: fruitState >= 127 {
292 } else: {
293 row <- map: row :el {
294 //remove fruit if it is not enabled
295 if: el = 4 {
296 el <- 1
297 } else: {}
298 el
299 }
300 }
301 makeTree: row
302 })
303 grid <- fold: ghostState grid with: :acc ghost {
304 vitality <- ghost value
305 loc <- (ghost tail) value
306 if: vitality = 1 {
307 //treat fright mode ghosts as a pellet for now
308 acc <- grid: acc set: loc to: 2
309 } else: {
310 if: vitality = 0 {
311 //treat normal mode ghosts as a wall for now
312 acc <- grid: acc set: loc to: 0
313 } else: {}
314 }
315 acc
316 }
287 visited <- treeMap: grid :row { 317 visited <- treeMap: grid :row {
288 treeMap: row :el { 0 } 318 treeMap: row :el { 0 }
289 } 319 }
290 path <- advancer: [(makeContClos: grid myLoc [])] 320 path <- advancer: [(makeContClos: grid myLoc [])]
291 #[0 (path value)] 321 #[0 (path value)]
292 } 322 }
293 323
294 main <- :initWorld ghostCode { 324 main <- :initWorld ghostCode {
295 /* 325 /*
296 print: (step: 0 #[ 326 print: (step: 0 #[
327 //grid
297 [ 328 [
298 [0 0 0 0] 329 [0 0 0 0]
299 [0 2 2 0] 330 [0 2 2 0]
300 [0 1 0 0] 331 [0 1 0 0]
301 [0 0 0 0] 332 [0 0 0 0]
302 ] 333 ]
334 //lmstate
303 #[0 #[1 2] 2 3 0] 335 #[0 #[1 2] 2 3 0]
336 //ghost state
304 [] 337 []
338 //fruit state
305 0 339 0
306 ]) */ 340 ]) */
307 #[0 step] 341 #[0 step]
308 } 342 }
309 } 343 }