8
\$\begingroup\$

I built a 2D fighter http://neighr.com/mif/index.html yesterday.

The second 'player' does hardly anything. Actually, nothing. To be honest, I have never made a game before that had an opponent like this.

So my question is, how does one start with AI programming for the opponent? Are there any tutorials, any best practices? I want it to be a challenge (for the player, not myself).

\$\endgroup\$
0

3 Answers 3

12
\$\begingroup\$

N-grams are popular here. The basic idea is to keep a list of moves the player has made. You can then, given the last N moves of the player, figure out percentage likelihood of what his next move might be.

Your game should have a database of effective counters and blocks to each move.

For offensive modes in the AI, you can still basic player modeling to determine which attacks the player has had the most trouble blocking or countering, and reuse those.

For AI difficulty, just dumb down the AI at easier levels. The worst AI mode might invert choices (that is, if it knows the player usually blocks punches, it has a higher rather than lower chane to throw a punch). The highest difficulty mode would use the non-handicapped algorithm, and is likely going to beat the crap out of the player.

If you're looking to make the game more fun, I also recommend adding personality to the AI. Some characters might taunt more, some might be more defensive than offensive, etc. players enjoy being able to ascribe human intelligence to AI characters.

\$\endgroup\$
3
\$\begingroup\$

Honestly as much as some of the top answers recommend more complex AI, If this is an early attempt at a game and you're not that skilled with code yet, you might try for a more dumb AI

For example a simple system of

wait (0-3 seconds)

Roll d6

pick from 6 actions.

Or something similar depending on how many actions you have

\$\endgroup\$
2
\$\begingroup\$

This is how i would go about making ai for a fighting game.

Make lists of moves (depending on char) that are appropriate for different distances away from the player and have him pick a move.if the difficulty is set on hard. Have him pick a hard hitting move. Otherwise pick the move that does less for medium and less for easy. You can also throw in a random factor that picks different ranges from the one that player is actually at depending on difficulty. The amount of decisions should be based on difficulty where he evaluates 3 seconds after each move(easy) 2 seconds(medium) ect. Each time determining his course of action.

summarizing, pick a distance(move set), pick a move and then how long they wait before they do the same thing. In between waiting for the next action they can strafe and dodge by chance. Hope this helps.

\$\endgroup\$
2
  • \$\begingroup\$ +1 This is an extremely simple, yet absolutely viable & efficient solution. By any chance, would you happen to know if a system like this has been used in any commercial games? :) \$\endgroup\$
    – Miguel
    Aug 17, 2012 at 4:32
  • \$\begingroup\$ No I don't. I'm speaking from very little experience. So if its any good, and I thought of it. Then surely I'm not the first.(if its any good). N moves would be smarter. But harder. \$\endgroup\$
    – Kaliber64
    Aug 19, 2012 at 1:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .