Dear Wesnoth developers and users,

I happened to think about a framework to balance Battle for Wesnoth. The core idea of these few mathematical principles is to automate the balancing, so that there is no need to play actual games to balance units, but several games can be simulated without any actual display, and the result can be exploited using algorithms to fit unit characteristics. Since the formalism here is quite general, there may be other applications I do not suspect.

I have some programming skills but I'm not used to Lua scripting so I'm open to any suggestions about how this could be implemented. Also, I would like to open a general discussion about how game balancing could be automated using mathematics, since this could be of tremenduous help for modders, and even core game developers.

A theory to automatically balance Battle for Wesnoth unit/terrain characteristics

Battle for Wesnoth is a turn-by-turn game where factions fight to kill other leaders. The complexity of the interactions between the units, and the unit/terrain interactions, prevent a complete theory to be made that would predict the winner from any starting situation. However, multiple tests on a sufficiently big map with a sufficiently large number of units over a sufficiently large number of turns may enable to calculate an overall contribution for each unit type at each turn for a given situation. Game balancing could then be achieved by examining the average contribution of all unit types over a representative set of situations.

Assuming that the particular size and configuration of the map does not influence the final outcome, and not considering any alliance, what characterize a situation is a set of numbers:

- The proportion matrix of each k-th unit and terrain for each i-th player P;

- The number of players N.

The outcome is the victory vector v, of which each element vi is 1 if player i wins and 0 otherwise.

Let us assume a multilinear function f of the proportions of each unit and terrain for each player, bounded between 0 and 1 and of which the rounded value is vi:

( 1 )

( 2 )

In eq. 1, [ ] denotes the rounding function.

Or, generalized for all N players as a vector equation:

( 3 )

For each situation, the objective is to find the vector of contributions c, containing all ck that minimizes the distance between f and v. The error vector is:

( 4 )

The problem is to find c that corresponds to the minimal possible values for the norm of the vector of squared ei. This is an ordinary least square minimization problem which can be solved in python language using pandas, for example.

Over a representative set of M situations, the average of the contribution vectors is the balance vector b:

( 5 )

For a fully equilibrated and balanced game, ideally, the elements of the b vector should all have a close value if all terrains have the same weight.

Starting from this representation, several algorithms could be imagined. We could, for example, simulate several starting situations with the same terrain but different proportions of units. We would then tune unit statistics such that the average over all different unit proportions yields a balance vector with closely equal bk elements. We could also imagine tuning unit statistics so that maps with a lot of forests give the same advantage to elfs than maps with a lot of hills/mountains give to dwarves. To tune these statistics, a general meta-algorithm could be imagined (it might take some calculation time) which would automatically minimize the distance between a targeted balance vector and the actual obtained balance vector by tuning the unit characteristics (HP, damages, capabilities...), using, for example, a Monte Carlo or simulated annealing approach or some combination of optimization method.

All the best, with the hope it can open an interesting discussion! Do not hesitate if you have any questions, as the mathematical formalism may pose some difficulties!