import type { GameState, Point, RuleVariant, Stone } from "../types.ts"; /** * A game nobody is getting anywhere in is a draw. * * Every game where stones are PLACED is bounded by the board: each move fills * a point for good, so 361 moves is a real ceiling on a 19×19 and the game * cannot outlast it. The games where pieces MOVE have no such bound. Two kings * shuffling between the same squares, or two Halma pieces stepping back and * forth, is a game that never ends and that neither player can be made to * stop — which is the oldest known problem in draughts, and why draughts has * had a rule about it for a century. * * The site's existing length setting cannot help here, and not by accident: * it refuses any board smaller than 81 points on the reasoning that "a small * board resolves on its own before any share of it has been played" — true of * noughts and crosses, false of draughts. Checkers is 8×8, so 64 < 81, and * the one game that most needs a cap is the one where the cap is unreachable. * And where a limit IS allowed it is a share of the board's CELLS, which * measures nothing in a game whose moves do not consume cells. * * So this counts moves rather than cells, and asks each family what progress * means in its own terms rather than inventing one measure for all of them. */ /** * How long nobody getting anywhere ends a game, and how "anywhere" is read, * per family. * * THE MEASURE IS DATA, deliberately. `stalled` used to ask * `variant !== RULE_VARIANTS.checkers` to decide which question to put, which * is the engine switching on a variant's NAME — the one thing AGENTS.md says * it never does — and a name in an `if` only looks harmless while there are * two families. There are three. A row here names its own measure and the * engine reads the row. * * MEASURED, not reasoned about. My first numbers came from imagining how long * a march ought to take, and one of them was low enough to end a real game of * Halma — an existing bot test caught it. What matters is not how long a game * runs but how long it runs WITHOUT anybody getting anywhere, and those are * different by an order of magnitude: * * checkers longest idle run 4 plies, in games of up to 72 * halma longest idle run 18 plies, in games of up to 389 * squareFour longest run of slides 232, in games of up to 240 * chineseCheckers longest idle run 40 plies, in games of up to 233 * * All measured over bot-vs-bot play with this rule lifted, or it would have * been measuring its own threshold. * * The margins are enormous on purpose. A cap that is ten times too generous * costs nothing — the game still ends, a little later. A cap that is slightly * too tight ends somebody's real game as a draw, which is a worse fault than * the endless game this exists to stop. And the weakest bot plays games * fifteen times longer than the strongest, so anything calibrated on good * play is calibrated on the easy case. * * Checkers keeps the draughts number rather than a multiple of its own * measurement: forty moves each is what draughts has said for a century, and * agreeing with the game people already know is worth more here than a * tighter bound nobody expects. */ export declare const PROGRESS_MEASURES: { /** A capture or a man's move: draughts' own definition of irreversible. */ readonly taking: "taking"; /** Getting nearer the camp you are filling than you stood a window ago. */ readonly racing: "racing"; /** Putting a new piece down, in a game that places a few and then slides them. */ readonly placing: "placing"; /** A man laid or a man taken: the two one-way things in a mill game. */ readonly milling: "milling"; }; export type ProgressMeasure = (typeof PROGRESS_MEASURES)[keyof typeof PROGRESS_MEASURES]; /** One game's no-progress rule: how long nobody getting anywhere may go on, and how "anywhere" is read. */ export type NoProgressRule = { plies: number; measure: ProgressMeasure; }; /** A draw a no-progress rule made: which measure fired, at the count the rule allows. */ export type StalledDraw = { measure: ProgressMeasure; plies: number; }; export declare const NO_PROGRESS_RULES: Partial>; /** * The no-progress rule that drew this game — what it measures and the count it * allows — or null where no such rule drew it. * * EVERY STALL NAMES ITS RULE. Chess does not say a game could not be finished; * it says "draw by the fifty-move rule". A stalled draughts game is a draw by * draughts' rule, and a stalled race — Halma or Chinese Checkers — a draw by * the no-progress rule, and each says so with that rule's count. * * Derived, never stored — the same way `drawnByLength` answers its question. * A finished game is its settings and its moves, and anything the two of them * imply is a question to ask, not a column to keep in step. * * Read from the table, like everything here: the engine never asks a game's name. */ export declare function stalledDrawOf(state: GameState): StalledDraw | null; /** Whether this game can run away at all: pieces that move rather than land. */ export declare function canStall(variant: string): boolean; /** * How far a point is from the camp a colour is trying to fill, or null when * this board has no camps this rule can read. * * NULL RATHER THAN ZERO, and that is the whole of a bug worth remembering. * The first version answered zero for a board it did not know — and zero is a * distance, so every piece was already home, no move ever set a new low, and * every game read as one long idle run. Measured on Chinese Checkers, whose * 17×17 star board is not in the square game's table: the rule would have * drawn every game of it at the threshold, and the reason would have looked * like a property of the game rather than a hole in the rule. * * A rule that cannot measure must not fire. Silence is the safe answer; zero * is the dangerous one. * * Measured to the far corner of the camp rather than its nearest square, so * the number keeps falling all the way in: a piece at the camp's edge is * still getting somewhere while it fills the depth of it. */ export declare function distanceHome(size: number, stone: Stone, point: Point): number | null; /** * How long a game has gone since the last move that could not be taken back, * for the families measured that way, or null where the question is asked as * a window instead. * * Two families answer a count, and they are the same rule with two definitions * of irreversible: * * TAKING (checkers) since the last capture or man's move. Draughts' * own rule, and both halves are one-way: a captured * piece does not come back and a king never becomes * a man again. * * PLACING (squareFour) since the last piece went down. Four each, then * "a turn moves one" — and from that ply on nothing * can change what is ACHIEVABLE, because there are * no captures and every slide can be slid back. * * The placing count never resets, and that is a fact about the game rather * than a fault in the measure: the position space closes when the last piece * lands and stays closed. It is worth saying out loud, because a counter that * only grows is the worst possible thing to compute by walking backwards. All * the placements come first — the phase is monotonic and no piece is ever * removed — so the count is arithmetic rather than a search, and stays O(1) * however long the shuffle runs. See `racingStalled` for what walking this * kind of thing on every node of the bot's search costs. */ export declare function pliesWithoutProgress(state: GameState): number | null; /** * Whether this game has gone nowhere for long enough to call it a draw. * * Which question to ask is read from the table, not from the variant's name. * This used to say `variant !== RULE_VARIANTS.checkers`, which is the engine * switching on a name — the thing AGENTS.md says it never does — and it was * wrong as well as irregular the moment a third family wanted a count. */ export declare function stalled(state: GameState): boolean;