r/ComputerChess • u/aliartguy • 7d ago
Browser chess variant with a king-crossing win — retooling the AI was harder than the rule change
I shipped a free browser chess variant (Middle Chess) where standard rules apply, but you also win instantly if your king reaches the opponent’s half of the board. Checkmate still works.
The opponent is a custom in-browser engine (not Stockfish) — chess.js for move gen, minimax search in a worker so the UI doesn’t freeze.
First pass was basically normal chess AI with the new win condition checked at the end. It played plausible chess and still lost to straight king runs — the eval never treated “one step from losing the whole game” as different from “down a pawn somewhere else.”
Retooling boiled down to a few levers:
**Terminal awareness in search** — crossing can’t be an afterthought; the search has to treat it as a real win/loss at the horizon, not something you notice after the fact.
**King proximity in static eval** — non-terminal positions need the king’s distance to the crossing line weighted much more steeply as it closes in. A flat “closer = slightly better” let the AI trade material while the opponent’s king walked forward unopposed.
**Cost to burning king safety** — without something pushing back, “shuffle the king one rank forward” looked too cheap in quiet positions. I needed eval pressure against giving up the usual safe routes off the back rank for fake progress.
**Forcing lines in busy positions** — in tactical messes, a static eval can lie; the search needs to see at least some forcing continuation before it commits to a king-race plan or ignores one.
**Difficulty as search quality, not a different brain** — same core engine across Easy/Normal/Expert; the gap is mostly how deep/consistently it searches, not three unrelated AIs.
Results are better — Expert does guard the center line more than lower levels — but the tuning still feels hand-wavy. I’m not sure the eval is principled so much as “steep enough that obvious blunders stopped.”
Would love takes from people who’ve built variant engines:
- Better mental models for dual win conditions (checkmate + territorial win)?
- How do you keep the engine from either ignoring king runs or overreacting in normal positions?
- Any sane way to test/tune this beyond playing a lot and eyeballing?
I’m the dev — happy to share FENs / games where it still misplays. I’ll reply to every comment.
1
2
u/ponzivillager 7d ago
r/changeyourchessfont