ai newsMi., 25. Nov.
EilmeldungOpenAI's Pretraining Loss Is Falling 7x Faster — and the Benchmarks Haven't Noticed Yet

Browser-Schach-Engines: Evaluierungsfunktion und Opening Book stecken im JavaScript

Schach- und Brettspiel-Plattformen im Browser preisen oft eine starke eingebaute Engine an. Züge kommen sofort und ohne Server-Roundtrip, auch offline nutzbar. Dahinter stecken meist Evaluierungsfunktion, Suchheuristiken und ein komprimiertes Opening Book direkt im JavaScript-Bundle.

dev.toMittwoch 02:09 · 25.11.DE2 Min. Lesezeit
Bild: dev.to

Wer Monate damit verbracht hat, Piece-Square-Tabellen, Mobilitätsgewichte oder ein Buch vorbereiteter Varianten zu tunen, der muss damit rechnen, dass jeder Besucher, darunter auch eine konkurrierende Website, diese Daten mitnehmen kann.

Öffnet man die DevTools bei einer typischen Browser-Engine, findet man dort mehr als nur eine UI:

All das muss kein neuronales Netz sein, um einen Diebstahl wert zu sein. Eine sorgfältig getunte Evaluation von wenigen Kilobyte genügt, um ein kostenloses Widget als hochwertig erscheinen zu lassen.

Angreifer implementieren Alpha-Beta nicht selbst neu. Sie formatieren den Bundle hübsch und suchen nach Arrays mit 64 Zahlen, Centipawn-Konstanten oder Zeichenketten mit bekannten Eröffnungsnamen.

Hier ist die Art von Funktion, die nahezu unverändert kopiert wird:

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; } Enter fullscreen mode Exit fullscreen mode Sobald evaluate und BOOK im Repository eines Konkurrenten liegen, ist Ihre "einzigartige" Engine nur noch ein Skin davon entfernt, die seine zu sein.

Die Kalibrierung des Schwierigkeitsgrads ist meist nur ein dünner Wrapper um dieselbe Funktion, sodass selbst der Casual-Modus Informationen preisgibt.

Der Offline-Modus und die "Sofortanalyse" brauchen weiterhin eine lokale Funktion. Für diesen Codeabschnitt gilt:

Wenn ein "Sieg" dadurch zustande kommt, dass die lokale Engine aufgibt, kann jeder evaluate abfangen und eine Aufgabe erzwingen. Offizielle Wertungen müssen von einem Server stammen, der die Partie ausgeführt oder zumindest verifiziert hat.

Eine Schach-KI im Browser liefert das aus, was sie stark macht: die Evaluation, die Suchstrategie und oft auch das Buch. Lassen Sie offizielle Partien auf dem Server laufen, schützen Sie die Offline-Engine, die Sie ausliefern müssen, und hören Sie auf vorzutäuschen, dass eine versteckte evaluate-Funktion ein Wettbewerbsvorteil ist.

Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.

Original (Englisch) anzeigen

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.

Open DevTools on a typical in-browser engine and you will find more than a UI:

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.

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; } Enter fullscreen mode Exit fullscreen mode 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.

Offline mode and "instant analysis" still need a local function. For that chunk:

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.

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.

Originaltitel: A browser chess or board-game AI still ships its evaluation function and opening bookQuelle: dev.to (dev.to). Original öffnen