Skip to main content
GameDev.net gamedev.net
🔒 Locked

AI ideas for scorched earth

Started by brainydexter Jan 6, 2010 at 3:25 PM 7 replies 3.3k views
Original Post
brainydexter
brainydexter
I am making a 2D game, something similar on the lines of scorched earth / pocket tanks. I have the whole framework in place, but I need some ideas to implement the AI for the tanks. It is easy to make them difficult tanks, since the computer tanks can know the opponent positions and plan the trajectory accordingly. This would make up for a sniper shot, one-hit-kill. I am sure players won't really like this much! Can anyone point out some simple ideas/thoughts that I can try out ? Thanks!
krez
krez
You could add some random variation to the angle and magnitude of the enemy tanks' shots (lower difficulty means adding a larger range of inaccuracy). To make them seem like they are still trying though, you should let their subsequent shots get closer to the target (have less random inaccuracy), as if it is making adjustments after the first failure. If they change target they ought to go back to the "full" value of their inaccuracy though.

Or you could make them suck in the way I do, and "forget" to account that the wind changes all the time. :)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
brainydexter
brainydexter
haha. I can see how not taking the wind into account would work. Wind would bring in accuracy and "make it look" good xD

I was thinking about introducing a degree of error for each player, and depending on the difficulty or 'dumbness', it would throw the angle off by that amount.

So, thanks for giving me some ideas to think about :)

I'll post whatever I end up using.
LorenzoGatti
LorenzoGatti
There's an important variable in this kind of game: the kind of weapons.

With powerful and complex weapons (both in Atomic Tanks and Scorched Earth at the maximum tech level and with more than default of money there are weapons that can kill all tanks in one shot) the game is over in very few turns and the advantage of the human player lies in his ability to predict what the weapons do: for example a computer might happily shoot a close range nuke and get caught in the blast radius. If the computer plays up to one or two turns, there is no improvement or stochastic variation to worry about.

On the other hand with weak and simple guns that take several direct hits to kill a tank (like those at minimum tech level in Scorched Earth and Atomic Tanks) the game is about taking cover and aiming better over the course of many turns; the computer might aim iteratively by trial and error, generating random parameters for its next shot by randomly interpolating and perturbing its previous attempts; the player would have the time to do the same, possibly better or with a smarter use of movement and different weapons.
Stronger computer players might simulate more than one randomly generated shot in secret and perform the best one (to represent their artillery skill); filter obviously bad shots according to rules (e.g. if simulation shows that they would be caught in the blast radius); and move near plausible cover instead of standing still.

The most difficult AI is needed with weak and complex weapons: the human player can carry out complex plans and exploit quirks, the computer player can only compensate with unnatural good aim unless reliable behaviour rules can be found. For example the AI in Worms rarely did something really dumb, and it used advanced weapons rather well (but not as well as the player).
Omae Wa Mou Shindeiru
Raskell
Raskell
Quote:
Original post by krez
You could add some random variation to the angle and magnitude of the enemy tanks' shots (lower difficulty means adding a larger range of inaccuracy).


Or you could come at it from the other angle. Add some variation to the AI's determination of your location, the angle to fire at, and wind speed (and direction if in 3D, but not in 2D). This is more representative of how real players play the game, and it provides for the possibility of creating AI personalities. One AI could be a fairly good judge of distance, but not be so good at judging angles, or wind speed. Another AI may not be that good at any of those things, but could be really good at making the necessary compensations for the follow up shots.
brainydexter
brainydexter
Ah, personalities!

I see what you're saying. I'll definitely give it more thought. As of now, Im having some issues with calculating the angle and velocity with which the NPC should fire, given the destination and the maximum height and range it has to cover.

Thanks tho for your idea.
NathanRunge
NathanRunge
Quote:
Original post by Raskell
Or you could come at it from the other angle. Add some variation to the AI's determination of your location, the angle to fire at, and wind speed (and direction if in 3D, but not in 2D). This is more representative of how real players play the game, and it provides for the possibility of creating AI personalities. One AI could be a fairly good judge of distance, but not be so good at judging angles, or wind speed. Another AI may not be that good at any of those things, but could be really good at making the necessary compensations for the follow up shots.


I was just about to propose a similar solution. I am currently developing a game inspired by early generation platformers. The player, however, takes on the role of the protagonist devising traps and pitfalls for the 'player character' to face. Without going into details, the main purpose of the AI is to appear as if it is a player. As such we approached AI development from a 'decision making' perspective. Rather than randomising deviation from the 'correct' solution, randomisation was applied as a means of 'estimation'.

The AI estimates a correct course of action based upon a number of attributes. Potential challenges include jump locations, slowing and speeding, timing, dodging and power-up usage to name a few. In this case you may have the AI 'estimating' the influence of the wind, the power and angle needed, the influence of terrain and how a weapon's impact may work (e.g. whether some form of liquid or shrapnel is deployed, point of detonation or explosion size). This opens up greater flexibility for different AI personalities, as mentioned by Raskell, and for improving performance as time progresses without relying on a 'catch-all' level of randomness.
Nanoha
Nanoha
I can't remember where I read this and It hink it might be with regards to half life 2's AI but it was soemthign like ensure the first shot always misses.

There were several points to this approach:
Getting one shotted with no warning just isn't fun.
Being narrowly missed adds tot he excitment of the game etc etc

Thats all I can remember (might have been in a book now I think about it).

As others have said about adding randomness to your shots. I think thats probably both simple and effective and you can add less randomness to scale up the difficulty.
Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.
szecs
szecs
Sorry, I haven't read through the posts.

The way I did it:

The AI takes a lot of virtual probe shots, so the wind, the bullet warp mode (none/warp/bounce) and the terrain are taken into account. It takes about 10000 random probe shots. (It seems slow, but even with DOS/VGA programming [=slow as hell pixel color reads] it took about 6 seconds for the AI to "think" in the worst case). So the AI can take some real spectacular shots, even in the trickiest situations.

Difficulty is implemented by simply adding random values to the angle/force of shooting.
The random values depend on a several things:
Wind and turn: the greater the wind, the less accurate the AI will be in the first round. The AI is always less accurate in the first round (like people).
And some other things I can't remember.

Weapons: The AI can buy weapons depending of the difficulty (easy "bots" don't buy nuke or laser), their money (they prefer buying nuke to armor), the amount of the weapons (they wont buy nuke, if they already have 2 pieces of it) and so on. (Was long ago, i don't remember everything.) Randomness is added to these decisions.

Choosing of weapons: In depends heavily on the game type: team deathmatch vs free for all. The AI tries to avoid shooting itself or its teammates. The AI chooses the most beneficial shot from the many possible hits: if it has nuke, and the shot will kill more enemies, the more beneficial that shot is.
If no possible hits, it will use its weakest weapon.
If there are a few players in the game, AI can shoot with baby nukes at a single enemy, but when there are a lot of players, it only uses baby nuke, if it can kill at least 2 enemies.
Same as with nuke, only uses it, if it can kill at least 2 enemies.

Shooting at the same enemy: The AI stores his last good try, (because the randomness will ruin the hit, so there's a probability to miss at first shot). So its first attempt will be that shot, if it still would produce a hit (didn't hit the enemy in the previous shot), the randomness of the real shot will be greatly reduced, so more likely to hit (just like in real life, once you have closed the enemy in, you will be more and more precise).

The AI will try a shot with the current real angle and force too, maybe the enemy has fallen into the spot (when you know you don't have to adjust anything, just fire).

I didn't implement some things for some reason:
1.Choosing between equal beneficial shots: The AI should prefer more dangerous enemies: an enemy that is far away and has low hp means no threat, so shoot the other one. Or shoot the one with more dangerous weapons.
Or shoot the enemy, that is currently aiming him (a bit tricky to determine this thing). The others are easy to implement, I dunno why I didn't add these.
But I added a thing: AI prefers the enemy, that will take its shot after it. (I mean the next shooter.)

2. Taking into account the thickness of the ground/dirt/whatever between the AI and an enemy:
If the AI can't shoot anybody, it starts to demolish the ground between itself and a target (preferable the smallest thickness).

However, the AI can commit suicide (there is a little chance), when none of the 10000 shots produce a hit. I left it that way, so when a deadlock situation occurs, the human player has a chance to win. (later, I introduced a newround console command, but left that in the game anyway).

BTW the AI was a BOT, because pushing keyboard events to the keyboard buffer was very easy with DOS. So the AI pushed the keyboard almost literally, until the adjustment were matching (with the random error) the values it calculated.

EDIT: didn't realize it's an almost dead thread. Didn't know the AI section is so slow....

[Edited by - szecs on February 2, 2010 11:04:32 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.