From 1af43cf92b7fee8273d30d63d4218330cdbc87de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Neto?= <886455+jpneto@users.noreply.github.com> Date: Sat, 20 Jun 2026 08:58:14 +0100 Subject: [PATCH] Update pollux.ts --- src/games/pollux.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/games/pollux.ts b/src/games/pollux.ts index 235291f6..0f72c1fa 100644 --- a/src/games/pollux.ts +++ b/src/games/pollux.ts @@ -204,26 +204,24 @@ export class PolluxGame extends GameBase { const empties = (this.graph.listCells() as string[]).filter(c => !this.board.has(c)); ///// hack: to work with AP's playground (since flags no-moves and automove are incompatible) - // this is the computational heaviest ply of the game - if (! safe ) { - const ply2moves: string[] = []; - this.shuffle(empties); - for (const cell of empties) { - if ( this.nNeighbors(cell).length === 0 ) { - for (const cell1 of empties) { - if ( cell === cell1 ) { continue; } - if ( this.nNeighbors(cell1).length === 0 && - !this.graph.neighbours(cell).includes(cell1) ) { - ply2moves.push(`${cell},${cell1}`); - } + // this is the computational heaviest ply of the game, computing all possible moves is unfeasible + this.shuffle(empties); + for (const cell of empties) { + if ( this.nNeighbors(cell).length === 0 ) { + for (const cell1 of empties) { + if ( cell === cell1 ) { continue; } + if ( this.nNeighbors(cell1).length === 0 && + !this.graph.neighbours(cell).includes(cell1) ) { + moves.push(`${cell},${cell1}`); } } - if (ply2moves.length === 2) { return ply2moves; } } + if (moves.length > 2) { break; } } //// end hack - for (const cell of empties) { + /* validateMove does not need this computation, which is too costly: O(n^4) + for (const cell of empties) { if ( this.nNeighbors(cell).length === 0 ) { for (const cell1 of empties) { if ( cell === cell1 ) { continue; } @@ -233,7 +231,7 @@ export class PolluxGame extends GameBase { } } } - } + }*/ } if ( this.stack.length === 4 ) { @@ -269,7 +267,7 @@ export class PolluxGame extends GameBase { } } } - + if (! safe ) { // shows a sample of moves (just for the frontend, the code will keep `safe` as true) this.shuffle(moves); return moves.slice(0, 50); // output a random (smallish) selection of moves