Mercurial > repos > icfp2012
view src/sim.tp @ 6:86cdb799f950
unbarfed some things
author | William Morgan <bill@mrgn.org> |
---|---|
date | Fri, 13 Jul 2012 21:48:03 -0700 |
parents | be946b2a2cbc |
children | 1bd46f854dbb 5941e6b3684c |
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 { next_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 doMove <- :roboMove { ended <- roboMove = "A" } advance <- :roboMove { doMove: roboMove moves <- moves + 1 self } } } fromStr <- :str { strLen <- str byte_length: index <- 0 maxRow <- 0 curRow <- 0 while: {index < strLen} do { curByte <- str byte: index if: curByte = (cellType newline) { maxRow <- if: curRow > maxRow {curRow} else: {maxRow} } 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"} } } main <- { } /* main <- { testInput <- "derp" simState <- state fromStr: testInput roboMove <- "W" getMove <- testMoves: while: {playing: simState roboMove} do: { print: "step..." roboMove <- getMove: simState advance: } } */ }