Browser chess, go, and other board-game sites often advertise a "strong built-in engine". The move arrives instantly, there is no server round-trip, and it works on a plane. That usually means the evaluation function, search heuristics, and a compressed opening book are sitting in the JavaScript bundle you just downloaded.
If you spent months tuning piece-square tables, mobility weights, or a book of prepared lines, every visitor — including a competing site — can take them.
What actually ships
Open DevTools on a typical in-browser engine and you will find more than a UI:
- Evaluation terms — material values, piece-square tables, king-safety weights, pawn-structure bonuses, and the taper between midgame and endgame.
- Search control — iterative deepening limits, null-move reductions, late-move reduction tables, and the quiescence rules that stop the search from blowing up.
- Opening book — a map of fen or hash keys to preferred moves, sometimes with weights you collected from your own games or licensed data.
- Time management — how much of the clock the engine spends on the first move of a new line.
- Difficulty knobs — Elo-calibration curves that "weaken" the engine for casual players, which are themselves valuable product work.
None of this needs to be a neural net to be worth stealing. A carefully tuned evaluation of a few kilobytes is enough to make a free widget feel premium.
How it gets lifted
Attackers do not re-implement alpha-beta. They pretty-print the bundle and look for arrays of 64 numbers, centipawn constants, or strings from well-known opening names.
Here is the kind of function that is copied almost unchanged:
const PST_MG = { p: [/* 64 midgame pawn scores */], n: [/* ... */] };
const BOOK = { "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3": ["c7c5", "e7e5"] };
export function evaluate(pos) {
let score = 0;
for (const p of pos.pieces) {
const pst = pos.phase > 0.5 ? PST_MG[p.type] : PST_EG[p.type];
score += (p.color === "w" ? 1 : -1) * (MATERIAL[p.type] + pst[p.sq]);
}
return score + mobility(pos) * 6 + kingSafety(pos) * 12;
}
Once evaluate and BOOK are in a competitor's repo, your "unique" engine is a skin away from being theirs. Difficulty calibration is usually a thin wrapper around the same function, so even your casual mode leaks.
What actually protects you
Move what you can off the client
- Rated games, leaderboards, and "play the official engine" should be adjudicated by a server-side engine. The client can animate a move the server already chose.
- Opening books you licensed or collected belong on the server. Ship only a tiny starter book if you need instant first-move feel, and fetch the rest after a signed request.
- Puzzle ratings and "coach" explanations can be generated server-side; the client only renders them.
Protect the interactive engine that must stay local
Offline mode and "instant analysis" still need a local function. For that chunk:
- Bundle the engine separately from the React UI.
- Apply stronger-than-mangling protection (control-flow flattening or VM-based compilation) to evaluation, search control, and the book decoder.
- Keep the hottest bitboard loops lighter if you measure a frame-time regression; protect the decision logic first.
- Leave source maps off the public CDN.
- Add a few harmless, distinctive evaluation quirks so a lifted copy is recognizable.
Do not treat the client as a rating authority
If a "win" is granted because the local engine resigned, anyone can hook evaluate and force a resignation. Official ratings must come from a server that ran, or at least verified, the game.
Practical checklist
- [ ] Rated play and official analysis are decided on the server, not only by the in-page engine.
- [ ] Licensed or proprietary opening books are not shipped in full in the public bundle.
- [ ] The evaluation and search-control chunk is split from the UI bundle.
- [ ] That chunk is protected with stronger-than-Terser obfuscation (control-flow or VM).
- [ ] Search performance is measured after protection; hot loops can be left lighter.
- [ ] Source maps for the engine are not on the public CDN.
- [ ] A few distinctive, harmless evaluation markers exist so you can recognize a copy.
- [ ] Difficulty sliders cannot be turned into a grandmaster by flipping one flag in DevTools — or if they can, that mode is clearly unofficial.
Honest limits
A determined engine author will eventually recover the shape of your evaluation. Obfuscation raises the cost of a casual lift; it does not make a secret stay secret. If a number cannot be public, do not put it in JavaScript.
Summary
An in-browser chess AI ships the work that makes it strong: the evaluation, the search policy, and often the book. Run official games on the server, protect the offline engine you have to ship, and stop pretending that a hidden evaluate function is a competitive moat.
Disclosure: I work on VEILVM, a JavaScript VM-protection service. Free browser tier (3 runs/day, up to 5 KB) and a Pro plan at $9/month or $79/year with API access. Try the playground at vm.ldvmp.com.
Top comments (0)