Replace 1d array with 2d array for visited coordinates.

In 2d array it is easier to check which coordinates was visited.