Log inGet started
← Explore
World media

Next Move: Computer Opponents for Turn-Based Tactics

Drop-in enemy AI for turn-based grid and tactics games: 7 personalities x 3 difficulties that really play differently, move+attack planning, cover, flanks, objectives, deterministic pure Luau.

0score
Embed

Embed this world

Paste this code into your own page and the world plays right there.

Updated Nov 13, 2026
aienemy-aicomputer-opponentturn-basedtacticsstrategygridxcom-likebotpure-luaunext-moveturnAiKitlibrary

Next Move (package turnAiKit) is a drop-in AI opponent for turn-based grid and tactics games: XCOM-likes, squad skirmishes, board wargames, square or hex grids. It decides, one step at a time, what each of the computer side's units should do: where to move, whom to shoot, when to heal, when to throw the grenade, when to stay in cover and when to end the turn. Every choice comes with readable reasons ("move then shoot", "cover 2.0 (+5.0)", "shoot b3 75% kill 50%").

Open this world to watch two Next Move sides fight on the demo board, with buttons to switch each side's personality and difficulty and a live log of why each unit did what it did.

What you get

  • A planner that thinks like a tactics player. It plans a unit's move together with the action it would take from the new cell, so it moves to where the shot is good. It weighs cover, the damage enemies could deal next turn, kill chances, flanks, firing positions, objectives and the ally it guards.
  • 7 personalities x 3 difficulties. Every personality plays measurably differently from the others at easy, normal and hard. The package's own tests measure it every run:
PersonalityPlays like
balancedAdvances into firing positions behind cover and trades shots. The reference.
aggressiveCloses in fast and attacks the most, but still takes cover and avoids melee reach (not suicidal).
defensiveHolds strong cover and shoots from safety.
objectiveTakes and holds the objective zone.
skirmisherKeeps to its weapon's range and backs away from melee.
flankerWorks around cover for shots on exposed targets.
bodyguardSticks to the medic (or leader), stands between it and threats, shoots what can reach it.
DifficultyHow it plays
easyPicks among its personality's own top plans, half-ignores next-turn threat and undervalues kills, so it plays worse while still playing in character.
normalNear-best play with a touch of noise.
hardBest play: focuses fire on wounded and killable targets and fully respects threat.

Mix roles inside one side with perUnit (a bodyguard next to two flankers), or define your own personality as a plain weights table.

  • Deterministic and engine-free. Pure Luau: the same state and seed give the same action on every peer, in tests and on a server.
  • A reference skirmish sim (turnAiKit.sim) with a complete adapter, self-play (Sim.playGame) and Sim.profile, which measures how any configuration plays (distance kept, cover share, attacks per turn, flank shots...).
  • A guide: "How to make a computer opponent for a turn-based tactics game".

The adapter idea

The brain never touches your game. You hand it an adapter: a few functions that answer questions about your game (who can act, where they can go, what they could do from a cell, how much cover a cell has). Then you run a loop on the AI side's turn:

local Brain = require("turnAiKit.brain")

local adapter = {
    units    = function(side) return Game.unitsThatCanAct(side) end,
    enemies  = function(side) return Game.enemiesOf(side) end,
    allies   = function(side) return Game.unitsOf(side) end,
    moves    = function(unit) return Game.reachableCells(unit.id) end,      -- { { cell = {q,r}, cost = n } }
    options  = function(unit, fromCell) return Game.attacksFrom(unit.id, fromCell) end,
    cover    = function(cell, fromCell) return Game.coverAgainst(cell, fromCell) end, -- 0 / 1 / 2
    distance = function(a, b) return Game.gridDistance(a, b) end,
}

Game.refreshAp("aliens")
while true do
    local action = Brain.nextAction(adapter, "aliens", { personality = "flanker", difficulty = "hard", seed = matchSeed })
    if action.kind == "end" then break end
    Game.apply(action)            -- a move, or the option you returned, spending AP
end

Install

Search ZeroMind for "Next Move" or "turnAiKit" and install the turnAiKit package, then:

local Brain = require("turnAiKit.brain")
local Sim = require("turnAiKit.sim")   -- optional: reference sim and adapter

Upgrading from turnBrain 1.0.0: the package was renamed in 1.0.1. Change require("turnBrain.brain") / require("turnBrain.sim") to turnAiKit.brain / turnAiKit.sim; the API is otherwise the same.

Versions

  • 1.0.1: renamed to Next Move (turnAiKit). Personalities retuned so each one plays measurably differently at every difficulty (new firing-position pressure weight, aggressive keeps cover, easy picks among its own top plans). Added Sim.profile and behaviour tests.
  • 1.0.0: first release as turnBrain.

Comments · 0

Open discussion, no rating attached. Ask questions, swap notes, follow threads.

Sign in to join the discussion.

Documented parts · 3