void CheckNeighbours(WFCTile tile) { int x = tile.x; int y = tile.y; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (Mathf.Abs(i) == Mathf.Abs(j)) { continue; } int x2 = x + i; int y2 = y + j; if (IsBoundry(x2, y2)) { continue; } WFCTile neighBour = tiles[x2, y2]; if (neighBour.CanCollapse()) { tilesToCheck.Enqueue(neighBour); } } } }
public void Observe() { float lowestEntropy = float.MaxValue; WFCTile tileToCollapse = null; for (int x = 0; x < mapSize; x++) { for (int y = 0; y < mapSize; y++) { WFCTile tile = tiles[x, y]; float entropy = tile.CalculateEntropy(); if (entropy < lowestEntropy && tile.CanCollapse()) { lowestEntropy = entropy; tileToCollapse = tile; } } } if (tileToCollapse != null) { tileToCollapse.Collapse(); //tilesToCheck.Enqueue(tileToCollapse); CheckNeighbours(tileToCollapse); } else { running = false; print("Can't find tile to collapse"); } }
public void Propagate() { print("Propogate"); while (tilesToCheck.Count > 0) { WFCTile tile = tilesToCheck.Dequeue(); if (!tile.CanCollapse()) { continue; } int x = tile.x; int y = tile.y; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (!tile.CanCollapse()) { break; } if (Mathf.Abs(i) == Mathf.Abs(j)) { continue; } int x2 = x + i; int y2 = y + j; if (IsBoundry(x2, y2)) { continue; } WFCTile neighBour = tiles[x2, y2]; if (tile.Propagete(neighBour)) { CheckNeighbours(tile); } } } } }