From af05a99de2b408406dc8211a4aa66fb9c0842022 Mon Sep 17 00:00:00 2001 From: Mark Steere <80453551+MarkSteere@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:15:04 +0800 Subject: [PATCH 1/3] Clear Path: ring the stones that cut the loser off instead of drawing a line A player reported a finished game in which the "highlighted path" ran through a crosscut. The game had ended by cut-off (the loser had no possible connecting path left), and the board drew the sealing chain of the winner's stones, which may step diagonally, as a line, so it looked like a claimed winning path. - After a cut-off the sealing stones are now ringed (`exit` annotation, shape circle, solid) and no line is drawn. A completed winning path is still drawn as a line. - The game description states the cut-off ending, and the move-log line for it now reads "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off." - Game version 20261117. Tests: the reported position (reached by a legal move sequence) and the ring/line distinction; 18 tests pass, full suite 2633 pass, typecheck, eslint and locale checks clean, 10,943 render JSONs of random games validated against the renderer schema. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_017npPuLb95uaXUHuPGvTT1b --- CHANGELOG.md | 3 +- .../en/apresults/apresults-path-map.json | 2 +- locales/en/apgames.json | 4 +- locales/en/apresults.json | 2 +- src/games/clearpath.ts | 43 +++++++----- test/games/clearpath.test.ts | 65 ++++++++++++++++--- 6 files changed, 88 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dec098b8..40575077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ Since the `1.0.0-beta` release, the version in `package.json` has stayed at `1.0 - **New games (dev / experimental only):** Agents of MARS, Bagh Chal, Bashni, Bricka, Croda, Dama, Ice Palace, Neutron, Outbound, QBF, Squares, Thricewise. -## [1.0.0-ci] - 2026-11-16 +## [1.0.0-ci] - 2026-11-17 ### Added @@ -46,6 +46,7 @@ Since the `1.0.0-beta` release, the version in `package.json` has stayed at `1.0 - **Alien City:** faster placement legality (board-local road graph instead of full-state clones), cached road distances for scoring, **`hasLegalPlacement`** for pass validation, **`no-moves` removed** so legal move lists are available to clients again; reject endgame tower claims when no legal placements remain; structured move log includes **`nullifyClaim`** when a claim is voided at game end. - **`handleClick` API:** optional fifth argument **`IHandleClickUi`** (`panelId`, `board` as **`IClickBoardContext`**) for composite panels and draw-grid-aware board clicks; clients pass `ui.board` from the visible `APRenderRep.board` (Abstract Play front and playground ship this for Quax diamond-board). - **Render annotations:** connection paths, win lines, and other undirected polylines use `type: "line"` instead of `type: "move"` with `arrow: false` (dozens of games; piece-slide highlights unchanged in Tintas, Chase, and Swarm; Even at Odds unchanged; Fractured score-track shifts stay `move` with arrows; Sentinel lines-of-sight stay `move` without arrowheads). +- **Clear Path:** after a cut-off win the stones that cut the loser off are ringed (`exit` circle annotation) instead of being joined by a line, so nothing on the board looks like a path through a crosscut; a completed winning path is still drawn as a line. Game description states the cut-off ending, and the move-log line says the ringed stones cut the loser off (`version` `20261117`). ### Fixed diff --git a/locale-src/en/apresults/apresults-path-map.json b/locale-src/en/apresults/apresults-path-map.json index fba43066..817940e0 100644 --- a/locale-src/en/apresults/apresults-path-map.json +++ b/locale-src/en/apresults/apresults-path-map.json @@ -2500,7 +2500,7 @@ "newLeaf": "cutoff", "newPath": "clearpath.EOG.cutoff", "newFullKey": "apresults:clearpath.EOG.cutoff", - "english": "{{player}} no longer has any possible connecting path." + "english": "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off." }, { "oldPath": "CLAIM.conhex", diff --git a/locales/en/apgames.json b/locales/en/apgames.json index ea0906ce..e5963fac 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -4302,7 +4302,7 @@ "cifra": "A breakthrough-style game where the board configuration changes from game to game.", "circleOfLife": "Place stones on a hex ecosystem to form species shapes. Each species devours the next lower species on the food chain. Capture 20 opponent stones, or fill the board as much as you can.", "clearcut": "Connect opposite sides of the board. Lines of pieces may cross in some circumstances, and this results in the removal of some opposing pieces.", - "clearpath": "An orthogonal connection game on the points of a square grid. Red connects the top and bottom edges, Blue the left and right edges, with a chain of orthogonally adjacent stones. Each turn you place one stone. A point is vital to a player if every possible connection of theirs passes through it. You may not place on a point vital to your opponent unless it is also vital to you, or your placement completes your connection. Crosscuts are allowed.", + "clearpath": "An orthogonal connection game on the points of a square grid. Red connects the top and bottom edges, Blue the left and right edges, with a chain of orthogonally adjacent stones. Each turn you place one stone. A point is vital to a player if every possible connection of theirs passes through it. You may not place on a point vital to your opponent unless it is also vital to you, or your placement completes your connection. Crosscuts are allowed. A placement that leaves your opponent without any possible connection wins at once, since your opponent can never connect.", "clusterfuss": "Continually capture pieces with the aim of detaching (and thereby eliminating) groups of opposing pieces. Be the last man standing!", "compart": "Play on each viable area, but be the one with fewer pieces at the end.", "complica": "A simple connect-4 game played on a narrow field where the columns never fill up.", @@ -4862,7 +4862,7 @@ "catsdogs": "The original game, *SNORT*, was designed by Simon Norton in 1970. The only rule was to prevent stones of different colors to be orthogonally adjacent. A stalemated player loses the game. Norton also proposed the misère version (stalemate is a win). The original game is, however, broken via a mirror strategy. Chris Huntoon proposed a bigger 11x11 board where the player cannot start at the center (in order to prevent mirroring) which he called *Cats and Dogs*, and is the main game here. Also available is the Portuguese tournament ruleset, played on the smaller 8x8 board, but where the first player must start at the central 2x2 area, and the second player must answer outside that area. This allows the game to break the mirror strategy, and still be played on the original smaller board. Check also Snort's article at [AGM#15](https://www.abstractgames.org/uploads/1/1/6/4/116462923/abstract_games_issue_15.pdf).", "chase": "Currently, most exchange moves will need to be hand edited. We're working on fixing this.", "circleOfLife": "Species are numbered 0–11 counterclockwise on the ring, starting with the single-hex species at the top. Species 0 eats 11; each other species eats the one numbered directly below it. Predation only occurs when you place a stone that forms a species adjacent to prey. Groups may not exceed four stones. The first player to capture 20 opponent stones wins, or the player who cannot place on their turn wins (having filled the ecosystem).", - "clearpath": "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. The chain of stones that cuts the opponent off is drawn on the board, as is a completed winning path.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", + "clearpath": "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. A completed winning path is drawn as a line through its stones. After a cut-off there is no winning path yet, and the stones that cut the opponent off (a chain from edge to edge in which diagonal steps are allowed) are ringed instead.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", "conspirateurs": "In the base game, pieces may move through sanctuaries as part of a multistep jump. They're not frozen until they end their move in a sanctuary. In the strict variant, pieces are frozen as soon as they enter a sanctuary.\n\nIn four-player games, players 1 and 2 are partnered, as are players 3 and 4.", "deckfish": "More information on the Decktet system can be found on the [official Decktet website](https://www.decktet.com).\n\nThe suit powers (token movement abilities) are:\n* Moons: Jump orthogonally over gaps. \n* Suns: Move one or two cards diagonally. \n* Waves: Move orthogonally until the last unobstructed card. \n* Leaves: Move orthogonally onto any card with no neighboring obstacles.\n* Wyrms: Move orthogonally onto the first occupied card, bumping that piece to the next card.\n* Knots: Make three orthogonal one-card moves, without backtracking.\n\nIn the rules, the \"first\" player is the player who places second in the placement phase but moves first in the movement phase, but here the first player is the one who places first but moves second. This is implemented using an automatic pass for the appropriate player.\n\nThe rule is enforced that, even when the last player is already winning, he must continue playing until he is out of moves.", "domineering": "Domineering, aka, Stop-Gate, is a partisan combinatorial game. The game was designed by Göran Andersson, c.1973, and was presented in the seminal CGT book *Winning Ways for Your Mathematical Plays*. There is an impartial version, called Cram, where players can both place horizontal or vertical dominoes. The variant \"Quelhas\" was proposed by Carlos P. Santos and Alfie Davies in 2025, being a misère version (the player without options wins the game) and using longer domino-like polyominoes.", diff --git a/locales/en/apresults.json b/locales/en/apresults.json index d73f5c50..f480a26d 100644 --- a/locales/en/apresults.json +++ b/locales/en/apresults.json @@ -552,7 +552,7 @@ }, "clearpath": { "EOG": { - "cutoff": "{{player}} no longer has any possible connecting path." + "cutoff": "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off." } }, "conhex": { diff --git a/src/games/clearpath.ts b/src/games/clearpath.ts index 9523d179..3a3b1e3b 100644 --- a/src/games/clearpath.ts +++ b/src/games/clearpath.ts @@ -37,7 +37,7 @@ export const gameApgamesEn = { export const gameApresultsEn = { EOG: { - cutoff: "{{player}} no longer has any possible connecting path.", + cutoff: "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off.", }, }; @@ -242,10 +242,10 @@ export class ClearPathGame extends GameBase { name: "Clear Path", uid: "clearpath", playercounts: [2], - version: "20261014", + version: "20261117", dateAdded: "2026-11-01", - description: "An orthogonal connection game on the points of a square grid. Red connects the top and bottom edges, Blue the left and right edges, with a chain of orthogonally adjacent stones. Each turn you place one stone. A point is vital to a player if every possible connection of theirs passes through it. You may not place on a point vital to your opponent unless it is also vital to you, or your placement completes your connection. Crosscuts are allowed.", - notes: "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. The chain of stones that cuts the opponent off is drawn on the board, as is a completed winning path.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", + description: "An orthogonal connection game on the points of a square grid. Red connects the top and bottom edges, Blue the left and right edges, with a chain of orthogonally adjacent stones. Each turn you place one stone. A point is vital to a player if every possible connection of theirs passes through it. You may not place on a point vital to your opponent unless it is also vital to you, or your placement completes your connection. Crosscuts are allowed. A placement that leaves your opponent without any possible connection wins at once, since your opponent can never connect.", + notes: "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. A completed winning path is drawn as a line through its stones. After a cut-off there is no winning path yet, and the stones that cut the opponent off (a chain from edge to edge in which diagonal steps are allowed) are ringed instead.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", urls: [ "https://www.marksteeregames.com/Clear_Path_rules.pdf", "https://www.marksteeregames.com", @@ -681,26 +681,33 @@ export class ClearPathGame extends GameBase { } } - // When the game is over, draw the winner's decisive chain: the - // winning path, or, after a cut-off, the chain of stones (diagonal - // steps allowed) that leaves the loser without any possible - // connecting path. + // When the game is over, show why. After a win by connection the + // winning path is drawn as a line through the stones. After a + // cut-off there is no winning path yet: the stones that leave the + // loser without any possible connecting path (a chain from edge to + // edge in which diagonal steps are allowed) are ringed instead, so + // that nothing on the board looks like a path through a crosscut. if (this.gameover && this.winner.length === 1) { const cells = this.toCells(); const winner = this.winner[0]; - let chain = cpEdgeChain(cells, n, n, winner, false); - if (chain.length === 0) { - chain = cpEdgeChain(cells, n, n, winner, true); - } - if (chain.length > 1) { - const targets = chain.map(idx => { - const x = idx % n; - return {row: (idx - x) / n, col: x}; - }); + const toTargets = (chain: number[]): [RowCol, ...RowCol[]] => chain.map(idx => { + const x = idx % n; + return {row: (idx - x) / n, col: x}; + }) as [RowCol, ...RowCol[]]; + const path = cpEdgeChain(cells, n, n, winner, false); + if (path.length > 1) { if (rep.annotations === undefined) { rep.annotations = []; } - rep.annotations.push({type: "line", targets: targets as [RowCol, ...RowCol[]], arrow: false}); + rep.annotations.push({type: "line", targets: toTargets(path), arrow: false}); + } else { + const seal = cpEdgeChain(cells, n, n, winner, true); + if (seal.length > 0) { + if (rep.annotations === undefined) { + rep.annotations = []; + } + rep.annotations.push({type: "exit", shape: "circle", style: "solid", targets: toTargets(seal)}); + } } } diff --git a/test/games/clearpath.test.ts b/test/games/clearpath.test.ts index 0e3fb171..9010e63f 100644 --- a/test/games/clearpath.test.ts +++ b/test/games/clearpath.test.ts @@ -35,8 +35,8 @@ function dotsOf(g: ClearPathGame): Array<{colour: number | string | undefined; p .map(m => ({colour: m.colour, points: m.points!.map(p => g.coords2algebraic(p.col, p.row))})); } -/** The chain drawn at the end of the game, in algebraic notation. */ -function chainOf(g: ClearPathGame): string[] { +/** The winning path drawn as a line at the end of the game, in algebraic notation. */ +function lineOf(g: ClearPathGame): string[] { const annotations = (g.render().annotations ?? []) as Array<{type: string; targets?: Array<{row: number; col: number}>}>; const line = annotations.find(a => a.type === "line"); if (line === undefined) { @@ -45,6 +45,18 @@ function chainOf(g: ClearPathGame): string[] { return line.targets!.map(p => g.coords2algebraic(p.col, p.row)); } +/** The stones ringed at the end of the game (the stones that cut the loser off), in algebraic notation. */ +function ringsOf(g: ClearPathGame): string[] { + const annotations = (g.render().annotations ?? []) as Array<{type: string; shape?: string; style?: string; targets?: Array<{row: number; col: number}>}>; + const rings = annotations.find(a => a.type === "exit"); + if (rings === undefined) { + return []; + } + expect(rings.shape).to.equal("circle"); + expect(rings.style).to.equal("solid"); + return rings.targets!.map(p => g.coords2algebraic(p.col, p.row)); +} + describe("Clear Path", () => { describe("Setup", () => { it("defaults to a 9x9 board and honours size variants", () => { @@ -123,9 +135,10 @@ describe("Clear Path", () => { expect(g.gameover).to.be.true; expect(g.winner).to.deep.equal([1]); expect(g.moves()).to.deep.equal([]); - // nothing is dotted once the game is over, and the winning path is drawn + // nothing is dotted once the game is over, the winning path is drawn and nothing is ringed expect(dotsOf(g)).to.deep.equal([]); - expect(chainOf(g)).to.deep.equal(["c5", "c4", "c3", "c2", "c1"]); + expect(lineOf(g)).to.deep.equal(["c5", "c4", "c3", "c2", "c1"]); + expect(ringsOf(g)).to.deep.equal([]); const results = g.stack[g.stack.length - 1]._results; expect(results).to.deep.equal([ {type: "place", where: "c3"}, @@ -238,15 +251,41 @@ describe("Clear Path", () => { ]); }); - it("draws the chain of stones that cuts the opponent off", () => { + it("rings the stones that cut the opponent off and draws no line", () => { const g = play(7, [...before, "d3"]); - expect(chainOf(g)).to.deep.equal(["b7", "b6", "b5", "c4", "d3", "e2", "f1"]); + expect(ringsOf(g)).to.deep.equal(["b7", "b6", "b5", "c4", "d3", "e2", "f1"]); + expect(lineOf(g)).to.deep.equal([]); expect(dotsOf(g)).to.deep.equal([]); - // the chain is a chain of red stones, orthogonal or diagonal steps, edge to edge + // the ringed stones are a chain of red stones, orthogonal or diagonal steps, edge to edge const chain = cpEdgeChain(cellsOf(g), 7, 7, 1, true).map(idx => g.coords2algebraic(idx % 7, Math.floor(idx / 7))); expect(chain).to.deep.equal(["b7", "b6", "b5", "c4", "d3", "e2", "f1"]); }); + it("handles the position of the November 2026 bug report", () => { + // 7x7. The player connecting left and right (player 2) sealed the + // other player off with g1. Player 2 has no completed path (the + // sealing chain passes the crosscut d4, e3 / d3, e4), so the win + // is by cut-off, and the sealing stones are ringed, not joined. + const g = play(7, ["b7", "a7", "e7", "c7", "c6", "b6", "g6", "d6", "a5", "e6", "c5", "f6", "d5", "b5", "e5", "c4", "f5", "d4", "g5", "a3", "a4", "b3", "b4", "c3", "e4", "e3", "g4", "c2", "d3", "d2", "g3", "f2", "b2", "e1", "e2", "f1", "g2"]); + expect(g.gameover).to.be.false; + expect(g.currplayer).to.equal(2); + // g1 is vital to both players, so player 2 may take it + expect(g.moves()).to.include("g1"); + g.move("g1"); + expect(g.gameover).to.be.true; + expect(g.winner).to.deep.equal([2]); + const cells = cellsOf(g); + expect(cpHasWinningPath(cells, 7, 7, 2)).to.be.false; + expect(cpConnects(cells, 7, 7, 1, true)).to.be.false; + expect(g.stack[g.stack.length - 1]._results).to.deep.equal([ + {type: "place", where: "g1"}, + {type: "eog", reason: "cutoff"}, + {type: "winners", players: [2]}, + ]); + expect(ringsOf(g)).to.deep.equal(["a3", "b3", "c4", "d4", "e3", "f2", "g1"]); + expect(lineOf(g)).to.deep.equal([]); + }); + it("explains the ending in the move log", () => { addResource("en"); const g = play(7, [...before, "d3"]); @@ -260,6 +299,9 @@ describe("Clear Path", () => { "apresults:_general.WINNERS", ]); expect(last.lines[1].textParams).to.deep.equal({player: "Blue player"}); + const formatted = g.chatLog(names); + const lastFormatted = formatted[formatted.length - 1]; + expect(lastFormatted).to.include("Blue player no longer has any possible connecting path. The ringed stones cut Blue player off."); assertChatLogParity(g, names); }); @@ -298,7 +340,14 @@ describe("Clear Path", () => { } // the loser never has a possible connection left, and the winner's chain is drawn expect(cpConnects(cells, 7, 7, loser, true)).to.be.false; - expect(chainOf(g).length).to.be.greaterThan(1); + // a winning path is drawn as a line, the stones that cut the loser off are ringed, never both + if (byCutoff) { + expect(ringsOf(g).length).to.be.greaterThan(1); + expect(lineOf(g)).to.deep.equal([]); + } else { + expect(lineOf(g).length).to.be.greaterThan(1); + expect(ringsOf(g)).to.deep.equal([]); + } expect(dotsOf(g)).to.deep.equal([]); // serialisation round trip const g2 = new ClearPathGame(g.serialize()); From 512b4ebb64f38f6b989b472743ca20e750427b9e Mon Sep 17 00:00:00 2001 From: Mark Steere <80453551+MarkSteere@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:16:55 +0800 Subject: [PATCH 2/3] Clear Path: after a cut-off, show a possible connection instead of the sealing chain Replaces the rings of the previous commit. After a cut-off win the board now draws one of the winner's remaining possible connections (the one needing the fewest further stones, orthogonal steps only, so it never passes a crosscut) as a dashed line, with the stones still to be placed drawn faintly (legend glyphs with opacity 0.35). A completed winning path is still drawn as a solid line. The move-log line for the cut-off ending now reads "{{player}} no longer has any possible connection, so {{winner}} cannot be stopped. The dashed line shows one of the possible connections still open to {{winner}}." New helper cpPossibleConnection (0-1 breadth-first search). Tests cover the route chosen for two cut-off positions, the faint stones, and random play; 19 tests pass, typecheck, eslint and locale checks clean, 10,943 render JSONs of random games validated against the renderer schema. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_017npPuLb95uaXUHuPGvTT1b --- CHANGELOG.md | 2 +- .../en/apresults/apresults-path-map.json | 4 +- locales/en/apgames.json | 2 +- locales/en/apresults.json | 2 +- src/games/clearpath.ts | 112 +++++++++++++++--- test/games/clearpath.test.ts | 108 +++++++++++++---- 6 files changed, 183 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40575077..a25936fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ Since the `1.0.0-beta` release, the version in `package.json` has stayed at `1.0 - **Alien City:** faster placement legality (board-local road graph instead of full-state clones), cached road distances for scoring, **`hasLegalPlacement`** for pass validation, **`no-moves` removed** so legal move lists are available to clients again; reject endgame tower claims when no legal placements remain; structured move log includes **`nullifyClaim`** when a claim is voided at game end. - **`handleClick` API:** optional fifth argument **`IHandleClickUi`** (`panelId`, `board` as **`IClickBoardContext`**) for composite panels and draw-grid-aware board clicks; clients pass `ui.board` from the visible `APRenderRep.board` (Abstract Play front and playground ship this for Quax diamond-board). - **Render annotations:** connection paths, win lines, and other undirected polylines use `type: "line"` instead of `type: "move"` with `arrow: false` (dozens of games; piece-slide highlights unchanged in Tintas, Chase, and Swarm; Even at Odds unchanged; Fractured score-track shifts stay `move` with arrows; Sentinel lines-of-sight stay `move` without arrowheads). -- **Clear Path:** after a cut-off win the stones that cut the loser off are ringed (`exit` circle annotation) instead of being joined by a line, so nothing on the board looks like a path through a crosscut; a completed winning path is still drawn as a line. Game description states the cut-off ending, and the move-log line says the ringed stones cut the loser off (`version` `20261117`). +- **Clear Path:** after a cut-off win the board no longer draws the winner's sealing chain (which steps diagonally and could pass a crosscut); it draws one of the winner's remaining possible connections instead, the one needing the fewest further stones, as a dashed line with the stones still to be placed shown faintly. A completed winning path is still drawn as a solid line. Game description states the cut-off ending, and the move-log line names the winner and the dashed line (`version` `20261117`). ### Fixed diff --git a/locale-src/en/apresults/apresults-path-map.json b/locale-src/en/apresults/apresults-path-map.json index 817940e0..c3c85b48 100644 --- a/locale-src/en/apresults/apresults-path-map.json +++ b/locale-src/en/apresults/apresults-path-map.json @@ -1,5 +1,5 @@ { - "generatedAt": "2026-11-16", + "generatedAt": "2026-11-17", "schemaVersion": 1, "entries": [ { @@ -2500,7 +2500,7 @@ "newLeaf": "cutoff", "newPath": "clearpath.EOG.cutoff", "newFullKey": "apresults:clearpath.EOG.cutoff", - "english": "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off." + "english": "{{player}} no longer has any possible connection, so {{winner}} cannot be stopped. The dashed line shows one of the possible connections still open to {{winner}}." }, { "oldPath": "CLAIM.conhex", diff --git a/locales/en/apgames.json b/locales/en/apgames.json index e5963fac..c2ddc6cc 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -4862,7 +4862,7 @@ "catsdogs": "The original game, *SNORT*, was designed by Simon Norton in 1970. The only rule was to prevent stones of different colors to be orthogonally adjacent. A stalemated player loses the game. Norton also proposed the misère version (stalemate is a win). The original game is, however, broken via a mirror strategy. Chris Huntoon proposed a bigger 11x11 board where the player cannot start at the center (in order to prevent mirroring) which he called *Cats and Dogs*, and is the main game here. Also available is the Portuguese tournament ruleset, played on the smaller 8x8 board, but where the first player must start at the central 2x2 area, and the second player must answer outside that area. This allows the game to break the mirror strategy, and still be played on the original smaller board. Check also Snort's article at [AGM#15](https://www.abstractgames.org/uploads/1/1/6/4/116462923/abstract_games_issue_15.pdf).", "chase": "Currently, most exchange moves will need to be hand edited. We're working on fixing this.", "circleOfLife": "Species are numbered 0–11 counterclockwise on the ring, starting with the single-hex species at the top. Species 0 eats 11; each other species eats the one numbered directly below it. Predation only occurs when you place a stone that forms a species adjacent to prey. Groups may not exceed four stones. The first player to capture 20 opponent stones wins, or the player who cannot place on their turn wins (having filled the ecosystem).", - "clearpath": "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. A completed winning path is drawn as a line through its stones. After a cut-off there is no winning path yet, and the stones that cut the opponent off (a chain from edge to edge in which diagonal steps are allowed) are ringed instead.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", + "clearpath": "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. A completed winning path is drawn as a solid line through its stones. After a cut-off there is no winning path yet. A dashed line then shows one of the winner's remaining possible connections, the one needing the fewest further stones, with those stones drawn faintly.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", "conspirateurs": "In the base game, pieces may move through sanctuaries as part of a multistep jump. They're not frozen until they end their move in a sanctuary. In the strict variant, pieces are frozen as soon as they enter a sanctuary.\n\nIn four-player games, players 1 and 2 are partnered, as are players 3 and 4.", "deckfish": "More information on the Decktet system can be found on the [official Decktet website](https://www.decktet.com).\n\nThe suit powers (token movement abilities) are:\n* Moons: Jump orthogonally over gaps. \n* Suns: Move one or two cards diagonally. \n* Waves: Move orthogonally until the last unobstructed card. \n* Leaves: Move orthogonally onto any card with no neighboring obstacles.\n* Wyrms: Move orthogonally onto the first occupied card, bumping that piece to the next card.\n* Knots: Make three orthogonal one-card moves, without backtracking.\n\nIn the rules, the \"first\" player is the player who places second in the placement phase but moves first in the movement phase, but here the first player is the one who places first but moves second. This is implemented using an automatic pass for the appropriate player.\n\nThe rule is enforced that, even when the last player is already winning, he must continue playing until he is out of moves.", "domineering": "Domineering, aka, Stop-Gate, is a partisan combinatorial game. The game was designed by Göran Andersson, c.1973, and was presented in the seminal CGT book *Winning Ways for Your Mathematical Plays*. There is an impartial version, called Cram, where players can both place horizontal or vertical dominoes. The variant \"Quelhas\" was proposed by Carlos P. Santos and Alfie Davies in 2025, being a misère version (the player without options wins the game) and using longer domino-like polyominoes.", diff --git a/locales/en/apresults.json b/locales/en/apresults.json index f480a26d..636460f5 100644 --- a/locales/en/apresults.json +++ b/locales/en/apresults.json @@ -552,7 +552,7 @@ }, "clearpath": { "EOG": { - "cutoff": "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off." + "cutoff": "{{player}} no longer has any possible connection, so {{winner}} cannot be stopped. The dashed line shows one of the possible connections still open to {{winner}}." } }, "conhex": { diff --git a/src/games/clearpath.ts b/src/games/clearpath.ts index 3a3b1e3b..84b9fea3 100644 --- a/src/games/clearpath.ts +++ b/src/games/clearpath.ts @@ -37,7 +37,7 @@ export const gameApgamesEn = { export const gameApresultsEn = { EOG: { - cutoff: "{{player}} no longer has any possible connecting path. The ringed stones cut {{player}} off.", + cutoff: "{{player}} no longer has any possible connection, so {{winner}} cannot be stopped. The dashed line shows one of the possible connections still open to {{winner}}.", }, }; @@ -184,6 +184,67 @@ export function cpEdgeChain(cells: Uint8Array, width: number, height: number, pl return []; } +/** + * A possible connection of `player` with the fewest unoccupied points: a + * chain of orthogonally adjacent points from one of the player's edges to + * the other, each holding a stone of the player or unoccupied, chosen so + * that as few points as possible are unoccupied. Returned as a list of + * point indices from edge to edge, or an empty list if the player has no + * possible connection. + */ +export function cpPossibleConnection(cells: Uint8Array, width: number, height: number, player: playerid): number[] { + const size = width * height; + const INF = 1 << 30; + const dist = new Int32Array(size).fill(INF); + const parent = new Int32Array(size).fill(-1); + // 0-1 breadth-first search: entering an unoccupied point costs 1, a stone of the player costs 0 + const deque = new Int32Array(2 * size + 2); + let head = size + 1; + let tail = size + 1; + const costOf = (idx: number): number => cells[idx] === player ? 0 : 1; + const usable = (idx: number): boolean => cells[idx] === player || cells[idx] === 0; + if (player === 1) { + for (let x = 0; x < width; x++) { + if (usable(x)) { dist[x] = costOf(x); if (dist[x] === 0) { deque[--head] = x; } else { deque[tail++] = x; } } + } + } else { + for (let y = 0; y < height; y++) { + const idx = y * width; + if (usable(idx)) { dist[idx] = costOf(idx); if (dist[idx] === 0) { deque[--head] = idx; } else { deque[tail++] = idx; } } + } + } + const done = new Uint8Array(size); + while (head < tail) { + const idx = deque[head++]; + if (done[idx] === 1) { continue; } + done[idx] = 1; + const x = idx % width; + const y = (idx - x) / width; + if ((player === 1 && y === height - 1) || (player === 2 && x === width - 1)) { + const chain: number[] = []; + for (let cur = idx; cur !== -1; cur = parent[cur]) { + chain.push(cur); + } + return chain.reverse(); + } + const neighbours: number[] = []; + if (x > 0) { neighbours.push(idx - 1); } + if (x < width - 1) { neighbours.push(idx + 1); } + if (y > 0) { neighbours.push(idx - width); } + if (y < height - 1) { neighbours.push(idx + width); } + for (const nidx of neighbours) { + if (!usable(nidx) || done[nidx] === 1) { continue; } + const nd = dist[idx] + costOf(nidx); + if (nd < dist[nidx]) { + dist[nidx] = nd; + parent[nidx] = idx; + if (costOf(nidx) === 0) { deque[--head] = nidx; } else { deque[tail++] = nidx; } + } + } + } + return []; +} + /** * The vital points of `player`: a mask (1 = vital) over all points. * An empty point is vital to a player if every possible connecting path for @@ -245,7 +306,7 @@ export class ClearPathGame extends GameBase { version: "20261117", dateAdded: "2026-11-01", description: "An orthogonal connection game on the points of a square grid. Red connects the top and bottom edges, Blue the left and right edges, with a chain of orthogonally adjacent stones. Each turn you place one stone. A point is vital to a player if every possible connection of theirs passes through it. You may not place on a point vital to your opponent unless it is also vital to you, or your placement completes your connection. Crosscuts are allowed. A placement that leaves your opponent without any possible connection wins at once, since your opponent can never connect.", - notes: "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. A completed winning path is drawn as a line through its stones. After a cut-off there is no winning path yet, and the stones that cut the opponent off (a chain from edge to edge in which diagonal steps are allowed) are ringed instead.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", + notes: "Clear Path was designed by Mark Steere in September 2026, in collaboration with Claude Fable 5.1, an AI model made by Anthropic.\n\nThe dots mark the points where the player to move may not place. Each dotted point is vital to the opponent (every possible connection of the opponent passes through it), not vital to the player to move, and not a winning placement. A point vital to both players is not dotted, since either player may take it, and neither is a point where the player to move completes a winning path. The dots are drawn in the opponent's colour. A player who no longer has any possible connection has no vital points.\n\nA placement that leaves the opponent without any possible connecting path ends the game at once, and the player who placed wins: the opponent can never connect and can never take the winner's vital points, so the winner's connection can no longer be stopped. A completed winning path is drawn as a solid line through its stones. After a cut-off there is no winning path yet. A dashed line then shows one of the winner's remaining possible connections, the one needing the fewest further stones, with those stones drawn faintly.\n\nPassing is not allowed, but a player with no legal placement has their turn skipped. The pass is submitted automatically.", urls: [ "https://www.marksteeregames.com/Clear_Path_rules.pdf", "https://www.marksteeregames.com", @@ -566,10 +627,11 @@ export class ClearPathGame extends GameBase { protected eogChatLineOverride(r: Extract, ctx: ChatLogCollectContext): ChatLogLine | undefined { if (r.reason === "cutoff") { const loser = this.resolveChatPlayerName(ctx.currplayer, ctx.players); + const winner = this.resolveChatPlayerName(ctx.currplayer === 1 ? 2 : 1, ctx.players); return { actor: { kind: "none" }, textKey: "apresults:clearpath.EOG.cutoff", - textParams: { player: loser }, + textParams: { player: loser, winner }, }; } return undefined; @@ -603,6 +665,22 @@ export class ClearPathGame extends GameBase { public render(): APRenderRep { const n = this.boardsize; + // When the game has ended by cut-off, the winner has no winning + // path yet. Show one of the winner's remaining possible connections + // (the one needing the fewest further stones, orthogonal steps only, + // so it never passes a crosscut): a dashed line along it, with the + // stones still to be placed drawn faintly. + let route: number[] = []; + let routeWinner: playerid | undefined; + if (this.gameover && this.winner.length === 1) { + const cells = this.toCells(); + if (cpEdgeChain(cells, n, n, this.winner[0], false).length === 0) { + routeWinner = this.winner[0]; + route = cpPossibleConnection(cells, n, n, routeWinner); + } + } + const toPlace = new Set(route.filter(idx => !this.board.has(this.idx2cell(idx)))); + // Build piece string const pstr: string[] = []; for (let row = 0; row < n; row++) { @@ -614,6 +692,8 @@ export class ClearPathGame extends GameBase { line += "A"; } else if (contents === 2) { line += "B"; + } else if (toPlace.has(row * n + col)) { + line += routeWinner === 1 ? "C" : "D"; } else { line += "-"; } @@ -663,6 +743,9 @@ export class ClearPathGame extends GameBase { legend: { A: { name: "piece", colour: 1 }, B: { name: "piece", colour: 2 }, + // stones still to be placed on the shown possible connection + C: { name: "piece", colour: 1, opacity: 0.35 }, + D: { name: "piece", colour: 2, opacity: 0.35 }, }, pieces: pstr.join("\n"), }; @@ -682,32 +765,25 @@ export class ClearPathGame extends GameBase { } // When the game is over, show why. After a win by connection the - // winning path is drawn as a line through the stones. After a - // cut-off there is no winning path yet: the stones that leave the - // loser without any possible connecting path (a chain from edge to - // edge in which diagonal steps are allowed) are ringed instead, so - // that nothing on the board looks like a path through a crosscut. + // winning path is drawn as a solid line through the stones. After a + // cut-off the winner's possible connection chosen above is drawn as + // a dashed line (orthogonal steps only, so never through a crosscut). if (this.gameover && this.winner.length === 1) { - const cells = this.toCells(); - const winner = this.winner[0]; const toTargets = (chain: number[]): [RowCol, ...RowCol[]] => chain.map(idx => { const x = idx % n; return {row: (idx - x) / n, col: x}; }) as [RowCol, ...RowCol[]]; - const path = cpEdgeChain(cells, n, n, winner, false); + const path = cpEdgeChain(this.toCells(), n, n, this.winner[0], false); if (path.length > 1) { if (rep.annotations === undefined) { rep.annotations = []; } rep.annotations.push({type: "line", targets: toTargets(path), arrow: false}); - } else { - const seal = cpEdgeChain(cells, n, n, winner, true); - if (seal.length > 0) { - if (rep.annotations === undefined) { - rep.annotations = []; - } - rep.annotations.push({type: "exit", shape: "circle", style: "solid", targets: toTargets(seal)}); + } else if (route.length > 1) { + if (rep.annotations === undefined) { + rep.annotations = []; } + rep.annotations.push({type: "line", style: "dashed", targets: toTargets(route), arrow: false}); } } diff --git a/test/games/clearpath.test.ts b/test/games/clearpath.test.ts index 9010e63f..ff2bf972 100644 --- a/test/games/clearpath.test.ts +++ b/test/games/clearpath.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions */ import "mocha"; import { expect } from "chai"; -import { ClearPathGame, cpConnects, cpEdgeChain, cpHasWinningPath, cpLegalPlacements, cpVitalPoints } from "../../src/games/clearpath"; +import { ClearPathGame, cpConnects, cpEdgeChain, cpHasWinningPath, cpLegalPlacements, cpPossibleConnection, cpVitalPoints } from "../../src/games/clearpath"; import { assertChatLogParity } from "../fixtures/chat/helpers"; import { addResource } from "../../src"; @@ -35,26 +35,39 @@ function dotsOf(g: ClearPathGame): Array<{colour: number | string | undefined; p .map(m => ({colour: m.colour, points: m.points!.map(p => g.coords2algebraic(p.col, p.row))})); } -/** The winning path drawn as a line at the end of the game, in algebraic notation. */ +/** The winning path drawn as a solid line at the end of the game, in algebraic notation. */ function lineOf(g: ClearPathGame): string[] { - const annotations = (g.render().annotations ?? []) as Array<{type: string; targets?: Array<{row: number; col: number}>}>; - const line = annotations.find(a => a.type === "line"); + const annotations = (g.render().annotations ?? []) as Array<{type: string; style?: string; targets?: Array<{row: number; col: number}>}>; + const line = annotations.find(a => a.type === "line" && a.style !== "dashed"); if (line === undefined) { return []; } return line.targets!.map(p => g.coords2algebraic(p.col, p.row)); } -/** The stones ringed at the end of the game (the stones that cut the loser off), in algebraic notation. */ -function ringsOf(g: ClearPathGame): string[] { - const annotations = (g.render().annotations ?? []) as Array<{type: string; shape?: string; style?: string; targets?: Array<{row: number; col: number}>}>; - const rings = annotations.find(a => a.type === "exit"); - if (rings === undefined) { +/** The possible connection drawn as a dashed line after a cut-off, in algebraic notation. */ +function dashedOf(g: ClearPathGame): string[] { + const annotations = (g.render().annotations ?? []) as Array<{type: string; style?: string; targets?: Array<{row: number; col: number}>}>; + const line = annotations.find(a => a.type === "line" && a.style === "dashed"); + if (line === undefined) { return []; } - expect(rings.shape).to.equal("circle"); - expect(rings.style).to.equal("solid"); - return rings.targets!.map(p => g.coords2algebraic(p.col, p.row)); + return line.targets!.map(p => g.coords2algebraic(p.col, p.row)); +} + +/** The points shown with a faint stone (still to be placed on the drawn possible connection), in algebraic notation. */ +function faintOf(g: ClearPathGame): string[] { + const rows = (g.render().pieces as string).split("\n"); + const out: string[] = []; + for (let row = 0; row < rows.length; row++) { + if (rows[row] === "_") { continue; } + for (let col = 0; col < rows[row].length; col++) { + if (rows[row][col] === "C" || rows[row][col] === "D") { + out.push(g.coords2algebraic(col, row)); + } + } + } + return out; } describe("Clear Path", () => { @@ -135,10 +148,11 @@ describe("Clear Path", () => { expect(g.gameover).to.be.true; expect(g.winner).to.deep.equal([1]); expect(g.moves()).to.deep.equal([]); - // nothing is dotted once the game is over, the winning path is drawn and nothing is ringed + // nothing is dotted once the game is over, the winning path is drawn and nothing else expect(dotsOf(g)).to.deep.equal([]); expect(lineOf(g)).to.deep.equal(["c5", "c4", "c3", "c2", "c1"]); - expect(ringsOf(g)).to.deep.equal([]); + expect(dashedOf(g)).to.deep.equal([]); + expect(faintOf(g)).to.deep.equal([]); const results = g.stack[g.stack.length - 1]._results; expect(results).to.deep.equal([ {type: "place", where: "c3"}, @@ -251,13 +265,34 @@ describe("Clear Path", () => { ]); }); - it("rings the stones that cut the opponent off and draws no line", () => { + it("shows a remaining possible connection of the winner as a dashed line", () => { const g = play(7, [...before, "d3"]); - expect(ringsOf(g)).to.deep.equal(["b7", "b6", "b5", "c4", "d3", "e2", "f1"]); + // Red's chain b7 b6 b5 c4 d3 e2 f1 steps diagonally, so it is not drawn. + // Red's possible connection needing the fewest further stones fills + // in the staircase: b7 b6 b5 c5 c4 d4 d3 e3 e2 f2 f1, four stones + // still to be placed (c5, d4, e3, f2). expect(lineOf(g)).to.deep.equal([]); expect(dotsOf(g)).to.deep.equal([]); - // the ringed stones are a chain of red stones, orthogonal or diagonal steps, edge to edge - const chain = cpEdgeChain(cellsOf(g), 7, 7, 1, true).map(idx => g.coords2algebraic(idx % 7, Math.floor(idx / 7))); + const dashed = dashedOf(g); + expect(dashed).to.deep.equal(["b7", "b6", "b5", "c5", "c4", "d4", "d3", "e3", "e2", "f2", "f1"]); + expect(faintOf(g)).to.deep.equal(["c5", "d4", "e3", "f2"]); + // orthogonal steps only, edge to edge, every point a red stone or unoccupied + const cells = cellsOf(g); + for (let i = 1; i < dashed.length; i++) { + const [x1, y1] = g.algebraic2coords(dashed[i - 1]); + const [x2, y2] = g.algebraic2coords(dashed[i]); + expect(Math.abs(x1 - x2) + Math.abs(y1 - y2)).to.equal(1); + } + expect(g.algebraic2coords(dashed[0])[1]).to.equal(0); + expect(g.algebraic2coords(dashed[dashed.length - 1])[1]).to.equal(6); + for (const c of dashed) { + const [x, y] = g.algebraic2coords(c); + expect(cells[y * 7 + x]).to.not.equal(2); + } + // the faint stones are exactly the unoccupied points of the drawn route + expect(faintOf(g)).to.deep.equal(dashed.filter(c => !g.board.has(c))); + // the chain that cuts Blue off still exists, diagonal steps allowed, but is not drawn + const chain = cpEdgeChain(cells, 7, 7, 1, true).map(idx => g.coords2algebraic(idx % 7, Math.floor(idx / 7))); expect(chain).to.deep.equal(["b7", "b6", "b5", "c4", "d3", "e2", "f1"]); }); @@ -282,8 +317,12 @@ describe("Clear Path", () => { {type: "eog", reason: "cutoff"}, {type: "winners", players: [2]}, ]); - expect(ringsOf(g)).to.deep.equal(["a3", "b3", "c4", "d4", "e3", "f2", "g1"]); expect(lineOf(g)).to.deep.equal([]); + // the drawn possible connection needs one more stone, at d1 + expect(dashedOf(g)).to.deep.equal(["a3", "b3", "c3", "c2", "d2", "d1", "e1", "f1", "g1"]); + expect(faintOf(g)).to.deep.equal(["d1"]); + // the chain that cut player 1 off (diagonal steps allowed) is not drawn + expect(cpEdgeChain(cells, 7, 7, 2, true).map(idx => g.coords2algebraic(idx % 7, Math.floor(idx / 7)))).to.deep.equal(["a3", "b3", "c4", "d4", "e3", "f2", "g1"]); }); it("explains the ending in the move log", () => { @@ -298,10 +337,10 @@ describe("Clear Path", () => { "apresults:clearpath.EOG.cutoff", "apresults:_general.WINNERS", ]); - expect(last.lines[1].textParams).to.deep.equal({player: "Blue player"}); + expect(last.lines[1].textParams).to.deep.equal({player: "Blue player", winner: "Red player"}); const formatted = g.chatLog(names); const lastFormatted = formatted[formatted.length - 1]; - expect(lastFormatted).to.include("Blue player no longer has any possible connecting path. The ringed stones cut Blue player off."); + expect(lastFormatted).to.include("Blue player no longer has any possible connection, so Red player cannot be stopped. The dashed line shows one of the possible connections still open to Red player."); assertChatLogParity(g, names); }); @@ -312,6 +351,21 @@ describe("Clear Path", () => { }); }); + describe("Possible connections", () => { + it("finds the possible connection needing the fewest further stones", () => { + // 5x5, Red: stones a5 and a1 only. Column a needs a4, a3, a2 (three stones); + // every other route needs at least four. + const g = play(5, ["a5", "e5", "a1", "e4"]); + const route = cpPossibleConnection(cellsOf(g), 5, 5, 1).map(idx => g.coords2algebraic(idx % 5, Math.floor(idx / 5))); + expect(route).to.deep.equal(["a5", "a4", "a3", "a2", "a1"]); + // a cut-off player has none + const h = play(5, ["a5", "a1", "b4", "b2", "d2", "d4", "e1", "e5", "c3"]); + expect(h.winner).to.deep.equal([1]); + expect(cpPossibleConnection(cellsOf(h), 5, 5, 2)).to.deep.equal([]); + expect(cpPossibleConnection(cellsOf(h), 5, 5, 1).length).to.be.greaterThan(1); + }); + }); + describe("Random play", () => { it("always ends with exactly one winner, by connection or by cut-off", () => { let cutoffs = 0; @@ -340,13 +394,19 @@ describe("Clear Path", () => { } // the loser never has a possible connection left, and the winner's chain is drawn expect(cpConnects(cells, 7, 7, loser, true)).to.be.false; - // a winning path is drawn as a line, the stones that cut the loser off are ringed, never both + // a winning path is drawn as a solid line; after a cut-off a possible + // connection of the winner is drawn dashed, with faint stones on its + // unoccupied points; never both if (byCutoff) { - expect(ringsOf(g).length).to.be.greaterThan(1); + const dashed = dashedOf(g); + expect(dashed.length).to.be.greaterThan(1); expect(lineOf(g)).to.deep.equal([]); + expect(faintOf(g)).to.deep.equal(dashed.filter(c => !g.board.has(c))); + expect(faintOf(g).length).to.be.greaterThan(0); } else { expect(lineOf(g).length).to.be.greaterThan(1); - expect(ringsOf(g)).to.deep.equal([]); + expect(dashedOf(g)).to.deep.equal([]); + expect(faintOf(g)).to.deep.equal([]); } expect(dotsOf(g)).to.deep.equal([]); // serialisation round trip From 3756135e6649c12e7ac42c77933dd3503bb896de Mon Sep 17 00:00:00 2001 From: Mark Steere <80453551+MarkSteere@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:19:17 +0800 Subject: [PATCH 3/3] Clear Path tests: compare faint stones as sets The random-play test compared the faint stones (listed row by row) with the unoccupied points of the dashed route (listed edge to edge), which only agree by chance. Compare them sorted. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_017npPuLb95uaXUHuPGvTT1b --- test/games/clearpath.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/games/clearpath.test.ts b/test/games/clearpath.test.ts index ff2bf972..f0a92478 100644 --- a/test/games/clearpath.test.ts +++ b/test/games/clearpath.test.ts @@ -290,7 +290,7 @@ describe("Clear Path", () => { expect(cells[y * 7 + x]).to.not.equal(2); } // the faint stones are exactly the unoccupied points of the drawn route - expect(faintOf(g)).to.deep.equal(dashed.filter(c => !g.board.has(c))); + expect([...faintOf(g)].sort()).to.deep.equal(dashed.filter(c => !g.board.has(c)).sort()); // the chain that cuts Blue off still exists, diagonal steps allowed, but is not drawn const chain = cpEdgeChain(cells, 7, 7, 1, true).map(idx => g.coords2algebraic(idx % 7, Math.floor(idx / 7))); expect(chain).to.deep.equal(["b7", "b6", "b5", "c4", "d3", "e2", "f1"]); @@ -401,7 +401,8 @@ describe("Clear Path", () => { const dashed = dashedOf(g); expect(dashed.length).to.be.greaterThan(1); expect(lineOf(g)).to.deep.equal([]); - expect(faintOf(g)).to.deep.equal(dashed.filter(c => !g.board.has(c))); + // (faint stones are listed row by row, the route edge to edge) + expect([...faintOf(g)].sort()).to.deep.equal(dashed.filter(c => !g.board.has(c)).sort()); expect(faintOf(g).length).to.be.greaterThan(0); } else { expect(lineOf(g).length).to.be.greaterThan(1);