ARTHIS

How the AI in these games actually works, and how to beat it

Four genuinely different approaches to computer opponents, the numbers behind each one, and the specific weakness every approach hands you.

By Aayush Kumar · Game AI · 10 min read

"The AI" covers at least four unrelated things across the games here, and treating them as one category will lose you matches. One cannot see your reply at all. One searches six moves deep and steps around a trap you are three turns from setting. One plays the position out twenty-four thousand times before answering. One is not deciding anything — it is being handed deliberate errors. Each leaves a specific weakness open.

Greedy scoring: one pass, no lookahead

The simplest useful opponent scores every legal move, sorts the list and plays from the top, never asking what you would do in reply. Chess works exactly this way, and the scoring numbers are the game:

let score = Math.random() * 10;
const captured = board[m.row][m.col];
if (captured) score += VALUE[captured] * 10;   // pawn = 100, queen = 900
if (givesCheck(m)) score += 80;                 // flat, regardless of value
if (landsOnDefendedSquare(m)) score -= VALUE[m.piece] / 3;
if (m.piece is pawn && reachesLastRank) score += 850;
score += centreBonus(m.row, m.col) * 6;

Look at lines three and five together. A capture is worth ten times what it takes; stepping onto a square you defend costs only a third of the moved piece's value. Those numbers do not balance. A hanging pawn is worth 1,000 to it; moving its queen onto a defended square costs 300. It takes the pawn with the queen.

The exploit: leave a pawn hanging that two of your pieces guard. It works most cleanly around move eight or ten, once two defenders aim at the same square. The second exploit is line four — check is worth a flat 80 whether or not it achieves anything, so it shoves a queen forward to give a pointless one. Do not chase the queen; block or capture with something you wanted to develop anyway, and take the free tempo.

Endgames are where it collapses: the centre bonus drags its king toward the middle while you push a pawn past it, and it loses races it cannot count. It also picks at random from everything within 30 points of its best move, so no line can be memorised against it.

Ludo's computer players are the same family: fixed priorities — home, capture, leaving the yard, the home lane, landing safe — with a small random weight so the three do not play alike. The capture score drowns out the danger score, so they take greedy captures that cost them the game. Park a token seven or more steps ahead of the nearest enemy and you are invisible; five ahead and everything in range comes for it.

Minimax with alpha-beta: actually searching

Four in Line is the real thing. It builds a tree of possible futures — my move, your best reply, my best answer to that — and scores the leaves, with alpha-beta pruning throwing away branches that cannot affect the result. The three settings change nothing but the depth: two ply on Easy, four on Normal, six on Hard.

Ply means half-moves. Two ply is "my move and your reply", enough to block an immediate win and nothing else; six ply is three full moves each, enough to see the trap you are three moves from setting. The evaluation function at the leaves is lopsided on purpose: a four-cell window holding three of its discs and one gap scores 50, the same window holding three of yours scores minus 80. Defence outweighs offence by a clear margin.

The exploit: that imbalance is tempo you can spend. Point a three at it somewhere harmless and it abandons its own developing line to kill the threat; use the free move to build the real fork elsewhere. A six-ply search never falls for a single line, so you need two threats one drop creates at once, and the decoy buys the move to build them. On Easy this is overkill — two ply walks into almost anything.

The search tries columns centre-first because that prunes faster, with the side effect that it opens like a textbook and looks stronger than it is for four moves. Tic Tac Push spans a similar range, up to a ten-move search, and its deep setting is genuinely hard: the rule that lining up three of your opponent's marks hands them the win is easy to blunder into, and a search does not blunder.

Monte Carlo: playing it out and counting

Bigger Tic Tac Toe uses a third approach. Rather than evaluating positions with a hand-written function, it plays the game out to the finish thousands of times with semi-random moves and keeps whichever first move won most often. No judgement about what a good position looks like is involved anywhere.

Normal gets 1,800 playouts, about a third of a second. Hard gets 24,000, a full second — which is why it answers visibly slower and almost never hands you a free board by accident. Easy is a one-move scorer with random noise that checks only whether its move immediately lets you finish a small board.

The exploit against Hard is thin, honestly — there is no evaluation bias to lever, because there is no evaluation function. It does have a horizon problem on slow plans, so draw a small board deliberately: a dead board permanently removes a square from the big grid. Against Easy, build two threats in one small board while feeding it into boards where it has nothing. Looking one move ahead, it will send you straight back to the board you are already winning.

Error models: the AI that is not trying to think

In a physics game a stronger opponent means a more accurate one, not a cleverer one. Carrom Clash models its three levels as error rather than strategy:

SettingAim errorPower errorOutright missPicks fromGoes for queen
Easyabout 2°16%22% of shotsbest 4 optionsno
Normalabout 0.7°7%6%best 2yes
Hardabout 0.25°3%neverbest 1yes

All three rank the same candidate shots the same way. Easy is Hard with a shaky hand that also refuses to chase the queen, which makes the queen free money down there — take it early with a cover lined up, and the 22 per cent whiff rate usually buys a second attempt. Against Hard the error model gives you nothing and you win on shot selection, building chains, since potting your own coin earns another shot.

Table Tennis adds a twist. As you strike it rolls how well it will read that ball, and wide, hard shots get misread far more often than flat ones down the middle — but every further stroke sharpens it, by up to 40 per cent ten shots deep. End points early: your best chance is shot three, not twelve.

Math Duel is the purest version of this design: the CPU does not react to you at all. When a question appears it draws one answer time from a range — four to six and a half seconds on Easy, just over one to two on Hard — commits to it, and separately rolls whether it will answer wrongly. You are racing a stopwatch. On Easy it misses about a third, so accuracy alone wins, and the minus-one penalty for a wrong tap means waiting beats guessing.

Dodgeball gives its opponents a dodge budget rather than reactions: one sidestep per throw, only when the ball is close, at a probability the difficulty sets — one attempt in six on Easy against nearly three in four on Hard. Spent or declined, that throw then connects. So throw twice in quick succession at one target.

Rubber-banding, stated openly

Several games adjust the opposition based on how you are doing — the design decision players most often suspect and least often have confirmed.

Bike Rush 3D does it in both directions. The rival's target speed is multiplied up when it is behind you and down when it is ahead, then clamped just short of the ceiling your own throttle reaches, so it can neither win a drag race nor vanish up the road. On Hard it may boost for a couple of seconds when it spots a clear lane sixty metres ahead: it beats you by reading traffic, not by being quicker. Every metre it gains is therefore a lane-choice mistake of yours, and crashing is the only thing that genuinely loses this race — a crash drops you to nine metres per second and locks the gas out for nearly two seconds.

Bumper Kart Arena hands human players an aim assist inside a narrow cone ahead of the kart that the bots never get. Line shots up along your direction of travel rather than swinging to face a target.

The opponent that learns your habits

One game builds a model of you. Hand Cricket on Normal counts how often you have played each number from one to six and bowls your favourite back at you. On Hard it also keeps a transition table — which number you tend to play after each other number — used once it has seen the same pairing twice. Both models pool the whole match, so habits you show while bowling are used against you when you bat.

The exploit is poisoning. The counts are cumulative and never forgotten, so lean hard on one number through the first innings and then abandon it; the model keeps pointing at a number you no longer play. The transition table only fires on a repeated pairing, so never follow the same number with the same number twice.

Against Easy, which picks at random, the correct play is to show six every ball: the chance of being out is one in six whatever you show, so take the most runs for the same risk. Step up a level and that becomes the worst habit you could have — which is the general point in miniature. There is no one way to play "the computer", because the computer is four different things.

If you want the rule decisions underneath these boards rather than the opponents on top of them, the house-rule arguments are here.

More from ARTHIS.space

Browse all 105 games