The AI initially took an average of around 7ms per tick to process. Though the AI only runs on the server, and our server tick rate is 30hz, this would still have severely limited the amount of games we could run on one machine. As a side note, the amount of time spent on AI didn’t vary much with the amount of AI-controlled players, because the heaviest state was Ball Ownership, and only one bot can hold the ball at any time.
I spent a couple of days on optimizing and brought the AI tick down to below 1ms on average and 3-4ms peak:
Shared AI Cache
Each bot has access to a shared cache that can be queried for information like lists of alive players, players with active status effects (“stunned”, etc.), players’ current stamina, bumper positions, the current ball owner, etc. etc. The cache is updated once per tick and stays valid throughout the tick.
Continue reading