# Calculate winner of battle when auto is chosen

There are two slightly different scenarios I am interested in and I'l give you examples of each.

The first is like the tournament system in Super Smash Brothers Melee, when there can be dozens of cpu vs cpu battles and it has to choose a winner. This could be done with a random number generator but I feel there is something more there.

The second is in some games, mostly strategy games, you can choose to play a battle or have the computer calculate the battle for you. The game Medieval: Total War comes to mind, where it calculates how many troops you and the computer lose. In these scenarios, it never goes as well as if I had done it myself but I usually win if it is plausible.

What I want to know is, how are these battles are calculated? Does anyone know how it is done, or have an idea of how to implement it?

I had an idea of just doing the battle normally but disabling all graphic display so it would conclude very fast, but I'm not sure this would work too well.

-
Chances are it just calculates an attack/defence rating for each unit and does it entirely on probability. You could use standard AI technqiues to simulate an actual battle, but there would be little payoff for the extra time needed. – The Communist Duck Jun 14 '11 at 13:05
@ The Communist Duck maybe but in total way if you send all peasants against horses you get stomped even if you outnumber 10 to 1. would you probability account for that, i never really looked into probability – Skeith Jun 14 '11 at 13:29
I added to answer for better formatting – Jonathan Connell Jun 14 '11 at 15:14
@3nixios that would make it 4/3/5 against 10/10/50 and would end up with an outcome of something like 2/1/2 and 11/9/8. "simple maths" is not an acceptable answer as it would never produce results close to ones I see in commercial games. – Skeith Jun 14 '11 at 15:18
Actually 'simple maths' with randomness is very acceptable, think of how strategy games work, in fact, any games work. A winner in any given situation is just an outcome of simple math functions with a bit of randomness to add spice; damage in an FPS, Beat 'em Up, RTS, is all just simple calculations. Obviously it takes work and is difficult to balance, which is why each character in Street Fighter 4 had an individual game designer working on them for example... – Jonathan Connell Jun 14 '11 at 15:44

Probably there is not a single answer for this. To be generic, you should use a model for the battle and put some order of randomness on it.

The random may be the weighted dice trown to se who wins a direct fight (as in Risk or D&D) where your model computes the direct fights.

Another aproach may be that both the contenders choose a random strategy and the match of this couple generates the direct fights to compute through another random number.

The strategy can be choosed by each army unit accounting the unit's nature or personality, a Markov chain can be used to move the army or each army unit from a strategy to the next taking into account the current overall result.

In any case what you do is to choose a granularity between a model for the battle and the success of a dice trown and keep it secret. Notthing is more boring that know how the battle will finish because you know the dynamics.

corollary: who designs a game hardly finds it enjoyable as is for the rest of the world.

-

The idea of doing the battle "normally" (usually multiplying any time deltas to make it go faster) is a simulation approach, like used in Football Managers, etc.

This approach has the benefit of being precise and if it is an option to 'skip' the battle, it is also reusing game code with an AI replacing the player.

A random number generator can work, it all depends on your needs. You could couple this generator with simple calculations dependant on player stats (wins/losses, strength, etc.) and use these to determine the outcome.

It is a fine balance between simulation and randomness when the only data the player has is the starting state and the end state. You need to balance it so that the player doesn't have an advantage in skipping battles if it is optional because he will prefer not to play. He also needs to feel that he is not cheated out of an easy win.

-