Mercurial > repos > icfp2014
view code/gameState.lm @ 55:194a1414e240
Partial implementation of Ghost-Quiche
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 27 Jul 2014 16:26:56 -0700 |
parents | 115695e42307 |
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") myAnd <- :a b { // only ones and zeros (a + b) = 2 } makeTicker <- :mapWidth mapHeight { lives <- 3 lambdamanPos <- #[5 5] win <- 0 pillCount <- 50 makeEventType <- :lagTick isMovement behavior{ print: 12 :curTick { print: 11 expireTick <- curTick + lagTick #[expireTick isMovement :gameState {behavior: expireTick gameState}] } } endOfLives <- makeEventType: (127 * mapWidth * mapHeight * 160) 0 :tick gameState { lives <- 0 777 print addEvents <- [] #[addEvents gameState] } isFood <- :tile {(2 <= tile) and (tile <= 4)} getLambdaManChoice <- :{0} moveLambdaMan <- makeEventType: 127 1 :tick gameState { move <- getLambdaManChoice: newPos <- (calcPos: move lambdamanPos) impending <- grid: grid get: newPos if: (not: (impending = 0)) { lambdamanPos <- impending } else { } if: (impending isFood) { #[(moveLambdaMan: (tick + 10)) gameState] } else { #[(moveLambdaMan: tick) gameState] } } /* fruit <- 0 fruit1Appears <- makeEventType: (127 * 200) 0 :gameState { fruit <- 80 #[fruit1Expires gameState] } fruit2Appears <- (127 * 400) 0 fruit1Expires <- (127 * 280) 0 fruit2Expires <- (127 * 480) 0 moveGhost0 <- 1 //(ghostType, ghostId)!? moveGhost1 <- 1 //(ghostType, ghostId)!? moveGhost2 <- 1 //(ghostType, ghostId)!? moveGhost3 <- 1 //(ghostType, ghostId)!? frightModeDeactivate <- (127 * 20) 0 */ executeEvents <- :tick isMove events gameState { event <- 0 eventTick <- 0 eventIsMove <- 0 eventLam <- 0 unexpired <- [] res <- 0 while: { not: (events empty?) } do: { event <- events value eventTick <- event value eventIsMove <- (event tail) value print: 17 if: ( ( eventTick = tick ) myAnd: ( eventIsMove = isMove ) ) { eventLam <- ((event tail) tail) res <- eventLam: gameState unexpired <- res value gameState <- res tail } else: { unexpired <- event | unexpired } events <- events tail } print: 18 #[unexpired gameState] } executeTick <- :tick events gameState { // TODO: update fruit countdown for AI input print: 14 // 1.) movement res <- executeEvents: tick 1 events gameState events <- res value gameState <- (res tail) value print: 15 // 2.) actions res <- executeEvents: tick 0 events gameState events <- res value gameState <- (res tail) value print: 16 // 3.) collide pills powerpills fruit if: pillCount = 0 { win <- 1 #[[] gameState] } else: { if: lives = 0 { #[[] gameState] } else: { #[events gameState] } } } nextTick <- :events { print: 8 fold: events 0x7FFFFFFF with: :curMin event { print: #[9 curMin event] eventTick <- event value print: 10 if: eventTick < curMin { curMin <- eventTick } else: {} curMin } } print: 4 :runUntil { res <- 0 tick <- 1 events <- [ endOfLives: 0 ] print: 6 gameState <- #[0 0] while: {(tick < runUntil) and (not: (events empty?))} do: { print: 7 tick <- events nextTick print: 5 res <- executeTick: tick events gameState print: 13 events <- res value gameState <- res tail } } } step <- :myState world { print: 1 ticker <- makeTicker: 10 10 print: 2 ticker: 1000 print: 3 #[0 0] } main <- :initWorld ghostCode{ #[0 step] } }