Either I don't understand something or there is a bug that prevents me from playing correctly: the detection for the number of neighbours does not seem to work consistently.
Examples

Here both solutions should be accepted, but I have to switch two houses:
