From fe8e5aed2be07a591a7fd8da8e6f4933bfcdf775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Neto?= <886455+jpneto@users.noreply.github.com> Date: Mon, 13 Jul 2026 09:07:31 +0100 Subject: [PATCH] correct Akimbo's bug when removing a crosscut, the game was unable to compute an eventual new naked diagonal --- locales/en/apgames.json | 2 +- src/games/akimbo.ts | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/locales/en/apgames.json b/locales/en/apgames.json index 59e960de..f081814f 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -1917,7 +1917,7 @@ "name": "Lines of 2" }, "#line": { - "name": "Lines of 3" + "name": "Lines of 3 (default)" }, "line-4": { "name": "Lines of 4" diff --git a/src/games/akimbo.ts b/src/games/akimbo.ts index f5b5e1ca..47da7e9c 100644 --- a/src/games/akimbo.ts +++ b/src/games/akimbo.ts @@ -257,6 +257,25 @@ export class AkimboGame extends GameBase { return false; } + // check if the removal of a cross cut at `cell` creates a new naked diagonal + // the function returns the new naked diagonal, or [] otherwise + private checkCrossCutRemoval(cell: string): string[] { + const dirs: [Direction, Direction][] = [["N","E"],["S","E"],["S","W"],["N","W"]]; + + for (const [dir1, dir2] of dirs) { + const [p1, p2, p3] = this.checkDiagonal(cell, dir1, dir2); + if ( p1 === 4 || p2 === 4 ) { continue; } + if ( p1 === this.currplayer && p2 === this.currplayer && p3 !== this.currplayer ) { + const g = new RectGrid(this.boardSize, this.boardSize); + const [x,y] = this.algebraic2coords(cell); + + return [g.ray(x, y, dir1).map(n => this.coords2algebraic(...n))[0], + g.ray(x, y, dir2).map(n => this.coords2algebraic(...n))[0]]; + } + } + return []; + } + public handleClick(move: string, row: number, col: number, piece?: string): IClickResult { try { const cell = this.coords2algebraic(col, row); @@ -364,17 +383,18 @@ export class AkimboGame extends GameBase { } if ( this.isCrosscut(m) ) { + const toDelete = this.pairNakedDiagonal(m); + this.board.delete(toDelete); + this.results.push( {type: "remove", where: toDelete} ); + // m and its pair are the one and only naked diagonal of current player // so the naked diagonal disappears, since its pair is about to be removed + // now check if the removal created a new naked diagonal at its adjacent pieces if ( this.currplayer === 1 ) { - this.nakedDiagonalP1 = []; + this.nakedDiagonalP1 = this.checkCrossCutRemoval(toDelete); } else { - this.nakedDiagonalP2 = []; + this.nakedDiagonalP2 = this.checkCrossCutRemoval(toDelete); } - - const toDelete = this.pairNakedDiagonal(m); - this.board.delete(toDelete); - this.results.push( {type: "remove", where: toDelete} ); } this.lastmove = m;