Reverse Engineering FIFA!

Siddhant Sukhatankar
4 min readFeb 20, 2021

Hello everybody! Nice to have you with us. Martin Tyler is my name, Allen Smith is his name alongside me. Looking forward to describing the action. It’s a delightful day, isn’t it? Yeah. This is a high-class game. Here we go!

FIFA from a developer’s lenses/ How to code FIFA
Here we go…..

I am a massive football fan, and that means that I love playing FIFA too. Through the years I have seen that the detailing of the game has been revamped to a whole new different level. The thing that remains the same is the gameplay. I have always pondered how this works and this blog is about knowing how FIFA gameplay would have been programmed. I do not claim that FIFA uses the approach which I have mentioned, but this is just seeing the game through the developer’s lenses. So let us begin.

Scratching the field

Imagine that a football pitch is placed on graph paper, for a better understanding of the distances.

So we can specify ground co-ordinates as xϵ[-15, 15] and yϵ[-10, 10]. In the same way, we can specify the coordinates of the goal too.

Coding FIFA
ground-graph overlay

The function mentioned below is about finding minimum distance between 2 points on this graph. We are going to need it extensively.

def distance(A, B):
return |A-B|

Controls of gameplay

As a programmer, the first thing that comes to my mind is that there is a class called ‘Player’ with few final variables like name, nationality, position, age, face, and other visual features. There are attack and defense functions.

Coding FIFA controls
Game Controls

For anyone who has played this game, might have observed that a single button does 2 different tasks- e.g., button A does shooting and tackling. This means that the game has two distinct control modes- attack and defense.

Whether an attacking action or a defending action is performed, solely depends on whether you have possession of the ball. We can think of possession as a boolean variable.

if distance(player, ball) == 0:
possession = True
else:
possession = False
if possession == True:
mode = 'Attack'
else:
mode = 'Defense'

The above checking needs to be done in real-time throughout the game for million times. There might have been instances, where we’ve wanted the defending set of control options but have instead gotten the attacking set of controls and vice versa. This is because the above checking system is late than the actual position of the ball nonetheless, it’s best.

Attack

In the attacking mode, the control switches to the player who possesses the ball. After every pass, the control switches to the player who receives the pass. The duration of the pressed button determines the power with which you want to kick the ball.

Defense

while(True):
team_A_Distance = create dict of key=player and value=distance(player, ball)

sortDictByValue(team_A_Distance)

control_index = 0
control = team_A_Distance[control_index]
if switchButtonPressed:
control_index += 1
control = team_A_Distance[control_index]

Goal and Away

Based on the coordinate system, if the coordinates of the ball are in the specified co-ordinate range of the goal, we can say that it is a goal. Similarly, if the ball crosses the coordinates of the field, we can say it as an away.

Corners and Free-kicks

These situations can be called exceptions. If you might have observed, after the ball is kicked, the outcome is pre-decided. Even if a button is not clicked, the action is taken care of. We need to give better thought to these cases.

How many lines of code is FIFA?

GOOOOOOOOOOOOOALLLLLLLLLLLLLLLLLLL! GOAL GOAL GOAL GOAL GOALLLLLLLLLLL! Well, with that goal Alan, it should wrap it up for Barcelona. I would have thought so, surely no way back now!

I found this interesting blog of AI generating FIFA commentary- https://towardsdatascience.com/ai-generating-football-video-game-commentary-271f56f45bf

--

--