'best data structure and algorithm for 2d grid movement

I have a shaped grid with holes like shown in the following image:

enter image description here

I want to know what is the most memory efficient data structure to represent the grid in the image and what algorithm can I use with such a data structure so that my player won't exit the grid(the blue colored cells). I want the player to move along the grid. I realized that I only have to check for the neighboring cell next to the player when moving on the x or y axis, but I am not sure if a multidimensional array is the most memory efficient data structure in this case if I were to use a bigger grid.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source