How to improve monster ai text adventure and how,
Members - Reputation: 220
Posted 12 January 2013 - 04:15 PM
Thanks in advance
Crossbones+ - Reputation: 3213
Posted 13 January 2013 - 01:15 AM
For starters you could implement probability into the AI. The choice between hit head, hit body, and miss should not be an equal probability. Really missing or not missing should be one probability at least (Let's say he misses 40% of the time).
Then the decision to hit the head or the body (in this case) could be dependent on a number of factors. How good of aim does the monster have? If the aim is poor then aiming for a headshot would not be a good decision to make (aim for center of mass). Also perhaps hitting the head vs the body have different percentages. Hitting the head is a smaller target and thus would have a higher probability of a miss.
This is of course still random variables but at least there is some basis behind the variables.
Now of course if you were fighting our would be hero... you would likely make decisions based on the hero's state. If the hero was high health and you were low health then it is likely that you would flee. Potentially you would try to block more. Also you would likely choose to do a body shot because it has a higher probability of not missing. (Although stupid enemies might not realize this fact).
Conversely if you had high health and you knew the hero had low health then you might be more aggressive and prone to taking chances. This would mean an increased chance of trying head shots even if they were a lower probability because the head shot could induce more damage.
So we can translate this into psedocode:
If enemy health is low and player health is low then try for a body shot. Try for a head shot with a low frequency (Maybe 10% of the time). Maybe 50% of the time attempt to flee/dodge (if that is possible).
If enemy health is high and player health is high then try for a head shot or a body shot randomly.
If enemy health is high and player health is low then try for a head shot with a greater frequency (although maybe pick body shot 30% of the time)
Then remember to factor in your combat engine the chance of actually making the shot. Since a head shot has a lower probability of being made that would mean that the chance of a miss increases. The chance of a miss for a body shot would be less. You could also potentially factor in the enemy health and make that affect the probability as well. Perhaps the probability of making any shot decreases if the enemy health decreases.
On implementing probability it is rather simple. If you generate a value between 0 and 99 and then test to see if the generated value is say less than 25, then you will have an event that will occur 25% of the time.
Mostly I would use if statements to make decisions based on the state of the game and then have a probability of taking certain actions as a result of those decisions (which could be adjusted depending on the skill level of the monster). It wouldn't be very fun if the monster ALWAYS made the same decisions with certain conditions.
Edited by shadowisadog, 13 January 2013 - 01:43 AM.