Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locales/en/apgames.json
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@
"name": "Lines of 2"
},
"#line": {
"name": "Lines of 3"
"name": "Lines of 3 (default)"
},
"line-4": {
"name": "Lines of 4"
Expand Down
32 changes: 26 additions & 6 deletions src/games/akimbo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading