Give every cell a row and column. Read the related explanation.
row
column
Move only if the destination is open. An obstacle blocks that move.
Use the same coordinates in the diagram and code.