Mercurial > repos > icfp2014
view code/gameState.lm @ 72:a2a5d80abaa0
Add and as a function to gqc to work around parser limitations
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jul 2014 00:42:21 -0700 |
parents | 476cd9eba2be |
children | c17380c8bac3 |
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 gridMaxX gridMaxY gridArea grid:inBounds? calcPos ] from: (module: "grid.lm") myAnd <- :a b { // only ones and zeros (a + b) = 2 } makeTicker <- :mapGrid { lives <- 3 lambdamanPos <- #[5 5] win <- 0 pillCount <- 50 isFood <- :tile { (2 <= tile) myAnd: (tile <= 4) } getLambdamanChoice <- {0} makeEventType <- :lagTick isMovement behavior{ print: 12 :curTick { print: 11 expireTick <- curTick + lagTick #[expireTick isMovement :events {behavior: expireTick events}] } } endOfLives <- makeEventType: (127 * (mapGrid gridArea) * 16) 0 :tick events { lives <- 0 777 print events } moveLambdaman <- makeEventType: 127 1 :tick events { print: 20 move <- getLambdamanChoice: newPos <- (calcPos: move lambdamanPos) impending <- grid: mapGrid get: newPos print: 21 if: (not: (impending = 0)) { lambdamanPos <- impending } else: { } print: 22 if: (impending isFood) { (moveLambdaman: (tick + 10)) | events } else: { (moveLambdaman: tick) | events } } /* fruit <- 0 fruit1Appears <- makeEventType: (127 * 200) 0 :events { fruit <- 80 fruit1Expires | events } 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 { print: #[23 tick isMove events] event <- 0 eventTick <- 0 eventIsMove <- 0 eventLam <- 0 unexpired <- [] 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) unexpired <- eventLam: unexpired } else: { unexpired <- event | unexpired } events <- events tail } print: 18 unexpired } executeTick <- :tick events { // TODO: update fruit countdown for AI input print: 14 // 1.) movement events <- executeEvents: tick 1 events print: 15 // 2.) actions events <- executeEvents: tick 0 events print: 16 // 3.) collide pills powerpills fruit if: pillCount = 0 { win <- 1 [] } else: { if: lives = 0 { [] } else: { events } } } 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 { tick <- 1 events <- [ endOfLives: 0 moveLambdaman: 0 ] print: 5 while: {(tick < runUntil) myAnd: (not: (events empty?))} do: { print: 6 events <- executeTick: tick events print: 7 tick <- events nextTick } } } step <- :myState world { print: 1 grid <- makeTree: (map: (world value) :row { makeTree: row }) ticker <- makeTicker: grid print: 2 ticker: 1000 print: 3 #[0 0] } /* main <- :initWorld ghostCode{ #[0 step] } */ main <- { 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 ]) } }