Developing the battle algorithm for ForEverAll has been the biggest challenge so far. Not because the code behind it is complex or difficult to implement, but because there are some maths, balances, and various stats to consider. I want to allow players to challenge one another to a battle – the winner getting some amount of experience points, and possibly a small monetary gain. However, I want to ensure that there are limitations and balances in the system; a level 1 player shouldn’t be attacked by a much more powerful and well equipped level 20 player. Players should also feel compelled to attack other players in hopes of a good outcome based and a nice reward. On the flipside, new players shouldn’t feel discouraged or targeted. So with all that in mind, a fair and balanced Battle Algorithm had to be implemented.
I recently read about a simple and easy to implement rating system: Elo Rating. It was invented by a physics professor. It was widely adopted and applied to many sports and games over the years, so if it’s good enough for everyone else, it’s good enough for me! I thought about ways I could incorporate a fair and balance ‘rating’ system, and so I came up with the BR (Battle Rating) which is strongly based off of the Elo Rating system. I also looked into Microsoft’s TrueSkill™ Ranking System which seems very interesting, but involves more calculations and back-end than I am aiming to build for Beta.
Battle Rating (BR) takes into account your character’s gear (equipped armor and equipped weapon), your level, some various stats (e.g; accuracy, battle reflexes), and how many battles you’ve won and lost. This calculated number then determines a range of players you can fight. If you’re within 50 points (above or below) another player, you’ll be able to fight them.
(armor + weapon) + (level + battle_reflexes + accuracy) + (battle_wins / battle_losses) / 10 = BR
In addition to the above, your BR will decrease/increase with each battle. If your BR is lower than your opponents and you come out victorious, your BR will increase quite a bit. If a person with a higher BR beats you, their BR will only increase slightly.
Since the native battle system can be taxing on your health and weapon / armor conditions, it’s important that a win rewards such risky behavior. Sure, we can reward winning players with experience points, but a monetary reward also makes battling more lucrative. Couple that with a gain in your BR and you’ve got yourself a fairly interesting set of mechanics. The idea will likely involve the amount of credits (CR in game) the defeated player has, and then calculating a very small percentage of that. This idea also leads to the need for allowing players to store their money in a secure vault (not yet implemented) so that the richer and stronger players aren’t a constant target.
Example Flow of a Battle
In order to get a better idea of the battle flow, here’s a breakdown:
- You challenge a player to a battle (assuming both BRs are within range).
- The system then sets your armor’s health, weapon damage, and calculates who goes first (based on Battle Reflexes).
- The main battle loop begins – once the armor’s health is depleted, the player’s health begins taking damage.
- The battle loop ends once a player’s health has reach (or falls below) 0.
- The battle system then awards players, updates the DB to reflect wins/losses, weapon/armor conditions, and then sends notifications of what happened to the challenged player.
- The BR then gets updated based on the battle’s results.
In the end, this system is simple, yet ensures a mostly fair and balance flow. The current implementation allows me to easily modify and adjust the code and main battle loop, it’s also good enough at this point for me to include with a beta launch.