I'm implementing an App for fun. It consists of a soccer round-robin tournament simulator in which all teams play each other. A Team consists in a simple object:

class Team{
  String _teamName;
  double _defensePower; // 30..90
  double _attackPower;  // 30..90

and Match is:

class Match {
  String _info;
  Team _homeTeam;
  Team _awayTeam;
  int _homeScore;
  int _awayScore;

So I would like to use an algorithm to simulate each one of these matches.

Each match simulation will be sliced in a loop with 90 steps (each step represents a minute in the game in which one of the teams will have the chance to score the goal).

The simulation must take into account the level of attack and defense of the teams, but with a good deal of unpredictability.

The result of the simulation should be a match with scores that are normal for soccer matches, such as:

home 1x0 away
home 0x0 away
home 2x3 away
home 4x0 away

Is there an algorithm that I could use to make this simulation?

  • Cool, have fun! But what is the question?
    – JacquesB
    Feb 16, 2019 at 15:05

1 Answer 1


With such limited information it is of course not possible to create a meaningful simulation, but it is possible to create an algorithm that spits out reasonable-ish results.

For example, you can define a number representing the game state (for example on the interval -1..1).

  • In each simulation step, the state is altered by a (normally distributed) random number scaled by the team's defense/attack power.

  • If the game state crosses a threshold, that is counted as a goal and the game state resets to the neutral position.

This is effectively a kind of random walk over the one-dimensional game state space. If you only have a finite number of possible game states, that would be a kind of Markov chain where the defense/attack power influences the transition probabilities.

Another approach would be a DnD style skill check mechanism, where a random number is added to some ability modifier, and if that number clears some threshold some action is performed.

You can of course add whatever mechanisms you like, for example per-team states like “defense”, “penalty”, “red card”, “ball possession”, and can mix and match various simulations – as long as this is not excessively complex and fun for your application.

The difficult part of this is balancing your mechanics to produce realistic results. You might want to create statistics of real-world match results, and tune your system so that it produces similar results (you don't want to simulate a match that ends with 20:1). Some mechanisms might have simple multiplicative or additive terms that you can use for tuning, without having to add extra balancing mechanics. You could also treat your simulation as a machine learning algorithm that must be trained on real data, and try to perform this tuning with an automated tuner (key word: hyperparameter tuning/optimization).

As statistics for tuning I would suggest by starting with average and median number of goals per side and goal difference between the sides, and later perhaps use distribution-based metrics such as a Chi-squared test to see whether the simulation produces significantly different results from real data.

  • thanks. I end up implementing some kind of random walk based on your answer.
    – alexpfx
    Feb 17, 2019 at 1:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.