skip to content

Why does a game bot trained by behaviour cloning on recorded player matches drift into situations players never reached, and how is that countered?

level: middleimportance: should knowfreq 24%

answer

  1. supervised learning on logs
  2. small errors leave the data
  3. players rarely record recoveries
  4. aggregate the bot's own states
  5. averaging two valid choices

basics

~20 s

Behaviour cloning learns only from states players visited; small bot errors lead to unfamiliar states where predictions worsen, so errors compound. Countered by labelling the bot's own states (DAgger), noisy demonstrations, reinforcement fine-tuning and an authored fallback.

solid answer

~50 s

**Behaviour cloning** is supervised learning from logged observations to player actions. At run time the bot's own small mistakes take it into states the logs barely cover, its predictions there are worse, and the errors **compound**: a distribution shift between the player's states and the bot's. Analyses of cloning show the cost can grow with the square of the horizon in the worst case. Players also rarely record **recoveries**, so the data lacks exactly the situations a drifting bot reaches. Counter it with **DAgger** (run the bot, have an expert label the states it visits, retrain on the aggregate), noise injected while recording, fine-tuning the clone with reinforcement learning, and an authored fallback when the bot is out of distribution. Separately watch for averaging of two valid actions, mixed skill levels in the logs and staleness after balance patches.

go deeper

for a junior

Recall that behaviour cloning is supervised learning from player logs, and that the bot's own mistakes lead it into states the logs do not cover.

for a middle

Explain compounding error from distribution shift, why recoveries are missing from the data, and how DAgger and noisy demonstrations address it.

for a senior

Show how you would measure drift, recovery and fallback rates in a cloned bot, and spot averaging between two valid actions.

for a principal

Weigh imitation for human-like style against reinforcement for strength, and plan retraining around balance patches and an authored fallback.

## Behaviour cloning **Imitation learning** trains a bot from demonstrations instead of a reward. Its simplest form, **behaviour cloning**, is ordinary supervised learning: record what players observed and what they did, then train a model to map observation to action. It appeals to game teams because it needs no reward design, produces human-like style, and can use the match logs a live game already collects. ## Why the bot drifts The training data covers only the states players actually visited. At run time the bot makes small mistakes: a slightly late turn, a slightly wrong aim. Each mistake moves it into a state a little unlike the training data, where its predictions are worse, which produces bigger mistakes. This is **compounding error** from **distribution shift** (often called covariate shift): the states the bot sees come from its own behaviour, not from the player's. Ross and Bagnell's analysis of imitation puts a shape on it. If the cloned policy errs with probability `ε` per step on the states the expert visits, its expected number of mistakes over a horizon of `T` steps can grow on the order of `ε T²` in the worst case, because one early error can derail every later step. Later analysis of training on the learner's own states, described below, brings the bound back to roughly linear in `T`, on the order of `ε T`, under its assumptions. A second, game-specific gap: players rarely record **recoveries**. Good players seldom end up half off the track or pinned in a corner, so the data holds few examples of getting out of trouble, which are exactly the states a drifting bot reaches. ## Countering it 1. **DAgger (dataset aggregation).** Run the bot, record the states it reaches, get an expert action for each, add those labelled states to the dataset and retrain. Repeat. In games the expert can be a human using a relabelling tool, an authored AI, or a search that computes a good action offline. 2. **Noise in demonstrations.** Perturb the recording player's controls slightly, so the data contains small deviations and the corrections that follow. 3. **Fine-tuning with reinforcement learning.** Start from the cloned policy and keep training against a reward; the clone supplies human style and a fast start, the reward teaches recovery. 4. **A guarded fallback.** Detect when the bot is out of distribution (low prediction confidence, states far from the data) and hand control to an authored behaviour until it is back on familiar ground. ## Other ways cloned bots go wrong | Problem | Cause | Common response | |---|---|---| | Steers into an obstacle players passed on both sides | regression averages two valid actions into an invalid one | predict a distribution over discrete or multi-modal actions | | Plays like an average of every skill level | logs mix novices and experts | filter or condition on a skill bracket | | Stale after a balance patch | the game changed, the logs did not | retrain on post-patch data | | Copies player mistakes and exploits | demonstrations are not optimal | filter matches, or fine-tune against a reward | The averaging problem deserves a closer look. If half the players pass a pillar on the left and half on the right, a model trained to minimise squared error on steering learns the mean, which is straight ahead into the pillar. Treating the action as a choice among options, or predicting a mixture of possible actions, keeps both modes. ## Checking a cloned bot - Compare the distribution of states the bot visits with the players' distribution; a widening gap is drift made visible. - Track recovery: how often the bot, once off its line, returns to normal play within a few seconds. - Watch the fallback rate; a bot that hands over to authored logic often is telling you where the data is thin. - Hold out recent matches for evaluation, so a balance change shows up as a drop before players see it. ## When imitation is the right tool Imitation shines when the goal is **human-likeness** rather than strength: practice bots that play like a given skill bracket, stand-ins for disconnected players, or opponents whose style should feel familiar. It is weaker when the bot must outperform the players it copies or survive long sequences where small errors accumulate. A common pipeline is to clone first for style, then reinforce for robustness, with an authored fallback in the shipped build.

  • Who plays the expert in DAgger when the expert is a human player who is no longer around?
    Options include designers labelling sampled states in a relabelling tool, an authored AI that is good enough to label locally, or an offline search that computes a strong action for a saved state given unlimited time. Any of these can supply actions for states the bot reached, which is all DAgger needs.
  • Why does a cloned bot need retraining after a balance patch even if it still plays smoothly?
    Its actions encode the old rules: weapon timings, speeds and costs it learned from pre-patch logs. Smooth play can still be wrong play, such as favouring a weakened option. Hold out post-patch matches for evaluation and retrain on post-patch data once enough exists.

A learner driver who only ever watched an instructor drive perfectly has never seen how to recover from drifting toward the kerb, so the first small slip turns into a bigger one.

  • A bot with low validation error on player logs will play well in the game.
  • More logs of the same skilled players fix compounding error on their own.
  • Cloning needs a carefully designed reward function to work.
  • Averaging players' steering gives a safe middle path around obstacles.
  • Imitation bots naturally learn how to recover from their own mistakes.