The AI of the Deal with the Devil

In The Killing Stone, the “deal with the devil” was critical to the entire concept of the game. Here’s how the code delivered on the narrative promise.

One part of The Killing Stone that I’m especially proud of is the demon’s AI in bargaining. Despite the mechanic being fairly simple, it needed to do a lot of heavy lifting for the core premise of the game, feeling like you’re facing off in a battle of wits against ancient and powerful demon lords.

Screenshot from The Killing Stone, playing a bargaining round by placing chits on placards, against a one-eyed devil in a mask.

At its core, the algorithm looks at how good or bad an outcome would be, considers its options against each of those outcomes, and picks the best one. My fellow code nerds may recognize this as a fairly simple Utility AI.

But no self-respecting devil would ever play it that straight. It would have its own petty priorities. It would try to play mind games with you. So, like a lot of human players, it uses the first round partly to pursue the outcomes it actually wants, but also to feel out the player and misdirect.

Screenshot from The Killing Stone, bargaining against a three-headed horse demon, who is definitely not trying to psych you out.

Before the AI was implemented, we could play bargains against random enemy plays. It was a very temporary implementation, but even that random version provided useful data!

Humans are so good at seeing patterns, we often see them where there are none. So it wasn’t surprising that when the game randomly selected exactly the same bids as the human, humans called it out. What was really useful though, was hearing how often my colleagues called this “cheating.”

The AI doesn’t cheat at all. It chooses its moves before you’ve even played, so it can’t possibly take your future movements into account. But it DOES try to guess!

So I was walking a fine line between making the AI appear intelligent and aware of the player’s intelligence, but I also had to avoid situations where it looked like the demon was acting on information it doesn’t really have.

Add to that, if the player is able to maneuver the AI into a state where it behaves predictably, it no longer feels like a high-stakes battle of wits against an intimidating foe.

But adding true randomness was dangerous because if the demon ever plays a move that doesn’t make sense, it will again break the magic. So instead, if the demon’s and player’s moves are ever too aligned, it will abruptly change its strategy.

Screenshot from The Killing Stone, bargaining against a golden monstrosity of a demon, calling out how symmetrically the player has played against the demon.

When playtest feedback started to say things like “personality” and “mind game” and how good it feels to “trick” or “outmaneuver” the demon, I knew we really had something.

Screenshots from redacted Discord users talking about how it feels to play bargain rounds in The Killing Stone.

No one has yet noticed that the different demon lords have different priorities in bargaining (at least not that I’ve heard), but I’m sure they will.

Screenshot from bargaining in The Killing Stone, with the final results being enacted, and Weregild commenting on it in terms of commerce.

The Killing Stone is out now in Early Access, sitting at 96% Very Positive on Steam! If that sounds like your thing, check it out, and good luck in all your machinations against the devil!

Tags: