#Getting a strange out of bounds error

2 messages · Page 1 of 1 (latest)

thorn shoal
#

|| here I setup the wide map for part 2||
||```c
height :: 7
width :: 7
wideW :: width*2
//...
mapa: [height][wideW]u8;
for y = 0; y < height; y += 1 {
wX := 0; // wide x
for x = 0; x < width; x += 1 {
switch mapaini[y][x] {
case '#': { mapa[y][wX] = '#'; mapa[y][wX+1] = '#'; }
case '.': { mapa[y][wX] = '.'; mapa[y][wX+1] = '.'; }
case 'O': { mapa[y][wX] = '['; mapa[y][wX+1] = ']'; }
case '@': {
mapa[y][wX] = '@';
robotPos = {y, wX};
mapa[y][wX+1] = '.';
}
}
wX += 2;
}
}

#

|| In each iteration, I start with a couple switch statements, the second is the one which is getting the out of bounds exception||
||```c
//...
m := mov[i];
checkPos := robotPos;
switch m {
case '<': {
fmt.println(len(mapa[:]), len(mapa[0][:])); // 7 14
fmt.println(checkPos); // [3, 10]
c := mapa[checkPos.y][checkPos.x - 1]; // out of bounds!
switch c {
//...