Skip to content

Understanding the "Propagation" step #1

Description

@op-rt

Dear @Coac ,

Thank you for this clear, pythonic and efficient port of the original C# script. I learned a lot from reading it.

A point is still obscure to me, during propagation:

  • Why are you starting to iterate over the neighbors of the neighbors of the collapsed cell ?
    (Every other implementation start by iterating over the 4 direct nighbors of the collapsed cell, not the neighbors of its neighbors)

  • Are you iterating over neighbors that have been collapsed as well ? (updating collapsed cell ?)

  • What happens when you remove the last available pattern of a cell (line 62 of propagator.py) ? (How do you handle cells with 0 patterns left ? Normally, this should throw an error)

In other words:

def propagate(cell):
        to_update = [neighbour for neighbour, _ in cell.get_neighbors()] 

       # Why putting the neighbors of the collapsed cell in the stack ?
       # Other implementations put the collapsed cell in the stack, then iterate over its neighbors

        while len(to_update) > 0:
            cell = to_update.pop(0)
            for neighbour, offset in cell.get_neighbors():

                # Usually, other implementations have an "if" statement here: "if neighbour is not collapsed:"

                for pattern_index in cell.allowed_patterns:
                    pattern = Pattern.from_index(pattern_index)
                    pattern_still_compatible = False
                    for neighbour_pattern_index in neighbour.allowed_patterns:
                        neighbour_pattern = Pattern.from_index(neighbour_pattern_index)

                        if pattern.is_compatible(neighbour_pattern, offset):
                            pattern_still_compatible = True
                            break

                    if not pattern_still_compatible:
                        cell.allowed_patterns.remove(pattern_index)  
               
                       # What happens if the cell has now 0 pattern available because of this removal ?

                        for neigh, _ in cell.get_neighbors():
                            if neigh not in to_update:
                                to_update.append(neigh)

                               # Also, what happens if you put in the stack a neighbor that a has been collapsed ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions