Mercurial > repos > icfp2012
diff src/sim.tp @ 65:aa822c683e28
merge
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 16 Jul 2012 04:35:43 -0700 |
parents | ff2b38518a58 ca86c88c2336 |
children | ff8d7b4499f5 |
line wrap: on
line diff
--- a/src/sim.tp Mon Jul 16 04:35:24 2012 -0700 +++ b/src/sim.tp Mon Jul 16 04:35:43 2012 -0700 @@ -133,6 +133,13 @@ _maxmoves <- in_width * in_height _heuristicValid <- false _heuristic <- 0 + getSafe <- :collection :index { + if: index >= 0 { + if: index < (collection length) { + collection get: index + } else: { (cellTypes wall) } + } else: { (cellTypes wall) } + } _succeeded <- false ret <- #{ grid <- in_grid @@ -142,26 +149,26 @@ calcX <- :index {index % width} calcY <- :index {index / width} getCell <- :x y { - grid get: (calcIndex: x y) + grid getSafe: (calcIndex: x y) } setCell <- :x y val { grid set: (calcIndex: x y) val } getNextCell <- :x y { - _nextGrid get: (calcIndex: x y) + _nextGrid getSafe: (calcIndex: x y) } setNextCell <- :x y val { _nextGrid set: (calcIndex: x y) val } validDest?:from <- :index :fromIndex { - cell <- (grid get: index) + cell <- (grid getSafe: index) if: (cell navigable) {true} else: { if: (cell eq: (cellTypes rock)) { diff <- index - fromIndex //make sure movement was horizontal if: (abs: diff) = 1 { rockdest <- index + diff - if: ((grid get: rockdest) eq: (cellTypes empty)) { + if: ((grid getSafe: rockdest) eq: (cellTypes empty)) { //make sure rock destination doesn't wrap (calcY: rockdest) = (calcY: index) } @@ -377,7 +384,7 @@ cur <- (grid length) - width col <- 0 while: {cur >= 0} do: { - os write: 2 ((grid get: cur) string) + os write: 2 ((grid getSafe: cur) string) cur <- cur + 1 col <- col + 1 if: col = width {