Gambits — Behavioural Decision Patterns For A Game Development AI

Konrad Abe
6 min readMar 15, 2021

--

Starting today, I’m kicking off my new series of articles about game development topics. These will mostly be theoretical and talk about concepts and techniques but will at times also include ideas and solutions, depending on the topic at hands such as different ways to go about pathfinding, grids and perspectives in games.

Our first topic will be Gambits.

What Is A Gambit?

A gambit (from ancient Italian gambetto, meaning “to trip”) is a chess opening in which a player sacrifices material with the aim of achieving a subsequent positional advantage.

Source: Wikipedia

Photo by GR Stocks on Unsplash

Historically, gambits are risky moves in a strategical play. The term is nowadays used in many contexts, including strategical situations outside of games, even in politics.

But why are we talking about gambit today? Thanks to one game in particular, gambits have become a popular term in game development circles as well.

How Are Gambits Used In Game Design?

When Square Enix released Final Fantasy XII for the PlayStation 2 in 2006, reception of one of the design choices created a lot of talk. To enable the player to play with multiple characters in an MMO style open-world RPG with (pausable) real-time combat, the developers added the gambit system. Using said gambits, the player could set several commands and triggers and the game would check those for a match and execute the respective action.

Overview of a magic focused unit’s gambits (Final Fantasy XII)

While part of the player base disliked the subjective loss of direct control, the system enabled players to create their own mini AI with simple and easy to understand building blocks.

Subsequentially, gambit systems have been used and talked about in the context of RPGs and there are some other notable examples of games allowing the player to control the AI of his own heroes.

Alternatives to Gambits

A common alternative to this gambit system and Something around for a lot longer would be decision modelling trees. These allow a more detailed, flexible and expandable control about the AI’s decision processes but at the cost of the player being able to add his own rules with simple tools.

Of course, there are also real AI solutions that implement real learning algorithms and mimic human decision models even more closely but that’s a different topic altogether.

Pro And Con Of Using Gambits

As mentioned above, the main Con or constraint of a system alike the gambits of Final Fantasy XII is its limiting nature. It is hard to implement command chains (do A, then B and then follow up with C) and you also need to limit the number of rules or gambits. On top of that, you need to teach your players how to use that system.

On the Pro side, we have the player interaction, which can create a positive effect of ownership because the player is the creator of his own rulesets and it can turn into an interesting metagame to find the right solution for a special situation or set of constraints and keeps the player engaged into solving new challenges.

For me personally, the fact that it is a very simple style of programming available to people with no experience in the field is another great boon here.

Anatomy Of A Gambit

Decisions need to be made by hand… (Final Fantasy Tactics)

The Target

Any action needs a target. The target can be yourself, an ally, a foe or maybe even the target of one of your allies. Depending on your game design, this could also include differentiations such as mercenaries, neutral bystanders, certain objects or even target areas.

The Condition

In addition to your chosen target, you can add a condition for each gambit. Say, for example, you want to use a healing spell on yourself but only when your own hit points are below 50%. In that case, you would pick target self (or any ally if you want to include your whole team/party)

Examples
Use
: Attack
On: closest enemy

Use: healing spell
On: ally (hp<=50%)

Use: potion
On: self (hp<=25%)

Use: fire spell
On: enemy status=weak to fire

Choosing the right items to use in a gambit (Final Fantasy XII)

Bonus: Trigger Conditions

I’m currently working on my own implementation of a gambit-like system and I’ve added an extra component, trigger conditions.

Basically, this is nothing else than a second unit/character/enemy to check for a condition to activate the gambit. Say for example you want to use a certain skill only when your mana/energy is above a certain level but target it on an enemy. In that case, you would do the following.

Use: expensive spell
On: target hp>=3000
When: self mp=>75%

Or you want to use a defensive ability when the enemy is enraged

Use: defensive stance
On: self
When: enemy status=enraged

Gambits In The Wild

The basic idea of gambits for player-controlled units is easy to implement but in a game using gambits, you can take it a step further and use it to model enemy Ai the same way, maybe with a few options not available to the player, to keep it interesting.

You can also use it in more complex games if you implement logic to handle pathfinding, the cost of certain terrains and other stuff like more complex actions. Go wild and be creative. If it fits your game concept, there are lots of interesting combinations you can achieve with them.

Gambits In My Own Projects

I will soon publish another article on my prototype using gambits. It won’t be a full and playable game but an interactive game demo showing how the decision modelling with gambits works and allowing the “player” to experiment with different combinations in different scenarios.

So stay tuned and be sure to follow me and future articles. The prototype should be ready in a week or two.

Some words about me:

If you want to see more of my work and progress, feel free to follow me and check out my other articles. If you clap feverishly for the articles you like most, it will be easier for me to decide which directions to pursue in following articles so use your ability to cast a vote for future content.

I’m also currently working on other series covering complex React Native Setups using Typescript and scalable apps with Redux, where I’ll go into details about how and why I do stuff the way I do as well as some articles on my experience in building games for web and mobile with React.

Here are some of my recent topics:
- React Quick Start with Typescript, Redux and Router
- Linting/Prettier with Typescript
- Redux + Toolkit with Typescript
- Spread & Rest Syntax in Javascript
- clean and simple Redux, explained
- Game Theory behind Incremental Games
- Custom and flexible UI Frames in React Native

And if you feel really supportive right now, you can always support me on patreon, thus allowing me to continue to write tutorials and offer support in the comments section.

--

--

Konrad Abe
Konrad Abe

Written by Konrad Abe

I’m a Web / App Developer & father 👨‍👩‍👧 doing freelance and part-time agency work since 2003, 💻 building stuff on the side 🕹 and attending conferences 🎟