Driven by a k-nearest neighbor algorithm, colored blocks swap places, so that each block borders at least one block of the same color.