• Advertisement
Sign in to follow this  

AI in RPG game

This topic is 1907 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

Hello everybody,
not sure weather this post should go in the Ai category, i've got 2 questions for you all.

So ive been doing lots of c++ recently and i think i'm ready to make an rpg.

1)I was looking at games like dragon warrior for a good start. Then I thought, there must be Ai involved (beacuse the monsters actually have to think to pick moves). I do not know anything about Ai programming and where to start it. I thought that maybe just a random rumber system would work, but it would make my game extremely dumb and artificial.
Any advise, guides, anything?

2)While this is obviously a highly debated subject, which c++ api should i use to make my game.
I've decided to use DirectX for 3d games( is that a good option?) , but my rpg is going to be 2d:
Which C++ Api is best for 2d games? : I tried SFML, but it didn't have some key features like animation.



Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
Ai for something like dragon warrior probably can be done with state machine ai - as in bunch of if -> else if combinations that ai can use. I think this is probably the way most of ai's work. As for the second question you could try SDL it has everything you will ever need for 2d rpg game, this is something i would use for 2d rpg game myself. Edited by proanim

Share this post


Link to post
Share on other sites
All you need to know about simple RPG AI you can learn from Final Fantasy 12. (You can create an AI for each of your characters in that game using the "gambit" system, with additional slots for making the AI more complex as you level up. Looking up a guide on the gambit system could probably give you a general idea of how these things work.)

In most simple RPGs the AI is simply a series of condition tests (looking at things like HP values, turn number, etc) that are in order of preference and end with a 'default' action.

[source lang="cpp"]ACTIONENUM chooseAction() {
if(myHP > 100) {return FIRE_BREATH;}
if(turnNumber == 3) {return HEAL_ALLY;}
if(enemyHP < 50) {return FINISHING_MOVE;}
return BASIC_ATTACK;
}[/source] Edited by Khatharr

Share this post


Link to post
Share on other sites
A lot of turn based strategy games can make good use of a minimax algorithm. This is good for deciding which action is the most effective one before executing it. Do you run away and heal your character? Or do you close in with the enemy and try to deal more damage? With the minimax tree, you can play out all the possible scenarios and responses to see which one is best. So, if the enemy is a warrior and you run away and heal, the warrior will have to chase you to attack the next turn. But, you can run out of his range, so this is a "good" move. If the enemy is a wizard and you run away and heal, he'll just cast a ranged fireball at you, dealing more damage than you'd heal. So, its more beneficial to just attack the wizard and do what damage you can.
If you build your game model correctly, you don't have to write pages of complicated If statements to capture this type of reasoning. Just give your minimax tree a list of the possible actions your character can do each turn, the possible responses, counter-responses, etc. and let the algorithm calculate the best move based on the scenario.
For complicated games like Chess, where there are dozens of possible moves each turn, your tree is going to get a lot of breadth. Since the essence of chess is thinking further ahead than your opponenet (and not making mistakes), breadth * depth will start to great very large trees. This will create some memory and processing limitations as the tree grows large. So, typically the tree depth will be limited to a set point. If the player chooses the easy difficulty setting, then the AI may only maintain a depth of 5 tree. If they choose medium, the AI will maintain depth 10 tree. If they choose hard, they'll get a depth 15 tree. The harder the AI is, the more time it will need to spend building deep and wide trees and evaluating the best branches to traverse. If you want to go insane, build a super computer with massive banks of CPU's and RAM and let the depth go really high, like 40. You'll get something like Deep Blue which can take on the worlds greatest chess players.
One technique you can use to save yourself some processing and RAM is to prune the tree a bit. If there is an obviously bad move (such as putting yourself into checkmate or losing your queen), you can stop traversing any subsequent moves down the tree. This is what people are really good at. The techniques for trimming and pruning your decision tree is where the specialized AI programmers differentiate themselves from the unspecialized programmers (I'm just a unspecialized programmer).

If your game is running in real time, you *may* be able to still get away with using this. If every ability has a cooldown time before it can be executed again, you can create a turn which is a set timespan in which actions can be performed, ie, you can swing your sword three times every five seconds, so a standard turn lasts for five seconds. Scripting complex if/else statements consisting of actions may also be a good way to go.

Share this post


Link to post
Share on other sites

A lot of turn based strategy games can make good use of a minimax algorithm.


I think you've misunderstood both the genre and depth of involvement in the Dragon Warrior series. People don't like RPGs where the enemies are impossible to beat. Minimax is great for strategic games, but simple RPGs rely more on giving enemies cool-looking and overpowered abilities while leaving them with a fatally flawed strategy. The fun of that kind of game is finding the flaw in the enemy's strategy and exploiting it to beat them. Edited by Khatharr

Share this post


Link to post
Share on other sites

I've decided to use DirectX for 3d games( is that a good option?) , but my rpg is going to be 2d:
Which C++ Api is best for 2d games? : I tried SFML, but it didn't have some key features like animation.

Thanks in advance for any help.


You aren't going to find an "Api" set that has animation built in. You might find some engines that help with that. A previous used suggested SDL, well, it's OK, but it doesn't have built in animation support either. I think SFML is perfect for C++ 2D game development. You'll have to learn to handle the animations yourself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement