# HG changeset patch # User William Morgan # Date 1406450199 25200 # Node ID d631e68a45d58715f08c7819778fa1b61d5a0858 # Parent 75f808e60aa80aba37594a68b200982c9b0a4657 separated out grid functions for reuse inside gameState.lm diff -r 75f808e60aa8 -r d631e68a45d5 code/dotScanner.lm --- a/code/dotScanner.lm Sat Jul 26 23:30:55 2014 -0700 +++ b/code/dotScanner.lm Sun Jul 27 01:36:39 2014 -0700 @@ -21,31 +21,13 @@ tree:set:to ] from: (module: "tree.lm") - grid:get <- :grid :pos { - x <- pos value - y <- pos tail - get: x fromTree: (get: y fromTree: grid) - } - - grid:update:with <- :grid :pos :fun { - x <- pos value - y <- pos tail - tree: grid update: y with: :row { - tree: row update: x with: fun - } - } - - grid:set:to <- :grid :pos :val { - grid: grid update: pos with: :el { val } - } - - grid:inBounds? <- :grid :pos { - x <- pos value - y <- pos tail - maxY <- grid value - maxX <- (get: 0 fromTree: grid) value - ((x >= 0) + (y >= 0) + (x < maxX) + (y < maxY)) > 0 - } + import: [ + grid:get + grid:update:with + grid:set:to + grid:inBounds? + calcPos + ] from: (module: "grid.lm") visited <- 0 @@ -80,25 +62,6 @@ continuations } - calcPos <- :move from { - x <- from value - y <- from tail - if: move { - if: move = 1 { - x <- x + 1 - } else: { - if: move = 2 { - y <- y + 1 - } else: { - x <- x - 1 - } - } - } else: { - y <- y - 1 - } - #[x y] - } - makeContClos <- :grid myLoc path { { ret <- [] diff -r 75f808e60aa8 -r d631e68a45d5 code/gameState.lm --- a/code/gameState.lm Sat Jul 26 23:30:55 2014 -0700 +++ b/code/gameState.lm Sun Jul 27 01:36:39 2014 -0700 @@ -8,6 +8,26 @@ 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") myAnd <- :a b { // only ones and zeros @@ -15,6 +35,9 @@ } makeTicker <- :mapWidth mapHeight { + lives <- 3 + win <- 0 + pillCount <- 50 makeEventType <- :lagTick isMovement behavior{ print: 12 @@ -26,9 +49,9 @@ } endOfLives <- makeEventType: (127 * mapWidth * mapHeight * 160) 0 :tick gameState { + lives <- 0 777 print addEvents <- [] - // set lives to zero #[addEvents gameState] } @@ -40,8 +63,14 @@ fruit2Appears <- (127 * 400) fruit1Expires <- (127 * 280) fruit2Expires <- (127 * 280) - //moveLambdaMan <- 127 (eating, lamdamanId) - //moveGhost <- (ghostType, ghostId) + + getLambdaManChoice <- :{0} + moveLambdaMan <- makeEventType: 127 0 : tick { + move <- getLambdaManChoice: + if: move + } + (eating, lamdamanId) + moveGhost <- (ghostType, ghostId) frightModeDeactivate <- (127 * 20) */ @@ -84,13 +113,24 @@ print: 15 // 2.) actions res <- executeEvents: tick 0 events gameState + events <- res value gameState <- (res tail) value print: 16 // 3.) collide pills powerpills fruit - #[events gameState] + if: pillCount = 0 { + win <- 1 + #[[] gameState] + } else: { + if: lives = 0 { + #[[] gameState] + } else: { + #[events gameState] + } + } + } nextTick <- :events { @@ -114,7 +154,7 @@ ] print: 6 gameState <- #[0 0] - while: {tick < runUntil} do: { + while: {(tick < runUntil) and (not: (events empty?))} do: { print: 7 tick <- events nextTick print: 5 diff -r 75f808e60aa8 -r d631e68a45d5 code/grid.lm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/code/grid.lm Sun Jul 27 01:36:39 2014 -0700 @@ -0,0 +1,68 @@ +#{ + 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") + + grid:get <- :grid :pos { + x <- pos value + y <- pos tail + get: x fromTree: (get: y fromTree: grid) + } + + grid:update:with <- :grid :pos :fun { + x <- pos value + y <- pos tail + tree: grid update: y with: :row { + tree: row update: x with: fun + } + } + + grid:set:to <- :grid :pos :val { + grid: grid update: pos with: :el { val } + } + + grid:inBounds? <- :grid :pos { + x <- pos value + y <- pos tail + maxY <- grid value + maxX <- (get: 0 fromTree: grid) value + ((x >= 0) + (y >= 0) + (x < maxX) + (y < maxY)) > 0 + } + + calcPos <- :move from { + x <- from value + y <- from tail + if: move { + if: move = 1 { + x <- x + 1 + } else: { + if: move = 2 { + y <- y + 1 + } else: { + x <- x - 1 + } + } + } else: { + y <- y - 1 + } + #[x y] + } +}