Sign in to follow this  

Tank game ai

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im makeing a tank game and i don't have any good ideas for the ai. its a simple game, theres only 4 dircetions u can move. basicly ur on a blank screen and ur faceing an ai controlled tank. i don't have any ideas about the ai for this game. if ur wondering, this is the seconed game i ever programed so it kinda sucks.

Share this post


Link to post
Share on other sites
I suggest making it move largely randomly and fire at the player from time to time, if they're in range.

Ideally make it try to stay at about maximum range too.

Oh yes, and you might want to take some English lessons.

Mark

Share this post


Link to post
Share on other sites
Let's say the enemy tank's main objective is to get you 'in its sights'. Since there are only four directions, it needs to get aligned with you along the x or y axis. At any time (if it's not already aligned with you), there are two choices for direction that will move it towards alignment. A simple choice is to move it in the direction that will reach axis alignment with the player first.

When the tank becomes aligned with the player along an axis, it turns toward the player. It's then lined up to fire.

This is probably the simplest approach possible and doesn't incorporate target leading, randomness, etc. But if this is your second game, it's probably a good place to start.

Share this post


Link to post
Share on other sites
For the tank's movement: every five seconds (or some other similarly small time interval), give the AI tank a new destination for it to travel to. Draw a line (not literally on the screen, but in theory) between the tank and the destination. If the player tank intersects this line, reset the destination point (to a random pos). Otherwise, reset the dest on some set time interval (like 5 seconds).

For the tank's attacks: as people have said, define a range the tank must be in for firing to be valid. If it is in range, give it some percent chance to fire, and then just let it fire (of course in the general direction of the player, which would require some vector algebra).

Share this post


Link to post
Share on other sites
Go to the consoles and PDA forums and download Tank Commander. It uses a simple AI that mimics decent tank behaviour (IMO) :)

The way I made the tank AI was as follows:

Create different actions:
Turn left
Turn right
Move forwards
Move backwards
turn and move left forward
turn and move right forward
turn and move left backward
turn and move right backward
turn towards player (or target)
turn and move towards target
fire

Each of these actions takes two parameter:
pause and duration

Pause is the amount of time the tank will wait befor executing the instruction (by just sitting there)
and duration indicates how long the tank will do the action for. We never work with angles, just time.

Now that you have your different actions, you can make some canned responsese:

i.e. on collision = ( turn left or turn right or backup or turn left and backup, etc...)



There are three distinctly different 'AI's in Tank Commander.

1. Wanderer
2. Zig Zagger
3. Seeker

Each of these 'AI''s works by getting different probablities of selecting an action.

A wanderer has an almost equal chance of doing anything-- for 'realisim' it will mostly move forward, seldom backwards.

A ZigZagger will turn until it faces the player, and then continue turning in that direction of a random duration. After that it will move forward for a random duration.

A seeker has a high probablitiy of turning and moving towards the target.

To make your tanks more or less difficult you can add offensive and defensive behavior.

For example, if the player fires a shot then any tank in front of the player should change their current state-- instead of moving forward maybe it will move backwards, or stop, or turn left, etc... It doesn't really matter what it does, just as long as it is possible it does something.

For offensive behavior: tanks are always on a shot timer; they can only shoot once ever 10 or so seconds. If the tank finds it's facing the player (generally facing, not exactly bang on) and it can shoot, let it. You adjust the difficulty of the tanks by inserting a delay; easy tanks will stop for 2 seconds before they fire while hard tanks will shoot on the run.

To make it so your tanks appear smart by leading the player, just dont ever have them shoot directly at the player. Whenever they are withing 10 degrees, or 5 or whatever you want to do, have them shoot.

The end result is a bunch of brainless rules that when combined give a pretty decent illusion of a 'thinking' tank.

By coincidence, with the rules and timings I put in to TankCommander, the tanks often look like they are using terrain as cover.






Share this post


Link to post
Share on other sites

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this