refactor dungeon generation code