# Turn-Based AI Question

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

## Recommended Posts

I've been developing a text-rpg for some time now, and I've decided to re-do its AI. I've never done anything with AI prior to this project, so I've just been using my own simple algorithms. In this text game, you and your enemy take turns, starting with you. I've come up with a system where the game weighs how good an enemy action is. For example, if A is weighed at 1 and B is weighed at 2 (all relative), B will have twice the likeleyhood of being chosen as the action than A. I've gotten this to work, but my methods for determining the numbers are not very good. In the game, special abilities are customizable, so I can't just hard-code anything. I have to come up with formulas that evaluate the different possible properties of the ability and rank how good they currently are based on each player's health, weapon... My current setup uses relative arbitrary points which are not balanced really. I was thinking of re-writing the AI using a system like the follwing: Each possible action is evaluated in each of the possible categories. In each category, it is weighed in percent, 100 being representative of the ideal outcome of the special ability. Then, the categories are combined by taking their average, giving the score for the particular action. For example: Let player A have choices of action b and c. b is ranked at 100% efficiency in effect 1 of the list of 2 possible effects of an action, and 50% in category 2. c is rankend at 80%, 0% respectively. Then, a weighted average of effeciencies is take (say 50/50 to make it simple), so b is given a score of 75% and c has 40%. Then, the chance of b is 75 / (75 + 40) and c is 40 / (75 + 40). I'm wondering if this is a good way to go about controlling an enemy's turn. It will hopefully prevent them from doing pointless things, which was a problem with my old AI. Is this a common technique for performing such a task?

##### Share on other sites
WEll, I would say you have to consider a few factors. What is the enemy's role in the combat? What actions does it have available? If the enemies role is to destroy the player as fast as possible, then the best action will be highest damage rate every time. THe problem is, if you figure out the highest damage or "Best" attack every time, players may end up unable to defeat your enemies. Which is why alot of games just randomize most attacks such as final fantasy. They have a few actions that will take presidence over the randomize ones, like if an enemy gets low health it might heal itself. You get the idea though. I'd probably just use some sort of top down AI approach for simplicity.

##### Share on other sites
As GodBeastX said, you should probably make the enemies have some goals also - if it is low on health, it will weight special abilities that heal much higher than normal. In other words, just make the weighting for each category dynamic depending on the situation and the AI will appear much more intelligent.

##### Share on other sites
I have encorporated some of the weighing aspect into the AI. I ended up using weighted randomization and it seems to work reasonably well. I will be releasing version 1.0.5 of my game with full sorce code (which includes the AI redesign) in a few day on my web site at http://www.angelfire.com/games6/drunken_brawl.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 12
• ### Forum Statistics

• Total Topics
634116
• Total Posts
3015598
×