Football Simulation


First, a demo

The premise

The client required a somewhat realistic football simulation to generate data at a large scale to train a model, while also providing human-friendly visuals (like a game).

Implementation

With modularity in mind, we set out to create a believable football simulation.

Staging system

To get data to train any model, we must provide a way to initialize the environment. In our case, I created a GUI system for the user to:

  • Place players of each team on the field
  • Set certain parameters of each player such as wandering distance, tackling distance, chasing tendency etc.
  • Set starting points of players

Tracking subsystem

Using subsystems, I created utilities for:

  • Handling zones for each team
  • Handling chases for each team (The Chase System)
  • Handling tracking of which player has the ball
  • Tracking what major actions have recently occurred, e.g. shooting the ball, successful tackle attempt etc.

Chase system

I got the idea of the chase from The AI of Marvel's Spider-Man | AI and Games #74, where Tommy Thompson describes how the enemies decide to attack the player using a centralized Combat Orchestrator. The described system has to needs to consider non-realistic factors such as "We should not overwhelm the player", "We should not attack the player in a way they cannot avoid such as offscreen startup". With these considerations in mind, the Combat Orchestrator designates enemies as attackers, tells previous attackers to chill/idle etc.

The chase system in football sim acts similarly. When a player of the opposing team gets the ball, the chase system scores all players of current team and picks the top players (number depending on initial settings) to chase the ball. As the chase progresses, some of the picked players become highly unlikely to catch the ball (they may have fallen behind), some of the non-picked players are in a better position to chase the ball (the opponent is heading towards the goal through them). The chase system dynamically drops out and tags in players from a chase.

Player system

The players are all AI controlled with no human intervention. They have a controller, a nested behavior tree and a service that subscribes to the subsystems and sets keys in the behavior tree. I found state machines to be an extra overhead in this case since they are a bit harder to manage and overkill for this application. The players use EQS to query the environment for:

  • Kicking locations

i.e. Where to kick ball from so it has a high chance of avoiding the goalie or other players

  • Intercepting kicks (WIP)
  • Wandering locations, keeping in mind that if a chase is going on then they should stick closer to the chase than not
  • Chasing the ball