Untitled

mail@pastecode.io avatar
unknown
csharp
2 months ago
1.0 kB
4
Indexable
Never
 private void GenerateSpawnings()
 {
     var spawning = new Spawnig();

     Backtracking(0, ref spawning);
 }
 bool IsValid(List<int> spawnings)
 {

     int totalCost = 0;
     foreach (var spawning in spawnings)
     {
         totalCost += spawning;

     }
     if (totalCost == weight)
         return true;
     else
     {
         return false;
     }
 }

 void DisplaySpawning(Spawnig toDisplay)
 {

     Debug.Log(toDisplay.placement[0] + " " + toDisplay.placement[1] + " " + toDisplay.placement[2] + " " + toDisplay.placement[3]);

 }
 private void Backtracking(int k, ref Spawnig spawning)
 {

     for (int i = 0; i <= weight; i++)
     {

         spawning.placement[k] = i;
         //no more space
         if (k == 3)
         {
             if (IsValid(spawning.placement))
             {
                 DisplaySpawning(spawning);
             }
         }
         else
         {
             Backtracking(k + 1, ref spawning);
         }




     }
 }
Leave a Comment