jwow22

Clean - Lowest Cost Object

Jan 5th, 2022 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1.  
  2.   public GridObject LowestCostObject()
  3.     {
  4.         int index = 0;
  5.         int max = 99999;
  6.         for (int i = 0; i < _spawner.spawnedObjects.Count; i++)
  7.         {            
  8.             GridObject gridObject = _spawner.spawnedObjects[i];
  9.            
  10.             int distanceCost = _pathfinding.TileDistanceCost(gridObject.currentTile, snake.currentTile);
  11.             int totalCost = distanceCost + gridObject.GetWeight();
  12.             if (totalCost < max)
  13.             {
  14.                 max = totalCost;
  15.                 index = i;
  16.             }
  17.         }
  18.         return _spawner.spawnedObjects[index];
  19.     }
Add Comment
Please, Sign In to add comment