Mercurial > repos > icfp2012
view src/sim.tp @ 5:be946b2a2cbc
initial barf into simulator file
author | William Morgan <bill@mrgn.org> |
---|---|
date | Fri, 13 Jul 2012 21:10:10 -0700 |
parents | bb29dcd46cbf |
children | 86cdb799f950 |
line wrap: on
line source
#{ 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 <- { } /* main <- { testInput <- "derp" simState <- state fromStr: testInput roboMove <- "W" getMove <- testMoves: while: {playing: simState roboMove} do: { print: "step..." roboMove <- getMove: simState advance: } } */ }