changeset 48:8b6f6e2cbf38

merge
author William Morgan <billjunk@mrgn.org>
date Sun, 27 Jul 2014 02:35:24 -0700
parents 115695e42307 (diff) 6d2cbad5fca9 (current diff)
children ec87d53603dd 57a4bddadd46
files
diffstat 4 files changed, 276 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sun Jul 27 02:35:24 2014 -0700
@@ -0,0 +1,3 @@
+syntax: glob
+code/lmc
+*~
--- a/code/dotScanner.lm	Sun Jul 27 01:50:49 2014 -0700
+++ b/code/dotScanner.lm	Sun Jul 27 02:35:24 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 <- []
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/code/gameState.lm	Sun Jul 27 02:35:24 2014 -0700
@@ -0,0 +1,198 @@
+#{
+	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]
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/code/grid.lm	Sun Jul 27 02:35:24 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]
+	}
+}