1

I would just like to know the various AI algorithms or logics used in arcade/strategy games for finding/selecting best target to attack for individual unit.

Because, I had to write an small AI logic, where their will be group of unit were attacked by an various tankers, so i am stuck in getting the better logic or algorithm for selecting an best target for unit to attack onto the tankers.

Data available are: Tanker position, range, hitpoints, damage.

please anybody know the best suitable algorithm/logic for solving this problem, respond early.

Thanks in advance, Ramanand.

Ramanand Bhat
  • 183
  • 2
  • 5
  • 22

3 Answers3

6

I'm going to express this in a perspective similar to RPG gamers:

What character would you bring down first in order to strike a crippling blow to the rest of your enemies? It would be common sense to bring down the healers of the party, as they can heal the rest of the team. Once the healers are gone, the team needs to use medicine - which is limited in supply - and once medicine is exhausted, the party is screwed.

Similar logic would apply to the tank program. In your AI, you need to figure out which tanks provide the most strength and support to the user's fleet, and eliminate them first. Don't focus on any other tanks unless they become critical in achieving their goal: Kill the strongest, most useful members of the group first.

So I'm going to break down what I feel is most likely pertains to the attributes of your tanks.

RANGE: Far range tanks can hit from a distance but have weak STRENGTH in their attacks.

TANKER POSITION: Closer tanks are faster tanks, but have less STRENGTH in their attacks.  Also low HITPOINTS because they're meant for SPEED, and not for DAMAGE.

TANKER HP: Higher HP means a slower-moving tank, as they're stronger.  But they won't be close to the front lines.

DAMAGE: Higher DAMAGE means a STRONGER tank with lots of HP, but SLOWER as well to move.

So if I were you, I'd focus first on the tanks that have the highest HP/strongest attacks, followed by the closest ones, and then worry about the ranged tanks - you can't do anything to them anyway until they move into your attack radius :P

And the algorithm would be pretty simple. if you have a list of tanks in a party, create a custom sort for them (using CompareTo) and sort the tanks by class with the highest possible HP to the top of the list, followed by tanks with their focus being speed, and then range.

And then go through each item in the list. If it is possible to attack Tank(0), attack. If not, go to Tank(1).

Jeffrey Kern
  • 2,024
  • 20
  • 40
  • It all also depends on personal preference. You could also find the closest tanks to your own and attack them :P – Jeffrey Kern Jun 20 '10 at 20:37
  • Firstly Thanks a lot for your explained details. Now thing is in our case Tanks won't move they are fixed with various random HP, damage and range. so our unit has to and will move with limited fixed speed to attack the tanker. Our unit has fixed HP, range and damage can make. – Ramanand Bhat Jun 21 '10 at 03:03
  • Now my major goal is to achieve maximum win percentage for unit group( Total unit count = 10), and not to the tankers( total tanker count = 5), say for 1000 simulations 90% of the time Unit group need to win against the tankers. Your above mentioned approach of selecting first tank which has maximum HP for attacking and for next select rest of them will result into only 40% win percentage. And for selecting the tanker which is closest first, will result into 70% win. – Ramanand Bhat Jun 21 '10 at 03:04
  • So till now i haven't come-up with the best algorithm/logic that gives the Unit win percentage near to 90% over tank. If you have any thoughts or plans on above requirement, please share it with me. Thank you very much, Ramanand. – Ramanand Bhat Jun 21 '10 at 03:05
  • Well it all comes down to what your values and game design are. I am basing it off of how I would personally design a tank game - I didn't realize the tankers were fixed with random HP. I figured they could move and had static HP amounts. Are you trying to come up with a 90% win rate for each scenario? It might not be possible with your current scenario, 70% might be your best. Have you tried running different scenarios with the same algorithm? – Jeffrey Kern Jun 21 '10 at 14:30
  • Also - you said HP is randomly generated. Are the tank's initial values the same generated numbers each time a scenario is played out (e.g., Tank1 will always get 45 HP, Tank2 will get 59, etc.) or do they change with each simulation? If the values constantly change, that will affect the outcome of each battle. – Jeffrey Kern Jun 21 '10 at 14:33
  • Yes. These simulations are for the Test purpose, and not for the actual game scenario. So yes we have tried running different scenarios with the same algorithm result into 70% win rate when we tried to target nearby tank to attack first. Anyhow i have learnt that, each algorithm/logic are basically based on the our game data and requirement, their is no proper or straight forward logic available, we need discover our own. Thanks, your support is really appreciated. – Ramanand Bhat Jun 22 '10 at 03:52
4

The goal is to attack only one opponent at a time and receive fire from at most one enemy at a time (though, preferably, none).

Ideally, you would attack the tanks by remaining behind cover and flanking them with surprise attacks. This allows you to destroy the tanks one at a time, while receiving no or little fire.

If you don't have cover, then you should use the enemy as cover. Move into a position that puts the enemy behind the enemy. This also improves your chance to hit.

You can also use range to reduce fire from multiple enemies. Retreat until you are only within range of one enemy.

If the enemies can all fire on you, you want to attack one target until it is no longer a threat, then move on to the next target. The goal is to reduce the amount of fire that you receive as quickly as possible.

If more than one enemy can fire on you at the same time, and you can choose your target, you should fire at the one that allows you to reduce the most amount of damage for the least cost. Simply divide the hit points by the damage, and attack the one with the smallest result. You should also figure in any other relevant stats. Range probably affects you and the enemy equally, but considering the ability to maneuver out of the way of fire, closer enemies are more harmful and should be given some weight in the calculation.

If moving decreases the likelihood of being hit, then you should keep moving, typically by circling your opponent to stay at their flank.

Team tactics would mostly include flanking and diversions.

What's the ammo situation, and is it possible to miss a stationary target?

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
1

Based on your comments it sounds like you already have some adhoc set of rules or heuristics to give you something around 70% success based on your own measures, and you want to optimize this further to get a higher win rate.

As a general solution method I would use a hill-climbing algorithm. Since I don't know the details of your current algorithm that is responsible for the 70% success rate, I can only describe in abstract terms how to adapt hill-climbing to optimize your algorithm.

The general principle of hill-climbing is as follows. Hopefully, a small change in some numeric parameter of your current algorithm would be responsible for a small (hopefully linear) change in the resulting success rate. If this is true then you would first parameterize your current set of rules -- meaning you must decide in your current algorithm which numeric parameters may be tweaked and optimized to achieve a higher success rate. Once you've decided what they are, the learning process is straight-forward. Start with your current algorithm. Generate a variety of new algorithms with slightly tweaked parameters than before, and run your simulations to evaluate the performance of this new set of algorithms. Pick the best one as your next starting point. Repeat this process until the algorithm can't get any better.

If your algorithm is a set of if-then rules (this includes rule-matching systems), and improving the performance involves reordering or restructuring those rules, then you may want to consider genetic algorithms, which is a little more complex. To apply genetic algorithms, it is essential that you define the mutation and crossover operators such that a single application of mutation or crossover results in a small change in the overall performance while a many applications of mutation and crossover results in a large change in the overall performance of your algorithm. I'm not an expert in this field but there should be much that comes up when you google for "genetic algorithms on decision trees". The pitfall to avoid is that if you simply consider swapping branches in a decision tree for the mutation operator, a single application might modify the root of your decision tree, generating a huge performance difference. This typically adds too much noise for a genetic algorithm, so my advice in this approach is to be very careful about the encoding of your operators.

Note that these two methods are very popular AI methods for learning or improving your current algorithm. You would do all of these simulations and learning offline. Then you would simply deploy the resulting, learned algorithm.

Eric
  • 706
  • 5
  • 13