Mercurial > repos > icfp2014
view code/dotScanner.lm @ 48:8b6f6e2cbf38
merge
author | William Morgan <billjunk@mrgn.org> |
---|---|
date | Sun, 27 Jul 2014 02:35:24 -0700 |
parents | d631e68a45d5 |
children | 57a4bddadd46 |
line wrap: on
line source
#{ import: [ length reverse split:at map fold:with filter flatten ] from: (module: "ll.lm") import: [ makeTree:size makeTree get:fromTree:size get:fromTree treeMap:size treeMap tree:size:update:with tree:update:with tree:set:to ] from: (module: "tree.lm") import: [ grid:get grid:update:with grid:set:to grid:inBounds? calcPos ] from: (module: "grid.lm") visited <- 0 advancer <- :continuations { notdone <- 1 while: { notdone } do: { if: (continuations isInteger?) { notdone <- 0 } else: { continuations <- fold: continuations [] with: :acc el{ ret <- acc if: notdone { ret <- el: if: (ret isInteger?) { ret <- acc } else: { if: (ret value) { notdone <- 0 ret <- (ret tail) } else: { ret <- (ret tail) | acc } } } else: {} ret } if: notdone { continuations <- flatten: continuations } else: {} } } continuations } makeContClos <- :grid myLoc path { { ret <- [] move <- 0 atpos <- 0 if: (grid: grid inBounds?: myLoc) { if: (grid: visited get: myLoc) { } else: { atpos <- grid: grid get: myLoc if: (atpos = 2) + (atpos = 3) + (atpos = 4) { //pellet, power pellet, fruit ret <- #[1 (reverse: path)] } else: { visited <- grid: visited set: myLoc to: 1 if: atpos { //empty space move <- 0 while: { move < 4 } do: { ret <- (makeContClos: grid (calcPos: move myLoc) move | path) | ret move <- move + 1 } ret <- #[0 ret] } else: {} } } } else: { } ret } } step <- :myState world { lmState <- (world tail) value myLoc <- (lmState tail) value ghostState <- ((world tail) tail) value fruitState <- ((world tail) tail) tail grid <- makeTree: (map: (world value) :row { if: fruitState >= 127 { } else: { row <- map: row :el { //remove fruit if it is not enabled if: el = 4 { el <- 1 } else: {} el } } makeTree: row }) grid <- fold: ghostState grid with: :acc ghost { vitality <- ghost value loc <- (ghost tail) value dir <- (ghost tail) tail nextloc <- 0 move <- 0 if: vitality = 1 { //treat fright mode ghosts as a pellet for now acc <- grid: acc set: loc to: 2 } else: { if: vitality = 0 { //treat normal mode ghosts as a wall for now acc <- grid: acc set: loc to: 0 while: { move < 4 } do: { nextloc <- calcPos: move loc if: (grid: acc inBounds?: nextloc) { acc <- grid: acc set: nextloc to: 0 } else: {} move <- move + 1 } } else: {} } acc } //make sure my location is marked clear even if there is a ghost nearby grid <- grid: grid set: myLoc to: 1 visited <- treeMap: grid :row { treeMap: row :el { 0 } } path <- advancer: [(makeContClos: grid myLoc [])] if: (path isInteger?) { print: 42 path <- [0] } else: {} #[0 (path value)] } main <- :initWorld ghostCode { /* print: (step: 0 #[ //grid [ [0 0 0 0] [0 2 2 0] [0 1 0 0] [0 0 0 0] ] //lmstate #[0 #[1 2] 2 3 0] //ghost state [] //fruit state 0 ]) */ #[0 step] } }