Simply keep track of where you are, and move a direction by increasing or decreasing the row or column (x or y) coordinate. Since you have an even number of rows and columns, you cannot have an exact middle, so cut that in half, and check the four for whatever you need.
Quzah.