Skip to content

EmanuelButoiGit/football-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ† Football Simulator ⚽

Genetic Algorithm Unity Built Strategy Evolution GitHub

This Football Simulator uses genetic algorithms to figure out the best football strategy.

πŸ”— See it in action: YouTube Video Link
πŸ•ΉοΈ Give it a try: Itch.io Link

πŸ— Building my own simulator

I didn’t have the simulator to create the algorithm and test it, so I tried to create my own simulator with Unity.
I built this simulator based on the Volta mode in FIFA.
While you can play in team sizes like 5v5, 4v4, and 3v3, this simulator focuses on 3v3.
I wanted to use the three formations from Volta as parts of a chromosome. But it was too complex to do.

Formation Formation Formation


πŸš€ Setup

To get the simulator ready:

  • Attach "BallScript" to a sphere.
  • Make a player using a capsule and add the "FollowBall" script.

Capsule Ball


  • Use cubes for goal posts and add the "GoalScript"

Goal Script


Another thing that I would like to mention is that I created an aquarium-like pitch so the ball won't jump outside.
The other scripts will be active in the environment and you need to assign the right Game Objects to work.

⚽ Football Strategies

Klopp

I did not add actions as a strategy like in this paper.
A strategy will be a combination of formation and player type and a player type will be a capsule with different attributes.

Players can be:

  1. Midfielder
  2. Attacker
  3. Defender

Just like in Volta!

🧬 The Genetic Algorithm

The initial population will be populated with random strategies.
Here, a chromosome might look like: 132, 111, 212, ... where each part tells the player type.

What's the aim? πŸ₯…
Find the best strategy. Teams play in tournaments and the algorithm pick the best team based on their points (which will be the fitness target).

World Cup group Stages


How do we select? πŸ”„

  1. The classic method: Best of 2.

Mating is done by combining genes based on random probabilities. If probability > :

  • 0.45 => we take the first parent
  • 0.90 => second else random gene
  1. Geek for Geek Method:

Perform Elitism => 10% of the population goes straight to the new generation 50% of the rest of the population will mate to produce new offspring. Mating will be the same as presented in the previous method.

πŸŽ“ Reinforcement Learning

For better AI, you could use Reinforcement Learning to generate a brain model that could be used for the players, for the AI agents.

Training with RL


There are some steps when implementing something like this:

  1. Watch: Gather data.
  2. Think: Decide using data.
  3. Act: Do something and get a reward if it's good.

πŸ“Œ Other things to mention

Mou screaming

It would be nice in the future to add different colors to individuals to see exactly which individuals are in that team.
I did add a short population and duration of time because of limited time.
It would be also interesting to scale the project (to add more players, more tactics, more attributes and to fix formations).

πŸ’‘ Conclusion

Genetic algorithms are crucial for making the player experience more unique and adding unpredictable complexity!

Releases

No releases published

Packages

No packages published

Languages