Mercurial > repos > icfp2012
changeset 55:b2e9e5ad3ad8
fixed array out of bounds errors. Test maps to proove it.
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sun, 15 Jul 2012 22:06:19 -0700 |
parents | 186fce0c98ee |
children | ca86c88c2336 |
files | maps/evilbug1.map maps/evilbug2.map maps/evilbug3.map maps/evilbug4.map maps/testSim3.map src/sim.tp |
diffstat | 6 files changed, 56 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/evilbug1.map Sun Jul 15 22:06:19 2012 -0700 @@ -0,0 +1,6 @@ +###R# +# # +# # +L # +##### +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/evilbug2.map Sun Jul 15 22:06:19 2012 -0700 @@ -0,0 +1,5 @@ +##### +# R# +# # +*# #* +*#L#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/evilbug3.map Sun Jul 15 22:06:19 2012 -0700 @@ -0,0 +1,6 @@ +##### +# R# +# # +*# #* +*#L#* +#####
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/evilbug4.map Sun Jul 15 22:06:19 2012 -0700 @@ -0,0 +1,3 @@ +# R# +*# #* +*#L#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim3.map Sun Jul 15 22:06:19 2012 -0700 @@ -0,0 +1,24 @@ +##### +#L # +# *# +# *# +# *# +# *# +# *# +# *# +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# R# +##### +
--- a/src/sim.tp Sun Jul 15 20:30:46 2012 -0700 +++ b/src/sim.tp Sun Jul 15 22:06:19 2012 -0700 @@ -129,7 +129,13 @@ _nextGrid <- #[] _robot <- null _ended <- false - + 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 @@ -139,26 +145,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) } @@ -281,7 +287,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 {