示例#1
0
 // Start is called before the first frame update
 void Start()
 {
     rand    = new System.Random();
     cells   = new CellularSimulation <int>(width, height);
     meshGen = GetComponent <MeshGenerator>();
     cells.UpdateInPlace(cell => rand.Next(0, 100) <= percentFilled ? 1 : 0);
     meshGen.GenerateMesh(cells.Values(), 1);
     StartCoroutine(RunLoop());
 }
示例#2
0
 int InitialValue(CellularSimulation <int> .Cell cell)
 {
     if (cell.IsEdge)
     {
         return(1);
     }
     else
     {
         return(rand.Next(0, 100) <= percentFilled ? 1 : 0);
     }
 }
示例#3
0
    int Smooth(CellularSimulation <int> .Cell cell)
    {
        int outOfBoundsNeighbors = 8 - cell.CountNeighbors();
        int wallNeighbors        = cell.CountNeighbors((me, other) => other.Value == 1);
        int wallCount            = outOfBoundsNeighbors + wallNeighbors;

        if (wallCount > 4)
        {
            return(1);
        }
        else if (wallCount < 4)
        {
            return(0);
        }
        return(cell.Value);
    }
示例#4
0
    void GenerateCave()
    {
        if (!useCustomSeed)
        {
            randomSeed = Time.time.ToString();
        }

        rand  = new System.Random(randomSeed.GetHashCode());
        cells = new CellularSimulation <int>(width, height);

        cells.UpdateInPlace(InitialValue);
        for (int i = 0; i < smoothCount; i++)
        {
            cells.Update(Smooth);
        }

        MeshGenerator meshGen = GetComponent <MeshGenerator>();

        meshGen.GenerateMesh(cells.Values(), 1);
    }
示例#5
0
    int Tick(CellularSimulation <int> .Cell cell)
    {
        switch (cell.CountNeighbors((x, y) => y.Value == 1))
        {
        case 0:
        case 1:
            return(0);

        case 2:
            return(cell.Value);

        case 3:
            return(1);

        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        default:
            return(0);
        }
    }
示例#6
0
 internal Cell(CellularSimulation <T> simulation, int x, int y)
 {
     this.simulation = simulation;
     X = x;
     Y = y;
 }