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
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.
To get the simulator ready:
- Attach "BallScript" to a sphere.
- Make a player using a capsule and add the "FollowBall" script.
- Use cubes for goal posts and add the "GoalScript"
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.
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:
- Midfielder
- Attacker
- Defender
Just like in Volta!
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).
How do we select? π
- 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
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.
For better AI, you could use Reinforcement Learning to generate a brain model that could be used for the players, for the AI agents.
There are some steps when implementing something like this:
- Watch: Gather data.
- Think: Decide using data.
- Act: Do something and get a reward if it's good.
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).
Genetic algorithms are crucial for making the player experience more unique and adding unpredictable complexity!