Jump to content

  • Log In with Google      Sign In   
  • Create Account


AI in RPG game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 infernapelover   Members   -  Reputation: 160

Like
0Likes
Like

Posted 02 November 2012 - 03:52 PM

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.

Sponsor:

#2 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 02 November 2012 - 04:37 PM

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, 02 November 2012 - 04:40 PM.


#3 Khatharr   Crossbones+   -  Reputation: 2936

Like
2Likes
Like

Posted 03 November 2012 - 05:26 AM

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, 03 November 2012 - 05:33 AM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#4 slayemin   Members   -  Reputation: 2267

Like
2Likes
Like

Posted 03 November 2012 - 06:52 AM

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.

Eric Nevala

Indie Developer | Dev blog


#5 lride   Members   -  Reputation: 633

Like
1Likes
Like

Posted 03 November 2012 - 07:27 AM

Start with Programming Game AI by Example
In your case, implementing a finite state machine is suitable
An invisible text.

#6 Khatharr   Crossbones+   -  Reputation: 2936

Like
0Likes
Like

Posted 03 November 2012 - 05:55 PM

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, 03 November 2012 - 06:00 PM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#7 BeerNutts   Crossbones+   -  Reputation: 2758

Like
0Likes
Like

Posted 03 November 2012 - 10:24 PM

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.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS