menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Data Science News

>

Tracking F...
source image

Dev

1M

read

276

img
dot

Image Credit: Dev

Tracking Furthest Enemy in a Tower Defence Game using Max Heap

  • In this article, I will explain how to use the max heap to track the furthest enemy on the map.
  • The answer to this question is the building block towards enabling towers to track enemies more effectively.
  • The current implementation uses an array enemySpatialGrid that tracks enemies in each cell on the map.
  • Sorting items generally takes O(N logN), this is slower than max heap.
  • An update is done similarly to adding a new enemy. Except we need to know the enemy’s position in the heap.
  • To achieve deletion, we need to take three steps.
  • Since the heap is already sorted, we just need to grab the first element in the heap.
  • Max heap successfully solved the problem. Now we know the furthest enemy on the map.
  • Additionally, the max heap is more performant than the existing implementation.
  • Lastly, its implementation paves the way to integrating it with towers.

Read Full Article

like

16 Likes

For uninterrupted reading, download the app