I have a program that runs on a 2D array. I'm checking certein indicies in this array to see what they are equal to:
if Board[current_y][current_x + 1] == "X" or current_x + 1 >= 5 or (current_y, current_x+1) in index_List or Board[current_y][current_x + 1] == "-":
direction_list.remove("right")
if Board[current_y][current_x - 1] == "X" or current_x - 1 < 0 or (current_y, current_x-1) in index_List or Board[current_y][current_x - 1] == "-":
direction_list.remove("left")
if current_y + 1 >= 5 or Board[current_y + 1][current_x] == "X" or (current_y+1, current_x) in index_List or Board[current_y + 1][current_x] == "-":
direction_list.remove("down")
if current_y - 1 < 0 or Board[current_y - 1][current_x] == "X" or (current_y-1, current_x) in index_List or Board[current_y - 1][current_x] == "-":
direction_list.remove("up")
This is something for a simple pathfinder I'm working on, where it checks one index to the right, left, up, or down and sees if the program can move to that index. However, when it reaches the edge, I'm checking if the value in an index that doesn't exist in the array is equal to "X".
Is there a way to make Python not throw an error in a case like this? I also program in C, and whenever you go out of bounds in C, it just makes it equal to NULL. Is there any way to make Python work like this?