# HG changeset patch # User William Morgan # Date 1342256323 25200 # Node ID 370a1eeb881268fa58e88f30652927cdf40d25a1 # Parent 66ea6fdd3fcb29539d3d6ec218acb9eea9a14ff1 merge and stuff diff -r 66ea6fdd3fcb -r 370a1eeb8812 src/sim.tp --- a/src/sim.tp Sat Jul 14 01:46:25 2012 -0700 +++ b/src/sim.tp Sat Jul 14 01:58:43 2012 -0700 @@ -1,4 +1,6 @@ #{ + + // utilities true <- #{ if:else <- :self trueblock :elseblock { trueblock: @@ -11,12 +13,25 @@ } } + foreach <- :string action { + strLen <- string byte_length: + index <- 0 + while: {index < strLen} do { + element <- (string byte: index) + action: index element + index <- index + 1 + } + } + // end utilities + + cellTypes <- #{ allstr <- #[] allobj <- #[] - make <- :idstr { + new <- :idstr { ret <- #{ id <- (idstr byte: 0) + isrobot <- { false } } allobj append: ret allstr append: idstr @@ -39,35 +54,37 @@ } } } - wall <- make: "#" - empty <- make: " " - earth <- make: "." - rock <- make: "*" - lambda <- make: "\\" - closedlift <- make: "L" - openlift <- make: "O" - newline <- make: "\n" + wall <- new: "#" + empty <- new: " " + earth <- new: "." + rock <- new: "*" + lambda <- new: "\\" + closedlift <- new: "L" + openlift <- new: "O" + newline <- new: "\n" robot <- { #{ id <- ("R" byte: 0) + isrobot <- { true } heldBreath <- 0 } } state <- #{ new <- :in_grid in_width in_height { - next_grid <- #[] + nextGrid <- #[] + robot <- false foreach: in_grid :index el{ - next_grid append: el + nextGrid append: el + if: (el isrobot) { robot <- el } else: { true } } #{ grid <- in_grid width <- in_width height <- in_height - robot <- cellTypes robot address <- :x y { x + y * width } - setCell <- :x y cell { - grid set: (address: x y) cell + setCell <- :x y val { + grid set: (address: x y) val } getCell <- :x y { grid get: (address: x y) @@ -99,14 +116,23 @@ } } fromStr <- :str { + strLen <- str byte_length: - index <- 0 maxRow <- 0 curRow <- 0 - while: {index < strLen} do: { - curByte <- str byte: index - if: curByte = (cellType newline id) { - maxRow <- if: curRow > maxRow {curRow} else: {maxRow} + foreach: str :index element { + if: element = ((cellTypes newline) id) { + maxRow <- if: curRow > maxRow {curRow} else: {maxRow} + curRow <- 0 + } else: { + curRow <- curRow + 1 + } + } + + foreach: str :index element { + if: element = ((cellTypes newline) id) { + // add spaces + curRow <- 0 } else: { curRow = curRow + 1 }