← Back to Here To Slay

Here To Slay, part 12: threat, styles and difficulty

The second half of Here To Slay's bots: when to challenge, how the bots team up against the leader, the three styles and the difference between the normal and advanced levels.

#tecnico

In part 11 I showed the foundation of the bots: how they receive the match, act like a player and score every move on their own turn. What was missing was making the bot look at the other players. This post covers that second half: reactions outside the turn, the threat weight, the styles and the difficulty levels.

With everything in place, the bot/ package ended up like this:

Classes in the bot package: the Match publishes its state to the BotDriver, which asks the BotBrain for a move; the BotBrain builds Threats and CardValues on every decision and delegates to the planners, which return a BotMove

To challenge or not

Outside its own turn, the ReactionPlanner is in charge. It handles challenge windows, modifier windows and the bot’s own rolls.

When someone plays a card and the bot has a Challenge in hand, it works out how much it loses if that card comes into play. A hero that gives the opponent a new class weighs more. A hero that would give them their sixth class is worth the whole match. And that harm is multiplied by the threat weight of the card’s owner, which I explain below. The rule is:

if (harm >= CardValues.WIN / 2) return true;   // a game-deciding card: always challenge
double pWin = Odds.challengerWins(myBonus, ownerBonus);
double cost = challenges >= 2 ? 3.5 : 5;       // spending a Challenge costs less when holding two
return pWin * harm > cost;

In other words, the bot challenges when the harm avoided, weighted by the chance of winning the challenge, is worth more than the card it will spend.

Modifiers follow the same idea, trying every possibility. For each modifier card in hand, each of its possible values and each roll in progress, the bot works out how the result would change and how much that is worth to it, minus the value of the card spent. It plays the modifier with the biggest gain. That includes playing a −4 on another player’s roll to make it fail.

The threat weight

The MP-Mix idea became the Threats class. At every decision, the bot gives each opponent a threat score:

double t = 100 * Math.max(monsters, classes) + 25 * Math.min(monsters, classes)
        + 2.5 * heroes + cardsInHand;
if (imminent(id)) t += 45;

monsters and classes are the progress on each path to victory, from 0 to 1. The path that’s further ahead weighs much more, because that’s the one the player will win by. imminent says whether the player is one good move from winning: one class or one monster away.

That score gives a weight, which multiplies any damage the bot can do to that player. Normally, the weight follows the relative threat: hitting whoever is ahead is worth more. But if someone’s win is imminent, their weight goes up to 2.0 (or 2.6 for advanced) and everyone else’s drops. Since all the bots read the same table and do the same math, they team up against the leader without any coordination between them.

The styles

The three styles are an enum in BotBrain: SLAYER, who hunts monsters, COLLECTOR, who collects classes, and RAIDER, who raids the others. Each bot draws one at the start of the match.

As the papers from part 10 suggested, a style has no rules of its own. It only multiplies by 1.3 the value of what that personality prefers:

double factor = switch (style) {
    case SLAYER -> tag.equals("monster") ? 1.3 : 1.0;
    case COLLECTOR -> tag.equals("class") ? 1.3 : 1.0;
    case RAIDER -> RAIDS.contains(tag) ? 1.3 : 1.0;
};

RAIDS is the list of heroes whose effects get in other parties’ way. When two moves have similar scores, the style breaks the tie. When one move is clearly better, they all do the same thing.

With style and noise, a turn decision goes through these steps:

How the TurnPlanner picks an action: it lists the legal options, values each one, divides by its action point cost, applies the style and the level’s noise and sends the highest

Normal and advanced

The difficulty levels live in the BotLevel enum, and almost everything in them came from the part of the research about seeming human:

NORMAL(0.30, 0.25, 900, 2300),
ADVANCED(0.06, 0.0, 700, 1700);
// noise, chance of letting something slip, min and max wait (ms)
  • noise: every score goes through noisy(), which multiplies it by a random factor. For normal, the variation reaches 30%, so sometimes an average move looks like the best one. For advanced, it stays at 6%;
  • letting things slip: 25% of the time, normal ignores a worthwhile challenge or modifier. On top of that, it only challenges when the gain is well above the cost, and doesn’t bother with modifiers that change little. In part 10 I wrote that the most convincing mistake is the opportunity that goes unnoticed, and that’s the mistake I gave it;
  • pace: no bot answers instantly. The wait is drawn from the level’s range and multiplied by the kind of action: confirming something is quick (×0.5), reacting to a window is normal (×1.0) and planning the turn takes longer (×1.4).

Advanced also does things normal doesn’t:

  • it counts the Challenges that haven’t shown up yet to estimate the risk of its card being challenged;
  • it builds combos, like playing a hero to unlock a monster and attacking in the same turn;
  • it switches styles during the match, going for whichever path is closest to a win, or turning raider when someone is about to win.

Normal keeps the style it drew and only attacks with reasonable odds.

What’s still missing

  • tuning: the numbers in these posts were picked by eye. The next step is putting bots against bots, many matches in a row, to see if advanced really wins more and whether any card’s value is way off;
  • playing against them: sitting down to play and seeing if they are, as I wanted in part 10, fun to play against.