예제 #1
0
    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);
                }
            }
        }
    }
예제 #2
0
    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");
        }
    }
예제 #3
0
    public bool Propagete(WFCTile neighbourTile)
    {
        bool changed = false;

        for (int i = superPosition.Count - 1; i >= 0; i--)
        {
            if (!CanCollapse())
            {
                break;
            }
            WFCTileType tileType   = superPosition[i];
            bool        compatible = false;
            for (int j = 0; j < neighbourTile.superPosition.Count; j++)
            {
                WFCTileType neighbourTileType = neighbourTile.superPosition[j];
                if (tileType.IsCompatible(neighbourTileType.tileType))
                {
                    compatible = true;
                    break;
                }
            }
            if (!compatible)
            {
                superPosition.RemoveAt(i);
                changed = true;
            }
        }
        Refresh();
        return(changed);
    }
예제 #4
0
 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);
                 }
             }
         }
     }
 }