Fixed a bug in hasNeighbor and isValidMove