# HG changeset patch # User William Morgan # Date 1342239010 25200 # Node ID be946b2a2cbc813cc7e5afd0865907d22ab7bb2d # Parent d4ba6138c99ea1712f4d5bbb04d2971c54af543a initial barf into simulator file diff -r d4ba6138c99e -r be946b2a2cbc src/sim.tp --- a/src/sim.tp Fri Jul 13 18:25:35 2012 -0700 +++ b/src/sim.tp Fri Jul 13 21:10:10 2012 -0700 @@ -1,5 +1,113 @@ #{ + true <- #{ + if:else <- :self trueblock :elseblock { + trueblock: + } + } + + false <- #{ + if:else <- :self trueblock :elseblock { + elseblock: + } + } + + cellType <- # { + robot <- "R" byte 0 + wall <- "#" byte 0 + rock <- "*" byte 0 + lambda <- "\" byte 0 + closedlift <- "L" byte 0 + openlift <- "O" byte 0 + earth <- "." byte 0 + empty <- " " byte 0 + newline <- "\n" byte 0 + } + + state <- #{ + new <- : in_grid in_width in_height { + dst_grid <- #[] + foreach: in_grid :index el{ + dst_grid append: el + } + #{ + grid <- [] + width <- in_width + height <- in_height + address <- :x y { x + y * width } + setCell <- :x y cell { + grid set: (address: x y) cell + } + getCell <- :x y { + grid get: (address: x y) + } + collected <- 0 + moves <- 0 + ended <- false + advance <- :roboMove { + nextState <- deepCopy: self + nextState <- doMove: + nextState ended <- ended: + nextState moves <- moves + 1 + } + + } + } + fromStr <- :str { + strLen <- str byte_length: + index <- 0 + maxRow <- 0 + curRow <- 0 + while: {index < strLen} do { + curByte <- str byte: index + if: curByte = (cellType newline) { + + } else: { + curRow = curRow + 1 + } + } + 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? + } + } + } + + testMoves <- { + myStep <- 0 + { + print: (string: myStep) + myStep <- myStep + 1 + if: myStep > 5 {"A"} else: {"W"} + } + } + + ended <- :simState roboMove { + if: roboMove = "A" {} + } + main <- { - 0 + } + +/* + main <- { + testInput <- "derp" + simState <- state fromStr: testInput + roboMove <- "W" + getMove <- testMoves: + while: {playing: simState roboMove} do: { + print: "step..." + roboMove <- getMove: + simState advance: + } + } +*/ }