I am writing a game for gameboy advance and I am implementing basic AI in the form of a binary search tree. There is 1 human player and 1 computer player. I need to figure out a way of telling how aggressive the human player is being in attacking the computer. The human will push a button to attack (and must be in a certain radius of the computer), so my first thought was to see how big the number of attacks was compared to the number of iterations my main while
loop had gone through. This seems like a poor way to do it though, because that number will depend on the frame rate, which can fluctuate. Does anyone have an idea for a better way to do this?
views:
278answers:
4You can use a pseudorandom generator for that. Say you have a rnd() function that returns a value from 0 to 1 - greater value corresponds to higher agressiveness. You introduce a coefficient from 0 to 1. Each time you need to determine whether the character would attack you call rnd() and compare the value with the coefficient. If it's greater than that - attack, otherwise not.
Why not just keep a count of the number of moments the human player can attack the computer player? I mean, you obviously have to check to see if he's in range, so why not check whether he's in range, and if he is, increment the could_have_attacked
counter. Then if he actually does attack, increment an attacked
counter. Then you can compare how often the human player attacks to how often he has the opportunity.
Alternatively, compare how often he is in range to how often he is not in range, or more generally keep track of the average distance between the players. More aggressive players will probably stay a lot closer to their opponents than passive players.
Your best bet will probably be a combination of different methods. Keep several different measurements, and try several different ways of weighing the methods against each other, and use extensive playtesting to pick which one is better.
You have to define what aggressive is. For example, you could say aggressive is a player that pursues the AI, so you would check whether he is in range more often than he is out of range. Or you could say aggressive is a player that attacks every chance he gets, so you would check the ratio of successful attacks to the amount of time the player has to attack. Or you could say an aggressive player will attack when he is injured. Once you define what "aggressive" means in your game world, you can establish key performance indicators of when the player falls under that definition.
I thought of something along the lines of counting the average time between combats and counting the average rate of fire while in combat. To do so, you would need 5 variables like this:
float avgTimeWithoutCombat;
float currentTimeWithoutCombat;
float avgRateOfFire;
int shotsFired;
float combatTimeElapsed;
As long as the player does not fight, you count the "peaceful" time in currentTimeWithoutCombat. When he fires, add it to avgTimeWithoutCombat and divide it by 2 to get the average.
Everytime the player attacks, increase the count of shotsFired. Also, count the time of the combat. Check in the main loop if a certain time without any attacks elasped. If so, the combat has ended and you can calculate the avgRateOfFire.
Now you have two values to measure the aggressiveness of the player:
- avgTimeWithoutCombat: The bigger this number, the less aggressive is the player.
- avgRateOfFire: The bigger this number, the more aggressive the player.