Question

I will go mostly theorical here because it's a context hard to explain,

I have a canvas 14x17, there are random creatures on this canvas, each can only occupy one square, i have the coordinates of all creatures in a table.

I have a 'bomb' which when i click on the tile i want it to explode, creates an explosion with where i clicked as the center.

This is the actual bomb: Ice Bomb

So, considering the bomb comes from my character that sits in the middle of the canvas, and there is a random amount of creatures around me, how would i find the best place to throw my bomb at which would cover the highest amount of creatures

(bonus points for only throwing if it can hit a minimum amount of creatures)

Was it helpful?

Solution

Algorithmic approach - find center of circle with given radius covering maximal amount of creatures. I think that such algorithm (if exists) is rather complex (example, another example) and is overkill for this relatively small field size.

Brutforce algorithm - calculate number of creatures inside all the possible circles

Reverse algorithm - requires continuous work during creature moving - keep array of integers - every element is number of creatures attainable from this point. When creature is moving right, decrement left cells, increment right cells and so on. Example for two creatures in (2,3) and (4,3) coordinates. (3,3) point is the best place to bomb.

0 0 1 0 0
0 1 1 1 0
0 0 2 0 1
0 1 1 1 1
0 0 1 1 1

What method is better - depends on some conditions - do creatures (frequently) move? and so on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top