IoC the memoizeLegalNeighbours