# HG changeset patch # User William Morgan # Date 1342415179 25200 # Node ID b2e9e5ad3ad8e48e235d786e81fd4737bbb55836 # Parent 186fce0c98ee8d8ed3a6ba605cd93cdda1538ea6 fixed array out of bounds errors. Test maps to proove it. diff -r 186fce0c98ee -r b2e9e5ad3ad8 maps/evilbug1.map --- /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 # +##### + diff -r 186fce0c98ee -r b2e9e5ad3ad8 maps/evilbug2.map --- /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#* diff -r 186fce0c98ee -r b2e9e5ad3ad8 maps/evilbug3.map --- /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#* +##### diff -r 186fce0c98ee -r b2e9e5ad3ad8 maps/evilbug4.map --- /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#* diff -r 186fce0c98ee -r b2e9e5ad3ad8 maps/testSim3.map --- /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# +##### + diff -r 186fce0c98ee -r b2e9e5ad3ad8 src/sim.tp --- 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 {