Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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).

share|improve this question
    
Dammit, HTML5 developers... –  jco Aug 4 '12 at 20:12
1  
@Bane: Problem? –  Lambda Dusk Aug 4 '12 at 21:52
    
Quite a few, actually. I was just joking though :) –  jco Aug 4 '12 at 22:11
    
+1 For ponies! :D –  Miguel Aug 17 '12 at 4:28

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
+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? :) –  Miguel Aug 17 '12 at 4:32
    
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. –  Kaliber64 Aug 19 '12 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.