# HG changeset patch # User Mike Pavone # Date 1342255585 25200 # Node ID 66ea6fdd3fcb29539d3d6ec218acb9eea9a14ff1 # Parent 5941e6b3684c1cd6ad2b68bc03b75ed0dcb32de2# Parent 1bd46f854dbbfd035e5745baf7b5f931500722e5 Merge diff -r 1bd46f854dbb -r 66ea6fdd3fcb src/sim.tp --- 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: ) + } } } -*/ + }