In our latest mystery game the player will use Agents, individual governing “heroes”, to enact their plans for world domination. The Agents will lead the people of your empire, they will convert the benighted heathens (through economic enticement or religious fervor), and they will defend your name across the land. But what happens when two Agents meet?
Enter the Challenge Mode. In Challenge Mode two opposing Agents will attempt to overcome each other through their brute charisma, cunning, and blind devotion to you, their ruler. So how do we resolve these conflicts?
While the rest of the team works on allowing our game to actually run, that is resolving core game mechanics and overcoming nasty technical issues, I’ve been messing around with how to answer the above question. I thought I’d take you through how one goes about doing something like this and give a little insight into how math can be fun! (really!)
So, when figuring out which Agent is “better” we must first take inventory of what we have to work with. In the case of our Agents, it’s not hard, because Agents only have two attributes, Economic Skill and Religious Skill. Now there a lot of things you can do with two numbers, but in the case of a game it’s usually wise to match your numbers with some sort of story. For example, we could take Religious Skill, raise it to the power of Pi, and then add Economic Skill factorial. Now we could do that, but what the hell would that amount to? And what sort of story would match such a math circus?
Instead, we decided to create the story that the most “well-rounded” Agent is the superior Agent. In other words, an Agent with comparable Economic Skill and Religious Skill will be more powerful than an Agent heavy in one area and weak in another.
Consider the four Agents below:
| Agent Name |
Bob |
Bill |
John |
Jim |
| Religious Skill |
11 |
15 |
21 |
5 |
| Economic Skill |
9 |
5 |
2 |
6 |
Bob would beat Bill because Bob is a more evenly balanced Agent. However, consider our next two Agents, Jim and John. John is clearly a more skilled Agent, should he be beat out by some noob like Jim? No, we answered, no he shouldn’t. To remedy this problem, we introduced the concept of level. Level is simply the sum of an Agent’s skill points divided by 3 (rounded down). In the above example, Jim would be level 3, John would be level 7. Though Jim may be more evenly developed, John is a beast and should beat Jim due to his age and experience. Now that we’ve got the concept, or story, we want our Agent Challenges to follow, we need to find an algorithm that will accurately express it.
Let’s break the algorithm down into parts. First we want to check for a healthy balance. To do this we’ll divide. Take the lower of the two skills and divide it by the higher. If the numbers are close, you should come in somewhere near 1, if not, you’ll have a small fraction. Next, to find just how far you were from a perfect balance, subtract 1.
Once this is done you’ll have a fraction. If you were balanced, you’re close to 0, if not, you’re closer to 1. Now it’s time to compensate for the Agent’s level. To do this we subtract half the level of the Agent. If the final number is a larger negative number, you come out on top. If it’s a smaller negative number, you have been overcome. This isn’t the only algorithm for determining the worth of your Agents in a challenge, but it produces a clean and accurate comparison with fairly nice numbers. Here is the final beta algorithm in the Challenge method for your viewing pleasure:
static String Challenge(Agent one, Agent two)
{
String lowest;
double oneFigure = Math.Abs((lesserSkill(one.getESkill(), one.getRSkill()) / greaterSkill(one.getESkill(), one.getRSkill())) - 1) - (one.getLevel() * .5);
double twoFigure = Math.Abs((lesserSkill(two.getESkill(), two.getRSkill()) / greaterSkill(two.getESkill(), two.getRSkill())) - 1) - (two.getLevel() * .5);
decimal oneFigureFinal = decimal.Round((decimal)oneFigure, 2);
decimal twoFigureFinal = decimal.Round((decimal)twoFigure, 2);
if (oneFigure < twoFigure)
lowest = one.getName();
else
lowest = two.getName();
return (one.getName() + ": " + oneFigureFinal + ", " + two.getName() + ": " + twoFigureFinal + "\n" + "Winner is " + lowest);
}
Filed under:
Coming Soon