Logic for tile generation