changeset 9:66ea6fdd3fcb

Merge
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 01:46:25 -0700
parents 5941e6b3684c (diff) 1bd46f854dbb (current diff)
children 370a1eeb8812
files src/sim.tp
diffstat 1 files changed, 36 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sat Jul 14 00:43:06 2012 -0700
+++ b/src/sim.tp	Sat Jul 14 01:46:25 2012 -0700
@@ -58,10 +58,10 @@
 		new <- :in_grid in_width in_height { 
 			next_grid <- #[]
 			foreach: in_grid :index el{
-				dst_grid append: el
+				next_grid append: el
 			}
 			#{
-				grid <- []
+				grid <- in_grid
 				width <- in_width
 				height <- in_height
 				robot <- cellTypes robot
@@ -103,7 +103,7 @@
 			index <- 0
 			maxRow <- 0
 			curRow <- 0
-			while: {index < strLen} do {
+			while: {index < strLen} do: {
 				curByte <- str byte: index
 				if: curByte = (cellType newline id) {
 					maxRow <- if: curRow > maxRow {curRow} else: {maxRow}
@@ -113,6 +113,7 @@
 			}
 			grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0)  (			                 "#" byte: 0) (" " byte: 0) ("#" byte: 0)  (			                 "#" byte: 0) ("#" byte: 0) ("#" byte: 0)] 
 			fresh <- new: grid 3 3
+			fresh
 		}
 	}
 
@@ -125,21 +126,40 @@
 		}
 	}
 	
-	main <- {
-		
+	readFile <- :path {
+		fd <- os open: path (os O_RDONLY)
+		print: "fd: " . fd . "\n"
+		if: fd < 0 { "" } else: {
+			cur <- ""
+			part <- ""
+			while: { 
+				part <- os read: fd 128
+				print: "read: " . part . "\n"
+				part != ""
+			} do: {
+				cur <- cur . part
+			}
+			os close: fd
+			cur
+		}
+	}
+	
+	getMove <- {
+		os read: 0 1
 	}
 
-/*
-	main <- {
-		testInput <- "derp" 
-		simState <- state fromStr: testInput
-		roboMove <- "W"
-		getMove <- testMoves:
-		while: {playing: simState roboMove} do: {
-			print: "step..."
-			roboMove <- getMove:
-			simState advance:
+	main <- :args {
+		if: (args length) < 2 {
+			print: "usage: sim filename\n"
+		} else: {
+			print: (args get: 1) . "\n"
+			text <- readFile: (args get: 1)
+			simState <- state fromStr: text
+			while: { if: (simState ended) {false} else: {true} } do: {
+				print: "step...\n"
+				simState advance: (getMove: )
+			}
 		}
 	}
-*/
+
 }