Let’s talk about Artificial Intelligence (AI), the soul and heart of complex video games — Mokens League

Mokens League
5 min readAug 5, 2022

Artificial intelligence (AI) is one of the most complex topics on computing, and it is not an exception on Game Development. AI could be as simple as a bunch of conditions and results, but it has no upper limit. One of the tasks for the people that work on any kind of AI is trying to keep it as simple as possible without compromising the result. There are a lot of techniques, patterns, and standard practices that aim in that direction, but custom problems require custom solutions.

The problems we faced at the beginning were the movement of the characters and their formations in the game field. A realistic but game-suitable movement is an extended topic for AI, ranging from pathfinding to procedural animations. The requirements are simple, but it needs to work perfectly for it to perform well on every situation. The formations, on the other side, are pretty specific. Sure, there will be papers about AI entities moving together and collaborating, but our needs, as a non-realistic soccer game, that must be simple to play and hard to master, differ from all of them, making us develop a new custom solution.

Movement in AI has many topics, like collision avoidance and local or global knowledge. In our case the movement will be based on physics, allowing us to use a few of its properties to make the characters look really smart. To make it work, characters need to have a Mass. The bigger the mass, the more force you need to move it. Might seem a little pointless, but the actual implementation makes it necessary. That way the characters don’t change directions instantly (being more difficult the heavier they are) and can mix several different forces to move in directions that otherwise would be very difficult to obtain. A clear example would be a character in the goal area, waiting for a corner pass. The character should be near the center of the area, but at the same time far from the goalkeeper and other characters to be able to receive the ball correctly. Doing it “the easy way” proves being all but easy. You can check every direction and select the one with least characters, but then you might be too far from the goal area. There are many considerations and this can get pretty complex in little time. But if we apply a force to get near the center of the area and forces to go in the opposite direction of other characters, you naturally get a mix of the forces that avoid characters without getting too far, making it seem intelligent. With this premise, we can do a lot of movements that look natural and do exactly what the player wants to. Our movement system has a lot more to it, but it’s mostly physics stuff and out of the scope for this post.

On the other hand, the formations have a lot of design considerations, making it a shared work between AI and Game Design. They are not as complex as our own physics system for the movement, but the formations system has pretty specific needs that must first be defined (the Game Design part) and then implemented (the AI part). Our first specification was that the formation needed a leader, someone to follow and be the character who defines the formation. That Moken should be the controlled character, for the formation to follow exactly what the player wants. Mokens on an attack formation should go forward, to the opponent's goal, as it is the main objective of the game, so whenever the player goes forward, all the formation does. Going backward is different though. Players don’t want all the characters to go back when the controlled Moken goes back. The player wants the characters near the opponent's goal to make the team play! Taking that into consideration, the formation should only go backwards if the controlled characters exit the formation from the back side. The defending formation is the reverse. When going backward, the formation will move backward. But going forwards will only move the formation forward when the leader exits the formation from the front side.

Besides those two base cases, there are other situations where the leader moves between the point from where the formation moves forward and the point moves backward. For simplicity, we define the position of the Mokens in a formation using a 3x3 grid.

If the leader doesn’t leave its square, nothing will happen. If the leader moves to a square where another Moken is, the other Moken will move to the original leader position (but maintaining the same leader!). Lastly, if the leader leaves its column to a column with at least another Moken, one Moken of the said column will go to the leader’s original position.

Might seem a little bit complex, but in fact, this is just the translation from the design to the requirements. Once we put it in a language, the computer understands that the Mokens will do what we want. This is a clear case of AI with a few conditions and their effects. Simple, and works like a charm!

Of course, those are a few conditions that result in simple behavior. When we get deeper into the game strategy those conditions may change completely.

For now, we can create new formations, define which formations are for attack, which ones are for defense and we can assign those formations to the Mokens. In future sprints, players will be able to select up to 4 formations to defense and 4 to attack and change between them in runtime, further increasing the player agency on the characters’ AI and allowing the players to create new and powerful strategies to win the games.

Although we only wrote about two use cases for AI in our game, even at this stage, we have a lot of detail on the character’s behavior for them to seem intelligent, like going towards the point the ball is going, assisting a character that is trying to make a corner pass or the full AI of the goalkeeper, which is done separately of the other characters. And even then, there is much more detail we need to put on our AI to make the player feel that the characters do exactly what they want.

And as I said before, if that AI is good and simple, it will be twice as good.

Written by Marc Palenzuela — Unity Developer at Mokens League.

About Mokens League

Win-To-Earn! Real-time multiplayer eSports using blockchain technology and NFTs to play competitively and win our tokens.

Find out more about Mokens League at:

🌐 Website: https://www.mokensleague.com/

📢 Community Discord: https://discord.gg/KPkkrkeqxF

🐦 Twitter: https://twitter.com/MokensLeague

📰 Medium: https://mokensleague.medium.com/

📷 Instagram: https://www.instagram.com/mokensleague/

🎥 YouTube: https://www.youtube.com/channel/UCF65LuFp7tBmauP-HMYcGBQ



Mokens League

Real-time multiplayer Free-to-play video games using collectible Mokens ⚽ 🎮 🏆 Join our Beta!