# HG changeset patch # User Mike Pavone # Date 1342255325 25200 # Node ID 5941e6b3684c1cd6ad2b68bc03b75ed0dcb32de2 # Parent 86cdb799f9507b7cb8eba89b2843a146fe86aea5 Read map file in simulator diff -r 86cdb799f950 -r 5941e6b3684c src/sim.tp --- a/src/sim.tp Fri Jul 13 21:48:03 2012 -0700 +++ b/src/sim.tp Sat Jul 14 01:42:05 2012 -0700 @@ -27,10 +27,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 address <- :x y { x + y * width } @@ -59,7 +59,7 @@ index <- 0 maxRow <- 0 curRow <- 0 - while: {index < strLen} do { + while: {index < strLen} do: { curByte <- str byte: index if: curByte = (cellType newline) { maxRow <- if: curRow > maxRow {curRow} else: {maxRow} @@ -69,16 +69,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 - } - deepCopy <- :oldState { - newState <- new: - #{ - // grid <- (use array copy thing) - width <- oldState width - height <- oldState height - address <- oldState address - // ... better way? - } + fresh } } @@ -91,21 +82,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: ) + } } } -*/ + }