# HG changeset patch # User William Morgan # Date 1342301901 25200 # Node ID 75a005b210c51e507180567212f1649bd78dcdf8 # Parent 883ae0c1b7f63b34f07529459c84f7ab9c875fc2 almost got movement diff -r 883ae0c1b7f6 -r 75a005b210c5 src/sim.tp --- a/src/sim.tp Sat Jul 14 11:09:36 2012 -0700 +++ b/src/sim.tp Sat Jul 14 14:38:21 2012 -0700 @@ -1,14 +1,20 @@ { true <- #{ - if:else <- :self trueblock :elseblock { - trueblock: - } + if <- :self trueblock { + trueblock: + } + if:else <- :self trueblock :elseblock { + trueblock: + } } false <- #{ - if:else <- :self trueblock :elseblock { - elseblock: - } + if <- :self trueblock { + self + } + if:else <- :self trueblock :elseblock { + elseblock: + } } eachbyte <- :string action { @@ -40,7 +46,7 @@ while: { if: index < (allid length) { (allid get: index) != id - } else: {false} + } } do: { index <- index + 1 } @@ -61,11 +67,19 @@ newline <- new: "\n" robot <- { #{ - id <- ("R" byte: 0) + id <- ("R" byte: 0) isrobot <- { true } heldBreath <- 0 - move <- :cmd { - cmd + x <- 0 + y <- 0 + move <- :cmd mine { + writeMove <- :xPrime yPrime { + mine setCell: xPrime yPrime self + mine setCell: x y empty + x!: xPrime + y!: yPrime + } + writeMove: x (y - 1) } } } @@ -93,19 +107,26 @@ foreach: in_grid :index el{ nextGrid append: el if: (el isrobot) { - robot <- el + robot <- el + updatePos: robot index } else: { true } } #{ grid <- in_grid width <- in_width height <- in_height - address <- :x y { x + y * width } + calcIndex <- :x y { x + y * width } + calcX <- :index {index % width} + calcY <- :index {index / width} setCell <- :x y val { - grid set: (address: x y) val + grid set: (calcIndex: x y) val } getCell <- :x y { - grid get: (address: x y) + grid get: (calcIndex: x y) + } + updatePos <- :obj Index { + obj x! (calcX: Index) + obj y! (calcY: Index) } water <- 0 flooding <- 0 @@ -118,9 +139,14 @@ } advance <- :roboCmd { endreached <- roboCmd = "A" - robot move: roboCmd + robot move: roboCmd self moves <- moves + 1 doUpdate: + if: debugToStdErr { + grid foreach: :index value { + os write: 2 (string: (value id)) + } + } self } @@ -190,6 +216,7 @@ os read: 0 1 } + debugToStdErr <- true main <- :args { if: (args length) < 2 { print: "usage: sim filename\n"