From d725d8f449bdceebfb0cabaa5f9c7eb0049ffd63 Mon Sep 17 00:00:00 2001 From: th555 Date: Sat, 14 Nov 2026 21:32:30 +0100 Subject: [PATCH 01/16] polypods snub --- ci-deps.dev.json | 4 +- locale-src/de/apgames.json | 4 + .../en/apresults/apresults-path-map.json | 2 +- locale-src/es-US/apgames.json | 4 + locale-src/fr/apgames.json | 4 + locale-src/it/apgames.json | 4 + locales/de/apgames.json | 1 + locales/en/apgames.json | 55 ++ locales/es-US/apgames.json | 1 + locales/fr/apgames.json | 1 + locales/it/apgames.json | 1 + package-lock.json | 22 +- package.json | 2 +- src/games/polypods.ts | 485 ++++++++++++++++++ 14 files changed, 569 insertions(+), 21 deletions(-) create mode 100644 src/games/polypods.ts diff --git a/ci-deps.dev.json b/ci-deps.dev.json index 22b4c5de..9aafbb74 100644 --- a/ci-deps.dev.json +++ b/ci-deps.dev.json @@ -1,6 +1,6 @@ { "renderer": "1.0.0-ci-41714483652.0", - "updatedAt": "2026-11-09T20:17:02.123Z", - "source": "recranks-ci-42691185522", + "updatedAt": "2026-11-14T20:05:51.337Z", + "source": "ci-deps.dev.json", "recranks": "1.0.0-ci-42691185522.0" } diff --git a/locale-src/de/apgames.json b/locale-src/de/apgames.json index 7ffc642e..d4365792 100644 --- a/locale-src/de/apgames.json +++ b/locale-src/de/apgames.json @@ -4271,6 +4271,10 @@ "src": "Pollux", "out": "Pollux" }, + "names.polypods": { + "src": "Polypods", + "out": "Polypods" + }, "names.pontedd": { "src": "Ponte del Diavolo", "out": "Ponte del Diavolo" diff --git a/locale-src/en/apresults/apresults-path-map.json b/locale-src/en/apresults/apresults-path-map.json index 6679be1a..cab00cb5 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-06", + "generatedAt": "2026-11-14", "schemaVersion": 1, "entries": [ { diff --git a/locale-src/es-US/apgames.json b/locale-src/es-US/apgames.json index 40816c6e..195732d8 100644 --- a/locale-src/es-US/apgames.json +++ b/locale-src/es-US/apgames.json @@ -4271,6 +4271,10 @@ "src": "Pollux", "out": "Pollux" }, + "names.polypods": { + "src": "Polypods", + "out": "Polypods" + }, "names.pontedd": { "src": "Ponte del Diavolo", "out": "Ponte del Diavolo" diff --git a/locale-src/fr/apgames.json b/locale-src/fr/apgames.json index 4a028e39..9d18e14c 100644 --- a/locale-src/fr/apgames.json +++ b/locale-src/fr/apgames.json @@ -4271,6 +4271,10 @@ "src": "Pollux", "out": "Pollux" }, + "names.polypods": { + "src": "Polypods", + "out": "Polypods" + }, "names.pontedd": { "src": "Ponte del Diavolo", "out": "Ponte del Diavolo" diff --git a/locale-src/it/apgames.json b/locale-src/it/apgames.json index 6ef2f52d..9669c5cd 100644 --- a/locale-src/it/apgames.json +++ b/locale-src/it/apgames.json @@ -4271,6 +4271,10 @@ "src": "Pollux", "out": "Pollux" }, + "names.polypods": { + "src": "Polypods", + "out": "Polypods" + }, "names.pontedd": { "src": "Ponte del Diavolo", "out": "Ponte del Diavolo" diff --git a/locales/de/apgames.json b/locales/de/apgames.json index e0778096..31338a8e 100644 --- a/locales/de/apgames.json +++ b/locales/de/apgames.json @@ -4742,6 +4742,7 @@ "plurality": "Plurality", "pods": "Natal Seas - Pods", "pollux": "Pollux", + "polypods": "Polypods", "pontedd": "Ponte del Diavolo", "posit": "Posit", "product": "Product", diff --git a/locales/en/apgames.json b/locales/en/apgames.json index 0a1ef0d4..f18687ea 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -2991,6 +2991,20 @@ "TOWER_STRAIGHT_LINE": "A tower moves over a line of empty hexes!", "PIECE_STRAIGHT_LINE": "A tower shoots a piece over a line of empty hexes!" }, + "polypods": { + "DISCONNECTEDMOVE": "A move from {{from}} to {{to}} would disconnect the band.", + "DISCONNECTEDPLACE": "Placing a piece at {{where}} would disconnect the band.", + "INITIAL_INSTRUCTIONS": "Place a piece on an empty space connected to the other pieces.", + "INVALIDPASS": "You cannot pass while you have pieces in hand.", + "MOVE2CONTROLLED": "You cannot capture your own stacks.", + "MOVE2EMPTY": "You cannot move to empty spaces.", + "PARTIAL": "It's possible you're trying to move a stack. Provide the destination.", + "TOOEARLY": "You cannot move until the first player has placed two pieces.", + "TOOEARLY_libre": "You cannot move until four stones have been placed on the board.", + "TOOFAR": "You can only move to an adjacent cell. {{to}} is not adjacent to {{from}}.", + "TOOHIGH": "Moving from {{from}} to {{to}} would result in a stack taller than three pieces high.", + "TRIPLESTACK": "You cannot move triple stacks." + }, "pontedd": { "BAD_BRIDGE_BLOCKED": "There may be no tiles under the bridge.", "BAD_BRIDGE_COLOUR": "Bridges must connect two tiles of the same colour.", @@ -4439,6 +4453,7 @@ "plurality": "Territorial game where players place trominos to enclosure areas. The player with more stones on a given area's perimeter owns that area.", "pods": "Natal Seas - Pods is a territorial game where the players take on the metaphorical role of competing whales vying for space to protect their young. Played on a hexagonal board, it uses an innovative mechanism of placements and movements.", "pollux": "A mix of Hex and Amazons: shoot to connect your edges or block the adversary.", + "polypods": "Polypods are creatures of the snub-square grid. They are composed of connected pieces of 2 types: core and feet. Feet are the extremities, i.e. the pieces with only one similarly-colored adjacent piece, or with exactly 2 that fill the other points of a small triangle of the grid. Core are the other pieces that connect all the feet together. Cores are toxic to the feet of adjacent opponent polypods. Polypods need to have at least as many feet as cores to stay alive. The game of Polypods is about growing and protecting polypods of your colour so that you have the most polypod cores when the game ends. Some removed pieces leave remains. Variants differ in when exactly remains are generated, and how they affect further play.", "pontedd": "Players build islands and attempt to connect as many of them as possible by bridge. Most points wins.", "posit": "Try to stalemate the adversary by building unscalable stacks.", "product": "Players score by multiplying their two largest groups. Largest score wins. If tied, the second player wins.", @@ -4742,6 +4757,7 @@ "plurality": "Plurality", "pods": "Natal Seas - Pods", "pollux": "Pollux", + "polypods": "Polypods", "pontedd": "Ponte del Diavolo", "posit": "Posit", "product": "Product", @@ -8117,6 +8133,45 @@ "name": "18x18 board" } }, + "polypods": { + "size-6": { + "name": "6x6 board" + }, + "size-7": { + "name": "7x7 board" + }, + "#size": { + "name": "8x8 board" + }, + "size-9": { + "name": "9x9 board" + }, + "size-10": { + "name": "10x10 board" + }, + "size-11": { + "name": "11x11 board" + }, + "size-12": { + "name": "12x12 board" + }, + "#variant": { + "description": "Directly attacked feet leave permanent remains.", + "name": "Polypods Base Game" + }, + "Stoney-footed": { + "description": "All removed feet leave permanent remains.", + "name": "Stoney-footed Polypods" + }, + "Energized": { + "description": "Eating remains gives a double move.", + "name": "Energized Polypods" + }, + "Scavenging": { + "description": "Every removed piece leaves remains. Placing next to (or on) a remains marker eats one, but a move that eats can't also attack.", + "name": "Scavenging Polypods" + } + }, "pontedd": { "size-8": { "name": "8x8 board" diff --git a/locales/es-US/apgames.json b/locales/es-US/apgames.json index 1faabfbc..e36f2a13 100644 --- a/locales/es-US/apgames.json +++ b/locales/es-US/apgames.json @@ -4742,6 +4742,7 @@ "plurality": "Plurality", "pods": "Natal Seas - Pods", "pollux": "Pollux", + "polypods": "Polypods", "pontedd": "Ponte del Diavolo", "posit": "Posit", "product": "Product", diff --git a/locales/fr/apgames.json b/locales/fr/apgames.json index 039103db..3372649f 100644 --- a/locales/fr/apgames.json +++ b/locales/fr/apgames.json @@ -4742,6 +4742,7 @@ "plurality": "Plurality", "pods": "Natal Seas - Pods", "pollux": "Pollux", + "polypods": "Polypods", "pontedd": "Ponte del Diavolo", "posit": "Posit", "product": "Product", diff --git a/locales/it/apgames.json b/locales/it/apgames.json index 75a0366a..1c024cba 100644 --- a/locales/it/apgames.json +++ b/locales/it/apgames.json @@ -4742,6 +4742,7 @@ "plurality": "Plurality", "pods": "Natal Seas - Pods", "pollux": "Pollux", + "polypods": "Polypods", "pontedd": "Ponte del Diavolo", "posit": "Posit", "product": "Product", diff --git a/package-lock.json b/package-lock.json index 9d8f6db7..8bd409cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@abstractplay/recranks": "1.0.0-ci-42691185522.0", - "@abstractplay/renderer": "1.0.0-ci-41714483652.0", + "@abstractplay/renderer": "1.0.0-ci-43630834489.0", "@turf/boolean-contains": "^6.5.0", "@turf/boolean-intersects": "^6.5.0", "@turf/boolean-point-in-polygon": "^6.5.0", @@ -113,9 +113,9 @@ } }, "node_modules/@abstractplay/renderer": { - "version": "1.0.0-ci-41714483652.0", - "resolved": "https://npm.pkg.github.com/download/@abstractplay/renderer/1.0.0-ci-41714483652.0/deb1971b84082a44f76339dea6c370d8122ce223", - "integrity": "sha512-mIaGQy80gv3gnGFdbwZkRvirKpRnOaK5DuWgFyZ/IyXxhn+J7uceJrIjD/H843UyLCBstt1gZV6HR5VXsAOM0Q==", + "version": "1.0.0-ci-43630834489.0", + "resolved": "https://npm.pkg.github.com/download/@abstractplay/renderer/1.0.0-ci-43630834489.0/b1fae0381fd42c3bb4d902519a91aff55cb27f1c", + "integrity": "sha512-45uM54GY0KtJ9DOO1UDQEdNVq7u7olrbY9nyq88YDehqK21E6eU6WZURyKx1mqqVaG3S95dNYD4HClgmtTf/oQ==", "license": "MIT", "dependencies": { "@svgdotjs/svg.js": "3.2.5", @@ -179,7 +179,6 @@ "integrity": "sha512-0oHSQWBZvjwcTuWOiyIemuGsXMwMvl2hqPiIoCvxiOOpgzIOqN/lcatygW3VGe9iDfHgcyqJfXC8B+XbKHpftA==", "dev": true, "license": "Apache-2.0", - "peer": true, "dependencies": { "@aws-sdk/core": "^3.977.8", "@aws-sdk/credential-provider-node": "^3.972.80", @@ -2675,7 +2674,6 @@ "integrity": "sha512-R5muMcZob3/Jjchn5LcO8jdKwSCbzqmPB6ruBxMcf9kbxtniZHP327s6C37iOfuw8mbKK3cAQa7sEl7afLrQ8A==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~6.21.0" } @@ -2747,7 +2745,6 @@ "integrity": "sha512-B2MdzyWxCE2+SqiZHAjPphft+/2x2FlO9YBx7eKE1BCb+rqBlQdhtAEhzIEdozHd55DXPmxBdpMygFJjfjjA9A==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.32.0", "@typescript-eslint/types": "8.32.0", @@ -2939,7 +2936,6 @@ "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3393,7 +3389,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.11.23", "caniuse-lite": "^1.0.30001810", @@ -4826,7 +4821,6 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -6382,8 +6376,7 @@ "version": "0.24.8", "resolved": "https://registry.npmjs.org/graphology-types/-/graphology-types-0.24.8.tgz", "integrity": "sha512-hDRKYXa8TsoZHjgEaysSRyPdT6uB78Ci8WnjgbStlQysz7xR52PInxNsmnB7IBOM1BhikxkNyCVEFgmPKnpx3Q==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/graphology-utils": { "version": "2.5.2", @@ -7473,7 +7466,6 @@ "integrity": "sha512-ek8NRg/OPvS9ISOJNWNAz5vZcpYacWNFDWNJjj5OXsc6YuKacfey6wF04cXz/tOJIVrZ2nGSkHpAY5qKtF6ISg==", "dev": true, "license": "ISC", - "peer": true, "dependencies": { "d": "^1.0.2", "duration": "^0.2.2", @@ -10058,7 +10050,6 @@ "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -10265,7 +10256,6 @@ "integrity": "sha512-gK5GVzDkJK1SI1zwHf32Mqxf2tSJkNx+eYcNly5+nHvWqXUJYUkWBQtKauoESz3ymezAI++ZwT855x5p5eop+Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "~0.25.0", "get-tsconfig": "^4.7.5" @@ -10416,7 +10406,6 @@ "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -10726,7 +10715,6 @@ "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, diff --git a/package.json b/package.json index c540b275..e8bc8bae 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ }, "dependencies": { "@abstractplay/recranks": "1.0.0-ci-42691185522.0", - "@abstractplay/renderer": "1.0.0-ci-41714483652.0", + "@abstractplay/renderer": "1.0.0-ci-43630834489.0", "@turf/boolean-contains": "^6.5.0", "@turf/boolean-intersects": "^6.5.0", "@turf/boolean-point-in-polygon": "^6.5.0", diff --git a/src/games/polypods.ts b/src/games/polypods.ts new file mode 100644 index 00000000..4480602d --- /dev/null +++ b/src/games/polypods.ts @@ -0,0 +1,485 @@ + +import { GameBase, IAPGameState, IClickResult, IIndividualState, IScores, IValidationResult } from "./_base.js"; +import type { APGamesInformation } from "../schemas/gameinfo.js"; +import { APRenderRep } from "@abstractplay/renderer/build/schemas/schema"; +import type { APMoveResult } from "../schemas/moveresults.js"; +import { reviver, UserFacingError, cloneState } from "../common/index.js"; +import i18next from "i18next"; +import { IGraph, SnubSquareGraph } from "../common/graphs/index.js"; + +export const gameApgamesEn = { + validation: { + DISCONNECTEDMOVE: "A move from {{from}} to {{to}} would disconnect the band.", + DISCONNECTEDPLACE: "Placing a piece at {{where}} would disconnect the band.", + INITIAL_INSTRUCTIONS: "Place a piece on an empty space connected to the other pieces.", + INVALIDPASS: "You cannot pass while you have pieces in hand.", + MOVE2CONTROLLED: "You cannot capture your own stacks.", + MOVE2EMPTY: "You cannot move to empty spaces.", + PARTIAL: "It's possible you're trying to move a stack. Provide the destination.", + TOOEARLY: "You cannot move until the first player has placed two pieces.", + TOOEARLY_libre: "You cannot move until four stones have been placed on the board.", + TOOFAR: "You can only move to an adjacent cell. {{to}} is not adjacent to {{from}}.", + TOOHIGH: "Moving from {{from}} to {{to}} would result in a stack taller than three pieces high.", + TRIPLESTACK: "You cannot move triple stacks.", + }, + variants: { + "size-6": { + name: "6x6 board", + }, + "size-7": { + name: "7x7 board", + }, + "#size": { + name: "8x8 board", + }, + "size-9": { + name: "9x9 board", + }, + "size-10": { + name: "10x10 board", + }, + "size-11": { + name: "11x11 board", + }, + "size-12": { + name: "12x12 board", + }, + "#variant": { + description: "Directly attacked feet leave permanent remains.", + name: "Polypods Base Game" + }, + "Stoney-footed": { + description: "All removed feet leave permanent remains.", + name: "Stoney-footed Polypods" + }, + "Energized": { + description: "Eating remains gives a double move.", + name: "Energized Polypods" + }, + "Scavenging": { + description: "Every removed piece leaves remains. Placing next to (or on) a remains marker eats one, but a move that eats can't also attack.", + name: "Scavenging Polypods" + }, + }, +}; + + +export type playerid = 1|2; +export type piecetype = "core"|"foot"; +export type cellcontent = { + player: playerid, + type: piecetype +}; +export type board = Map; + +export interface IMoveState extends IIndividualState { + currplayer: playerid; + board: board; + lastmove?: string; +}; + +export interface IPolypodsState extends IAPGameState { + winner: playerid[]; + stack: Array; +}; + +export class PolypodsGame extends GameBase { + public static readonly gameinfo: APGamesInformation = { + name: "Polypods", + uid: "polypods", + playercounts: [2], + version: "20261111", + dateAdded: "2026-11-11", + description: "Polypods are creatures of the snub-square grid. They are composed of connected pieces of 2 types: core and feet. Feet are the extremities, i.e. the pieces with only one similarly-colored adjacent piece, or with exactly 2 that fill the other points of a small triangle of the grid. Core are the other pieces that connect all the feet together. Cores are toxic to the feet of adjacent opponent polypods. Polypods need to have at least as many feet as cores to stay alive. The game of Polypods is about growing and protecting polypods of your colour so that you have the most polypod cores when the game ends. Some removed pieces leave remains. Variants differ in when exactly remains are generated, and how they affect further play.", + urls: [ + "https://boardgamegeek.com/boardgame/466344/polypods" + ], + bggid: "466344", + people: [ + { + type: "designer", + name: "Dale Walton", + urls: ["https://boardgamegeek.com/boardgamedesigner/1988/dale-walton"], + apid: "1f26a119-d9a4-4ff1-bbc7-ec599c07ea1e", + }, + { + type: "coder", + name: "hoembla", + urls: [], + apid: "36926ace-08c0-417d-89ec-15346119abf2", + }, + ], + variants: [ + { + uid: "size-6", + group: "size" + }, + { + uid: "size-7", + group: "size" + }, + { uid: "#size" }, + { + uid: "size-9", + group: "size" + }, + { + uid: "size-10", + group: "size" + }, + { + uid: "size-11", + group: "size" + }, + { + uid: "size-12", + group: "size" + }, + { uid: "#variant" }, + { + uid: "Stoney-footed", + group: "variant", + }, + { + uid: "Energized", + group: "variant", + }, + { + uid: "Scavenging", + group: "variant", + }, + + ], + categories: ["goal>score>eog", "mechanic>place", "board>shape>rect", "board>connect>snub"], + flags: ["scores", "experimental"] + }; + + public numplayers = 2; + public currplayer: playerid = 1; + public board!: board; + public boardsize = 8; + public graph: IGraph = this.getGraph(); + public gameover = false; + public winner: playerid[] = []; + public variants: string[] = []; + public stack!: Array; + public results: Array = []; + + public applyVariants(variants?: string[]) { + this.variants = (variants !== undefined) ? [...variants] : []; + for(const v of this.variants) { + if(v.startsWith("size")) { + const [,size] = v.split("-"); + this.boardsize = parseInt(size, 10); + this.graph = this.getGraph(); + } + } + } + + constructor(state?: IPolypodsState | string, variants?: string[]) { + super(); + + if (state === undefined) { + this.applyVariants(variants); + const fresh: IMoveState = { + _version: PolypodsGame.gameinfo.version, + _results: [], + _timestamp: new Date(), + currplayer: 1, + board: new Map(), + }; + this.stack = [fresh]; + + } else { + if (typeof state === "string") { + state = JSON.parse(state, reviver) as IPolypodsState; + } + if (state.game !== PolypodsGame.gameinfo.uid) { + throw new Error(`The Polypods engine cannot process a game of '${state.game}'.`); + } + this.gameover = state.gameover; + this.winner = [...state.winner]; + this.applyVariants(state.variants); + this.stack = [...state.stack]; + } + this.load(); + } + + public load(idx = -1): PolypodsGame { + if (idx < 0) { + idx += this.stack.length; + } + if ( (idx < 0) || (idx >= this.stack.length) ) { + throw new Error("Could not load the requested state from the stack."); + } + + const state = this.stack[idx]; + + this.currplayer = state.currplayer; + this.board = cloneState(state.board) as board; + this.lastmove = state.lastmove; + return this; + } + + public otherPlayer(): playerid { + return this.currplayer === 1 ? 2 : 1; + } + + private getGraph(): IGraph { + return new SnubSquareGraph(this.boardsize, this.boardsize, "T"); + } + + private updatePolypods(board: board): board { + /* Update the */ + return board; + } + + public moves(player?: playerid): string[] { + if (this.gameover) { return []; } + if (player === undefined) { + player = this.currplayer; + } + + const moves = (this.graph.listCells() as string[]).filter((c) => (!this.board.has(c))); + moves.push("pass"); + + return moves; + } + + public handleClick(move: string, row: number, col: number, piece?: string): IClickResult { + try { + let move = ""; + // normal play + const cell = this.graph.coords2algebraic(col, row); + if (move.length === 0) { + move = cell; + } + + const result = this.validateMove(move) as IClickResult; + if (! result.valid) { + result.move = ""; + } else { + result.move = move; + } + return result; + } catch (e) { + return { + move, + valid: false, + message: i18next.t("apgames:validation._general.GENERIC", {move, row, col, piece, emessage: (e as Error).message}) + } + } + } + + public validateMove(m: string): IValidationResult { + const result: IValidationResult = {valid: false, message: i18next.t("apgames:validation._general.DEFAULT_HANDLER")}; + + if (m.length === 0) { + result.valid = true; + result.complete = -1; + result.message = i18next.t("apgames:validation.bricka.INITIAL_INSTRUCTIONS"); + return result; + } + + if (m === "pass") { + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } + + const cell = m; + + if (!this.graph.graph.hasNode(cell)) { + result.valid = false; + result.message = i18next.t("apgames:validation._general.INVALIDCELL", {cell}); + return result; + } + + if (this.board.has(cell)) { + result.valid = false; + result.message = i18next.t("apgames:validation._general.OCCUPIED", {where: cell}); + return result; + } + + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } + + public move(m: string, {trusted = false} = {}): PolypodsGame { + if (this.gameover) { + throw new UserFacingError("MOVES_GAMEOVER", i18next.t("apgames:validation._general.MOVES_GAMEOVER")); + } + m = m.toLowerCase(); + m = m.replace(/\s+/g, ""); + + if (! trusted) { + const result = this.validateMove(m); + if (! result.valid) { + throw new UserFacingError("VALIDATION_GENERAL", result.message) + } + if (! this.moves().includes(m)) { + throw new UserFacingError("VALIDATION_FAILSAFE", i18next.t("apgames:validation._general.FAILSAFE", {move: m})) + } + } + + this.results = []; + if (m === "pass") { + this.results.push({type: "pass"}); + } else { + // placement + this.board.set(m, {player: this.currplayer, type: "foot"}); + this.results.push({type: "place", where: m}); + } + + this.board = this.updatePolypods(this.board); + + // update currplayer + this.lastmove = m; + this.currplayer = this.otherPlayer(); + + this.checkEOG(); + this.saveState(); + return this; + } + + protected checkEOG(): PolypodsGame { + if ( (this.lastmove === "pass") && (this.stack[this.stack.length - 1].lastmove === "pass") ) { + this.gameover = true; + const score1 = this.getPlayerScore(1); + const score2 = this.getPlayerScore(2); + if (score1 > score2) { + this.winner = [1]; + } else if (score1 < score2) { + this.winner = [2]; + } else { + this.winner = [1, 2]; + } + this.results.push( + {type: "eog"}, + {type: "winners", players: [...this.winner]} + ); + } + + return this; + } + + public state(): IPolypodsState { + return { + game: PolypodsGame.gameinfo.uid, + numplayers: this.numplayers, + variants: this.variants, + gameover: this.gameover, + winner: [...this.winner], + stack: [...this.stack] + }; + } + + public moveState(): IMoveState { + return { + _version: PolypodsGame.gameinfo.version, + _results: [...this.results], + _timestamp: new Date(), + currplayer: this.currplayer, + lastmove: this.lastmove, + board: cloneState(this.board) as board + }; + } + + public render(): APRenderRep { + // Build piece string + let pstr = ""; + const cells = this.graph.listCells(true); + for (const row of cells) { + if (pstr.length > 0) { + pstr += "\n"; + } + const pieces: string[] = []; + for (const cell of row) { + if (this.board.has(cell)) { + const c = this.board.get(cell)!; + if (c.player === 1 && c.type === "foot") { + pieces.push("A"); + } else if (c.player === 1 && c.type === "core") { + pieces.push("B"); + } else if (c.player === 2 && c.type === "foot") { + pieces.push("C"); + } else if (c.player === 2 && c.type === "core") { + pieces.push("D"); + } + } else { + pieces.push("-"); + } + } + pstr += pieces.join(","); + } + + // Build rep + const board = { + style: "snubsquare", + snubStart: "T", + width: this.boardsize, + height: this.boardsize, + blocked: [{row: 0, col: 0}], + }; + if (this.boardsize % 2 === 0) { + board.blocked.push({row: this.boardsize-1, col: this.boardsize-1}); + } + const rep: APRenderRep = { + renderer: "stacking-offset", + board, + legend: { + A: { + name: "piece", + colour: 1 + }, + B: { + name: "piece-chariot", + colour: 1 + }, + C: { + name: "piece", + colour: 2 + }, + D: { + name: "piece-chariot", + colour: 2 + } + }, + pieces: pstr + }; + + // Add annotations + if (this.stack[this.stack.length - 1]._results.length > 0) { + rep.annotations = []; + for (const move of this.stack[this.stack.length - 1]._results) { + if (move.type === "place") { + const [x, y] = this.graph.algebraic2coords(move.where!); + rep.annotations.push({type: "enter", targets: [{row: y, col: x}]}); + } + } + if (rep.annotations.length === 0) { + delete rep.annotations; + } + } + + return rep; + } + + public sidebarScores(): IScores[] { + return [ + { name: this.neutralAreaLabel("apgames:status.SCORES"), scores: [this.getPlayerScore(1), this.getPlayerScore(2)] } + ] + } + + public getPlayerScore(player: playerid): number { + let score = [...this.board.values()].filter((c) => (c.player === player && c.type === "core")).length; + return score; + } + + public clone(): PolypodsGame { + return new PolypodsGame(this.serialize()); + } +} From e10bd23bd30a4e603eedb9bdb90d2aaac4412c2f Mon Sep 17 00:00:00 2001 From: th555 Date: Sun, 15 Nov 2026 00:17:40 +0100 Subject: [PATCH 02/16] base game (without markers) --- locales/en/apgames.json | 15 +--- src/games/polypods.ts | 162 ++++++++++++++++++++++++++++++++-------- 2 files changed, 132 insertions(+), 45 deletions(-) diff --git a/locales/en/apgames.json b/locales/en/apgames.json index f18687ea..dfcdccc1 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -2992,18 +2992,9 @@ "PIECE_STRAIGHT_LINE": "A tower shoots a piece over a line of empty hexes!" }, "polypods": { - "DISCONNECTEDMOVE": "A move from {{from}} to {{to}} would disconnect the band.", - "DISCONNECTEDPLACE": "Placing a piece at {{where}} would disconnect the band.", - "INITIAL_INSTRUCTIONS": "Place a piece on an empty space connected to the other pieces.", - "INVALIDPASS": "You cannot pass while you have pieces in hand.", - "MOVE2CONTROLLED": "You cannot capture your own stacks.", - "MOVE2EMPTY": "You cannot move to empty spaces.", - "PARTIAL": "It's possible you're trying to move a stack. Provide the destination.", - "TOOEARLY": "You cannot move until the first player has placed two pieces.", - "TOOEARLY_libre": "You cannot move until four stones have been placed on the board.", - "TOOFAR": "You can only move to an adjacent cell. {{to}} is not adjacent to {{from}}.", - "TOOHIGH": "Moving from {{from}} to {{to}} would result in a stack taller than three pieces high.", - "TRIPLESTACK": "You cannot move triple stacks." + "INITIAL_INSTRUCTIONS": "Place a piece on an empty space.", + "DEADPOLYPOD": "Invalid placement: the resulting polypod would have more cores than feet.", + "ENEMYCORE": "You may not place next to an opponent core." }, "pontedd": { "BAD_BRIDGE_BLOCKED": "There may be no tiles under the bridge.", diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 4480602d..a39a9a8c 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -5,22 +5,14 @@ import { APRenderRep } from "@abstractplay/renderer/build/schemas/schema"; import type { APMoveResult } from "../schemas/moveresults.js"; import { reviver, UserFacingError, cloneState } from "../common/index.js"; import i18next from "i18next"; +import { dfsFromNode } from 'graphology-traversal'; import { IGraph, SnubSquareGraph } from "../common/graphs/index.js"; export const gameApgamesEn = { validation: { - DISCONNECTEDMOVE: "A move from {{from}} to {{to}} would disconnect the band.", - DISCONNECTEDPLACE: "Placing a piece at {{where}} would disconnect the band.", - INITIAL_INSTRUCTIONS: "Place a piece on an empty space connected to the other pieces.", - INVALIDPASS: "You cannot pass while you have pieces in hand.", - MOVE2CONTROLLED: "You cannot capture your own stacks.", - MOVE2EMPTY: "You cannot move to empty spaces.", - PARTIAL: "It's possible you're trying to move a stack. Provide the destination.", - TOOEARLY: "You cannot move until the first player has placed two pieces.", - TOOEARLY_libre: "You cannot move until four stones have been placed on the board.", - TOOFAR: "You can only move to an adjacent cell. {{to}} is not adjacent to {{from}}.", - TOOHIGH: "Moving from {{from}} to {{to}} would result in a stack taller than three pieces high.", - TRIPLESTACK: "You cannot move triple stacks.", + INITIAL_INSTRUCTIONS: "Place a piece on an empty space.", + DEADPOLYPOD: "Invalid placement: the resulting polypod would have more cores than feet.", + ENEMYCORE: "You may not place next to an opponent core.", }, variants: { "size-6": { @@ -151,7 +143,7 @@ export class PolypodsGame extends GameBase { ], categories: ["goal>score>eog", "mechanic>place", "board>shape>rect", "board>connect>snub"], - flags: ["scores", "experimental"] + flags: ["scores", "no-moves", "experimental"] }; public numplayers = 2; @@ -226,24 +218,103 @@ export class PolypodsGame extends GameBase { } private getGraph(): IGraph { - return new SnubSquareGraph(this.boardsize, this.boardsize, "T"); + const graph = new SnubSquareGraph(this.boardsize, this.boardsize, "T"); + graph.graph.dropNode(graph.coords2algebraic(0, 0)); + if (this.boardsize % 2 === 0) { + graph.graph.dropNode(graph.coords2algebraic(this.boardsize-1, this.boardsize-1)); + } + return graph; } private updatePolypods(board: board): board { - /* Update the */ - return board; + /* Set the pieces to feet or core depending on friendly connectivity */ + const newBoard = cloneState(board) as board; + newBoard.forEach((piece, cell) => { + const neighbours = this.graph.neighbours(cell).filter((cell) => ( + newBoard.has(cell) && newBoard.get(cell)!.player === piece.player)); + if (neighbours.length <= 1) { + piece.type = "foot"; + } else if (neighbours.length === 2) { + // In this case have to check if it's a small triangle + if (this.graph.graph.hasEdge(neighbours[0], neighbours[1])) { + piece.type = "foot"; + } else { + piece.type = "core"; + } + } else { + piece.type = "core"; + } + }); + return newBoard; } - public moves(player?: playerid): string[] { - if (this.gameover) { return []; } - if (player === undefined) { - player = this.currplayer; + private polypodAt(board: board, startCell: string): Set { + /* Return the polypod that includes the given cell */ + const polypod = new Set(); + if (!board.has(startCell)) { + return polypod; + } else { + const thisPlayer = board.get(startCell)!.player; + dfsFromNode(this.graph.graph, startCell, (c) => { + if (board.has(c) && board.get(c)!.player === thisPlayer ) { + polypod.add(c); + return false; + } else { + return true; + } + }); + } + return polypod; + } + + private allPolypods(board: board): Set[] { + /* Return an array of all polypods */ + const polypods: Set[] = []; + const tmpBoard = new Map(board); + while (tmpBoard.size >= 0) { + const anyCell = tmpBoard.keys().next().value; + if (anyCell === undefined) { break; } + const polypod = this.polypodAt(board, anyCell); + polypods.push(polypod); + polypod.forEach((c) => {tmpBoard.delete(c)}); } + return polypods; + } + + private polypodAlive(board: board, polypod: Set): boolean { + /* Check if a polypod is alive i.e. has at least as many feet as cores */ + const cores = [...polypod].filter((c) => (board.get(c)!.type === "core")).length; + const feet = [...polypod].filter((c) => (board.get(c)!.type === "foot")).length; + return feet >= cores; + } - const moves = (this.graph.listCells() as string[]).filter((c) => (!this.board.has(c))); - moves.push("pass"); + private removeDeadPolypods(board: board): board { + /* Remove polypods that have more cores than feet */ + const newBoard = cloneState(board) as board; + this.allPolypods(newBoard).forEach((polypod) => { + if (!this.polypodAlive(newBoard, polypod)) { + polypod.forEach((c) => { + newBoard.delete(c); + }); + } + }); + return newBoard + } - return moves; + private attackFeet(board: board): board { + /* Remove any feet which are next to enemy cores */ + const newBoard = cloneState(board) as board; + board.forEach((footPiece, footCell) => { + if (footPiece.type === "foot") { + for (const nb of this.graph.neighbours(footCell)) { + if (board.has(nb) && board.get(nb)!.type === "core" + && board.get(nb)!.player !== footPiece.player){ + newBoard.delete(footCell); + } + } + } + }); + return newBoard; } public handleClick(move: string, row: number, col: number, piece?: string): IClickResult { @@ -277,7 +348,7 @@ export class PolypodsGame extends GameBase { if (m.length === 0) { result.valid = true; result.complete = -1; - result.message = i18next.t("apgames:validation.bricka.INITIAL_INSTRUCTIONS"); + result.message = i18next.t("apgames:validation.polypods.INITIAL_INSTRUCTIONS"); return result; } @@ -302,6 +373,26 @@ export class PolypodsGame extends GameBase { return result; } + // Check placement is not next to enemy core + for( const c of this.graph.neighbours(cell)) { + const nb = this.board.get(c); + if (nb != undefined && nb.player === this.otherPlayer() && nb.type === "core") { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.ENEMYCORE", {where: cell}); + return result; + } + } + + // Check that the grown polypod is still alive + let boardAfter = cloneState(this.board) as board; + boardAfter.set(cell, {player: this.currplayer, type: "foot"}); + boardAfter = this.updatePolypods(boardAfter); + if (!this.polypodAlive(boardAfter, this.polypodAt(boardAfter, cell))) { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.DEADPOLYPOD", {where: cell}); + return result; + } + result.valid = true; result.complete = 1; result.message = i18next.t("apgames:validation._general.VALID_MOVE"); @@ -320,9 +411,6 @@ export class PolypodsGame extends GameBase { if (! result.valid) { throw new UserFacingError("VALIDATION_GENERAL", result.message) } - if (! this.moves().includes(m)) { - throw new UserFacingError("VALIDATION_FAILSAFE", i18next.t("apgames:validation._general.FAILSAFE", {move: m})) - } } this.results = []; @@ -331,10 +419,14 @@ export class PolypodsGame extends GameBase { } else { // placement this.board.set(m, {player: this.currplayer, type: "foot"}); + this.board = this.updatePolypods(this.board); // First pass to update the attacking polypod + this.board = this.attackFeet(this.board); + this.board = this.updatePolypods(this.board); // Second pass to update any attacked polypods + this.board = this.removeDeadPolypods(this.board); + this.results.push({type: "place", where: m}); } - this.board = this.updatePolypods(this.board); // update currplayer this.lastmove = m; @@ -433,19 +525,23 @@ export class PolypodsGame extends GameBase { legend: { A: { name: "piece", - colour: 1 + colour: 1, + scale: 0.85 }, B: { name: "piece-chariot", - colour: 1 + colour: 1, + scale: 1.2 }, C: { name: "piece", - colour: 2 + colour: 2, + scale: 0.85 }, D: { name: "piece-chariot", - colour: 2 + colour: 2, + scale: 1.2 } }, pieces: pstr @@ -464,7 +560,7 @@ export class PolypodsGame extends GameBase { delete rep.annotations; } } - + console.log("Score:", this.sidebarScores()[0].scores); return rep; } From cce6a9a24c9a748ba60f42598c4efe7c80723b46 Mon Sep 17 00:00:00 2001 From: th555 Date: Sun, 15 Nov 2026 00:39:38 +0100 Subject: [PATCH 03/16] tiebreaker --- src/games/polypods.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index a39a9a8c..0557989b 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -447,7 +447,28 @@ export class PolypodsGame extends GameBase { } else if (score1 < score2) { this.winner = [2]; } else { - this.winner = [1, 2]; + // Tiebreaker: player with most empty spots next to only their pieces + let tie1 = 0; + let tie2 = 0; + for (const cell of this.graph.graph.nodes()) { + if (!this.board.has(cell)) { + const nbPs: Set = new Set(this.graph.neighbours(cell).filter((nb) => ( + this.board.has(nb))).map((nb) => (this.board.get(nb)!.player))); + if (nbPs.has(1) && !nbPs.has(2)) { + tie1++; + } else if (nbPs.has(2) && !nbPs.has(1)) { + tie2++; + } + } + } + console.log("Tiebreaker", tie1, tie2) + if (tie1 > tie2) { + this.winner = [1]; + } else if (tie1 < tie2) { + this.winner = [2]; + } else { + this.winner = [1, 2]; + } } this.results.push( {type: "eog"}, From c12951afd78221eda767e95599969c51adc8ff78 Mon Sep 17 00:00:00 2001 From: th555 Date: Sun, 15 Nov 2026 13:11:05 +0100 Subject: [PATCH 04/16] base game with markers --- src/games/polypods.ts | 48 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 0557989b..836a1595 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -63,10 +63,12 @@ export type cellcontent = { type: piecetype }; export type board = Map; +export type remains = Set; export interface IMoveState extends IIndividualState { currplayer: playerid; board: board; + remains: remains; lastmove?: string; }; @@ -149,6 +151,7 @@ export class PolypodsGame extends GameBase { public numplayers = 2; public currplayer: playerid = 1; public board!: board; + public remains: remains = new Set(); public boardsize = 8; public graph: IGraph = this.getGraph(); public gameover = false; @@ -179,6 +182,7 @@ export class PolypodsGame extends GameBase { _timestamp: new Date(), currplayer: 1, board: new Map(), + remains: new Set, }; this.stack = [fresh]; @@ -209,6 +213,7 @@ export class PolypodsGame extends GameBase { this.currplayer = state.currplayer; this.board = cloneState(state.board) as board; + this.remains = cloneState(state.remains) as remains; this.lastmove = state.lastmove; return this; } @@ -226,6 +231,10 @@ export class PolypodsGame extends GameBase { return graph; } + private isEmpty(cell: string): boolean { + return !this.board.has(cell) && !this.remains.has(cell) + } + private updatePolypods(board: board): board { /* Set the pieces to feet or core depending on friendly connectivity */ const newBoard = cloneState(board) as board; @@ -288,33 +297,37 @@ export class PolypodsGame extends GameBase { return feet >= cores; } - private removeDeadPolypods(board: board): board { + private removeDeadPolypods(board: board): [board, Set] { /* Remove polypods that have more cores than feet */ const newBoard = cloneState(board) as board; + const captured = new Set; this.allPolypods(newBoard).forEach((polypod) => { if (!this.polypodAlive(newBoard, polypod)) { polypod.forEach((c) => { newBoard.delete(c); + captured.add(c); }); } }); - return newBoard + return [newBoard, captured] } - private attackFeet(board: board): board { + private attackFeet(board: board, remains: remains): [board, remains] { /* Remove any feet which are next to enemy cores */ const newBoard = cloneState(board) as board; + const newRemains = cloneState(remains) as remains; board.forEach((footPiece, footCell) => { if (footPiece.type === "foot") { for (const nb of this.graph.neighbours(footCell)) { if (board.has(nb) && board.get(nb)!.type === "core" && board.get(nb)!.player !== footPiece.player){ newBoard.delete(footCell); + newRemains.add(footCell); } } } }); - return newBoard; + return [newBoard, newRemains]; } public handleClick(move: string, row: number, col: number, piece?: string): IClickResult { @@ -367,7 +380,7 @@ export class PolypodsGame extends GameBase { return result; } - if (this.board.has(cell)) { + if (!this.isEmpty(cell)) { result.valid = false; result.message = i18next.t("apgames:validation._general.OCCUPIED", {where: cell}); return result; @@ -420,11 +433,15 @@ export class PolypodsGame extends GameBase { // placement this.board.set(m, {player: this.currplayer, type: "foot"}); this.board = this.updatePolypods(this.board); // First pass to update the attacking polypod - this.board = this.attackFeet(this.board); + [this.board, this.remains] = this.attackFeet(this.board, this.remains); this.board = this.updatePolypods(this.board); // Second pass to update any attacked polypods - this.board = this.removeDeadPolypods(this.board); + let captured: Set; + [this.board, captured] = this.removeDeadPolypods(this.board); this.results.push({type: "place", where: m}); + if (captured.size > 0) { + this.results.push({type: "capture", where: [...captured].join()}); + } } @@ -451,7 +468,7 @@ export class PolypodsGame extends GameBase { let tie1 = 0; let tie2 = 0; for (const cell of this.graph.graph.nodes()) { - if (!this.board.has(cell)) { + if (this.isEmpty(cell)) { const nbPs: Set = new Set(this.graph.neighbours(cell).filter((nb) => ( this.board.has(nb))).map((nb) => (this.board.get(nb)!.player))); if (nbPs.has(1) && !nbPs.has(2)) { @@ -497,7 +514,8 @@ export class PolypodsGame extends GameBase { _timestamp: new Date(), currplayer: this.currplayer, lastmove: this.lastmove, - board: cloneState(this.board) as board + board: cloneState(this.board) as board, + remains: cloneState(this.remains) as remains, }; } @@ -522,6 +540,8 @@ export class PolypodsGame extends GameBase { } else if (c.player === 2 && c.type === "core") { pieces.push("D"); } + } else if (this.remains.has(cell)) { + pieces.push("E"); } else { pieces.push("-"); } @@ -563,6 +583,11 @@ export class PolypodsGame extends GameBase { name: "piece-chariot", colour: 2, scale: 1.2 + }, + E: { + name: "piece", + colour: 3, + scale: 0.5 } }, pieces: pstr @@ -575,6 +600,11 @@ export class PolypodsGame extends GameBase { if (move.type === "place") { const [x, y] = this.graph.algebraic2coords(move.where!); rep.annotations.push({type: "enter", targets: [{row: y, col: x}]}); + } else if (move.type === "capture") { + for (const cell of move.where!.split(",")) { + const [x, y] = this.graph.algebraic2coords(cell); + rep.annotations.push({ type: "exit", targets: [{ row: y, col: x }] }); + } } } if (rep.annotations.length === 0) { From cd59d7ab7eba58415d0b81cd97fab69b8ab05668 Mon Sep 17 00:00:00 2001 From: th555 Date: Sun, 15 Nov 2026 13:48:45 +0100 Subject: [PATCH 05/16] stoney-footed variant --- src/games/polypods.ts | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 836a1595..99076e70 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -40,15 +40,15 @@ export const gameApgamesEn = { description: "Directly attacked feet leave permanent remains.", name: "Polypods Base Game" }, - "Stoney-footed": { + "stoney-footed": { description: "All removed feet leave permanent remains.", name: "Stoney-footed Polypods" }, - "Energized": { + "energized": { description: "Eating remains gives a double move.", name: "Energized Polypods" }, - "Scavenging": { + "scavenging": { description: "Every removed piece leaves remains. Placing next to (or on) a remains marker eats one, but a move that eats can't also attack.", name: "Scavenging Polypods" }, @@ -131,15 +131,15 @@ export class PolypodsGame extends GameBase { }, { uid: "#variant" }, { - uid: "Stoney-footed", + uid: "stoney-footed", group: "variant", }, { - uid: "Energized", + uid: "energized", group: "variant", }, { - uid: "Scavenging", + uid: "scavenging", group: "variant", }, @@ -198,6 +198,7 @@ export class PolypodsGame extends GameBase { this.applyVariants(state.variants); this.stack = [...state.stack]; } + console.log(this.variants); this.load(); } @@ -312,10 +313,11 @@ export class PolypodsGame extends GameBase { return [newBoard, captured] } - private attackFeet(board: board, remains: remains): [board, remains] { + private attackFeet(board: board, remains: remains): [board, remains, Set] { /* Remove any feet which are next to enemy cores */ const newBoard = cloneState(board) as board; const newRemains = cloneState(remains) as remains; + const attacked = new Set; board.forEach((footPiece, footCell) => { if (footPiece.type === "foot") { for (const nb of this.graph.neighbours(footCell)) { @@ -323,11 +325,12 @@ export class PolypodsGame extends GameBase { && board.get(nb)!.player !== footPiece.player){ newBoard.delete(footCell); newRemains.add(footCell); + attacked.add(footCell); } } } }); - return [newBoard, newRemains]; + return [newBoard, newRemains, attacked]; } public handleClick(move: string, row: number, col: number, piece?: string): IClickResult { @@ -431,16 +434,29 @@ export class PolypodsGame extends GameBase { this.results.push({type: "pass"}); } else { // placement + const originalBoard = cloneState(this.board) as board; this.board.set(m, {player: this.currplayer, type: "foot"}); this.board = this.updatePolypods(this.board); // First pass to update the attacking polypod - [this.board, this.remains] = this.attackFeet(this.board, this.remains); + let attacked: Set; + [this.board, this.remains, attacked] = this.attackFeet(this.board, this.remains); this.board = this.updatePolypods(this.board); // Second pass to update any attacked polypods let captured: Set; [this.board, captured] = this.removeDeadPolypods(this.board); + if (this.variants.includes("stoney-footed")) { + /* Stoney-footed: all original feet (before the attack) of a dead polypod get a marker */ + for (const cell of captured) { + const pc = originalBoard.get(cell)!; + if (pc.type === "foot") { + this.remains.add(cell); + } + } + } + this.results.push({type: "place", where: m}); - if (captured.size > 0) { - this.results.push({type: "capture", where: [...captured].join()}); + const allCaptured = [...attacked, ...captured]; + if (allCaptured.length > 0) { + this.results.push({type: "capture", where: allCaptured.join()}); } } @@ -478,7 +494,6 @@ export class PolypodsGame extends GameBase { } } } - console.log("Tiebreaker", tie1, tie2) if (tie1 > tie2) { this.winner = [1]; } else if (tie1 < tie2) { From 4dca5d63b421518658bbc674f408044d0d215c0b Mon Sep 17 00:00:00 2001 From: th555 Date: Sun, 15 Nov 2026 22:24:13 +0100 Subject: [PATCH 06/16] implement Energized polypods variant --- .../en/apresults/apresults-path-map.json | 2 +- locales/en/apgames.json | 11 +- src/games/polypods.ts | 254 +++++++++++++----- 3 files changed, 202 insertions(+), 65 deletions(-) diff --git a/locale-src/en/apresults/apresults-path-map.json b/locale-src/en/apresults/apresults-path-map.json index cab00cb5..7779c7ff 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-14", + "generatedAt": "2026-11-15", "schemaVersion": 1, "entries": [ { diff --git a/locales/en/apgames.json b/locales/en/apgames.json index dfcdccc1..e1c4bba6 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -2994,7 +2994,10 @@ "polypods": { "INITIAL_INSTRUCTIONS": "Place a piece on an empty space.", "DEADPOLYPOD": "Invalid placement: the resulting polypod would have more cores than feet.", - "ENEMYCORE": "You may not place next to an opponent core." + "ENEMYCORE": "You may not place next to an opponent core.", + "NOFOLLOWUP": "Energized Polypods: when eating a remains marker, a valid bonus move must be available next to the same polypod.", + "BONUS": "You must make an additional placement on an empty cell adjacent to the active polypod.", + "MUSTEAT": "The first placement of a multi-action turn must be on a remains marker." }, "pontedd": { "BAD_BRIDGE_BLOCKED": "There may be no tiles under the bridge.", @@ -8150,15 +8153,15 @@ "description": "Directly attacked feet leave permanent remains.", "name": "Polypods Base Game" }, - "Stoney-footed": { + "stoney-footed": { "description": "All removed feet leave permanent remains.", "name": "Stoney-footed Polypods" }, - "Energized": { + "energized": { "description": "Eating remains gives a double move.", "name": "Energized Polypods" }, - "Scavenging": { + "scavenging": { "description": "Every removed piece leaves remains. Placing next to (or on) a remains marker eats one, but a move that eats can't also attack.", "name": "Scavenging Polypods" } diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 99076e70..bb0cbb22 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -13,6 +13,9 @@ export const gameApgamesEn = { INITIAL_INSTRUCTIONS: "Place a piece on an empty space.", DEADPOLYPOD: "Invalid placement: the resulting polypod would have more cores than feet.", ENEMYCORE: "You may not place next to an opponent core.", + NOFOLLOWUP: "Energized Polypods: when eating a remains marker, a valid bonus move must be available next to the same polypod.", + BONUS: "You must make an additional placement on an empty cell adjacent to the active polypod.", + MUSTEAT: "The first placement of a multi-action turn must be on a remains marker." }, variants: { "size-6": { @@ -198,7 +201,6 @@ export class PolypodsGame extends GameBase { this.applyVariants(state.variants); this.stack = [...state.stack]; } - console.log(this.variants); this.load(); } @@ -232,10 +234,6 @@ export class PolypodsGame extends GameBase { return graph; } - private isEmpty(cell: string): boolean { - return !this.board.has(cell) && !this.remains.has(cell) - } - private updatePolypods(board: board): board { /* Set the pieces to feet or core depending on friendly connectivity */ const newBoard = cloneState(board) as board; @@ -298,19 +296,46 @@ export class PolypodsGame extends GameBase { return feet >= cores; } - private removeDeadPolypods(board: board): [board, Set] { + private removeDeadPolypods(board: board, remains: remains, attacked: Set): [board, remains, Set] { /* Remove polypods that have more cores than feet */ const newBoard = cloneState(board) as board; + const newRemains = cloneState(remains) as remains; const captured = new Set; + const capturedFeet = new Set; this.allPolypods(newBoard).forEach((polypod) => { if (!this.polypodAlive(newBoard, polypod)) { polypod.forEach((c) => { newBoard.delete(c); captured.add(c); + if (this.board.get(c)!.type === "foot") { + capturedFeet.add(c); + } }); } }); - return [newBoard, captured] + + if (this.variants.includes("stoney-footed") || this.variants.includes("energized")) { + /* In these variants all removed feet (including downgraded cores from the same turn) + get turned into remains */ + for (const cell of captured) { + if (capturedFeet.has(cell)){ + newRemains.add(cell); + } + } + } + if (this.variants.includes("energized")) { + /* "When a polypod dies, remains must also be added to the dying core locations + that are adjacent to the feet that were initially attacked." */ + for (const attackedFoot of attacked) { + for (const nb of this.graph.neighbours(attackedFoot)) { + if (captured.has(nb) && board.get(nb)!.type === "core") { // The original board! + newRemains.add(nb); + } + } + } + } + + return [newBoard, newRemains, captured]; } private attackFeet(board: board, remains: remains): [board, remains, Set] { @@ -335,18 +360,21 @@ export class PolypodsGame extends GameBase { public handleClick(move: string, row: number, col: number, piece?: string): IClickResult { try { - let move = ""; - // normal play const cell = this.graph.coords2algebraic(col, row); - if (move.length === 0) { - move = cell; + let newmove; + if (move === "") { + newmove = cell; + } else { + newmove = move + ";" + cell; } - - const result = this.validateMove(move) as IClickResult; + const result = this.validateMove(newmove) as IClickResult; if (! result.valid) { - result.move = ""; - } else { result.move = move; + if (move !== "") { + result.canrender = true; + } + } else { + result.move = newmove; } return result; } catch (e) { @@ -358,6 +386,53 @@ export class PolypodsGame extends GameBase { } } + private validPlacement(cell: string, board: board, remains: remains): IValidationResult { + /* Check whether a single placement is valid. Does not check whether a valid followup move + is available for energized polypods. */ + if (!this.graph.graph.hasNode(cell)) { + return {valid: false, message: i18next.t("apgames:validation._general.INVALIDCELL", {cell})}; + } + + /* In the energized variant, you may place on top of a marker under some conditions */ + if (this.variants.includes("energized")) { + if (board.has(cell)) { + return {valid: false, message: i18next.t("apgames:validation._general.OCCUPIED", {where: cell})}; + } + } else if (board.has(cell) || remains.has(cell)) { + return {valid: false, message: i18next.t("apgames:validation._general.OCCUPIED", {where: cell})}; + } + + // Check placement is not next to enemy core + for( const c of this.graph.neighbours(cell)) { + const nb = board.get(c); + if (nb != undefined && nb.player === this.otherPlayer() && nb.type === "core") { + return {valid: false, message: i18next.t("apgames:validation.polypods.ENEMYCORE", {where: cell})}; + } + } + + // Check that the grown polypod is still alive + let boardAfter = cloneState(board) as board; + boardAfter.set(cell, {player: this.currplayer, type: "foot"}); + boardAfter = this.updatePolypods(boardAfter); + if (!this.polypodAlive(boardAfter, this.polypodAt(boardAfter, cell))) { + return {valid: false, message: i18next.t("apgames:validation.polypods.DEADPOLYPOD", {where: cell})}; + } + + return {valid: true, message: i18next.t("apgames:validation._general.VALID_MOVE")}; + } + + private isValidBonusMove(cell: string, board: board, remains: remains): boolean { + /* Note, does not check that the move is adjacent to the active polypod, this must be checked + separately */ + if (!(board.has(cell) || remains.has(cell))) { + const bonusResult = this.validPlacement(cell, board, remains); + if (bonusResult.valid) { + return true; + } + } + return false; + } + public validateMove(m: string): IValidationResult { const result: IValidationResult = {valid: false, message: i18next.t("apgames:validation._general.DEFAULT_HANDLER")}; @@ -375,47 +450,101 @@ export class PolypodsGame extends GameBase { return result; } - const cell = m; - - if (!this.graph.graph.hasNode(cell)) { + const moves = m.split(";"); + if (moves.length === 2 && this.variants.includes("energized")) { + /* First move must consume a marker */ + const firstResult = this.validateMove(moves[0]); + if (firstResult.valid === false) { + return firstResult; + }; + if (firstResult.complete !== -1) { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.MUSTEAT"); + return result; + } + /* First move is valid so now validate the 2nd (bonus) move */ + const [boardAfter, remainsAfter] = this.applyMove(moves[0], this.board, this.remains); + const activePolypod = this.polypodAt(boardAfter, moves[0]); + const adjacentCells = new Set; + for (const cell of activePolypod) { + for (const nb of this.graph.neighbours(cell)) { + if (!activePolypod.has(nb)) { + adjacentCells.add(nb); + } + } + } + if (this.isValidBonusMove(moves[1], boardAfter, remainsAfter) && adjacentCells.has(moves[1])) { + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } else { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.BONUS"); + return result; + } + } else if (moves.length !== 1) { result.valid = false; - result.message = i18next.t("apgames:validation._general.INVALIDCELL", {cell}); + result.message = i18next.t("apgames:validation._general.INVALID_MOVE"); return result; } - if (!this.isEmpty(cell)) { - result.valid = false; - result.message = i18next.t("apgames:validation._general.OCCUPIED", {where: cell}); - return result; + const cell = m; + + const placeResult = this.validPlacement(cell, this.board, this.remains); + if (!placeResult.valid) { + return placeResult; } - // Check placement is not next to enemy core - for( const c of this.graph.neighbours(cell)) { - const nb = this.board.get(c); - if (nb != undefined && nb.player === this.otherPlayer() && nb.type === "core") { + if (this.variants.includes("energized") && this.remains.has(cell)) { + // This move energizes the piece, check that a valid followup move is available + const [boardAfter, remainsAfter] = this.applyMove(cell, this.board, this.remains); + + const polypod = this.polypodAt(boardAfter, cell); + let validBonusMove = false; + for (const cell of polypod) { + for (const nb of this.graph.neighbours(cell)) { + if (this.isValidBonusMove(nb, boardAfter, remainsAfter)) { + validBonusMove = true; + break; + } + } + if (validBonusMove) { break; } + } + + if (!validBonusMove) { result.valid = false; - result.message = i18next.t("apgames:validation.polypods.ENEMYCORE", {where: cell}); + result.message = i18next.t("apgames:validation.polypods.NOFOLLOWUP"); + return result; + } else { + result.valid = true; + result.message = i18next.t("apgames:validation.polypods.BONUS"); + result.complete = -1; + result.canrender = true; return result; } } - // Check that the grown polypod is still alive - let boardAfter = cloneState(this.board) as board; - boardAfter.set(cell, {player: this.currplayer, type: "foot"}); - boardAfter = this.updatePolypods(boardAfter); - if (!this.polypodAlive(boardAfter, this.polypodAt(boardAfter, cell))) { - result.valid = false; - result.message = i18next.t("apgames:validation.polypods.DEADPOLYPOD", {where: cell}); - return result; - } - result.valid = true; result.complete = 1; result.message = i18next.t("apgames:validation._general.VALID_MOVE"); return result; } - public move(m: string, {trusted = false} = {}): PolypodsGame { + private applyMove(cell: string, board: board, remains: remains): [board, remains, Set, Set] { + let newBoard = cloneState(board) as board; + newBoard.set(cell, {player: this.currplayer, type: "foot"}); + newBoard = this.updatePolypods(newBoard); + let newRemains: remains + let attacked: Set; + [newBoard, newRemains, attacked] = this.attackFeet(newBoard, remains); + newBoard = this.updatePolypods(newBoard); + let captured: Set; + [newBoard, newRemains, captured] = this.removeDeadPolypods(newBoard, newRemains, attacked); + return [newBoard, newRemains, attacked, captured]; + } + + public move(m: string, {partial = false, trusted = false} = {}): PolypodsGame { if (this.gameover) { throw new UserFacingError("MOVES_GAMEOVER", i18next.t("apgames:validation._general.MOVES_GAMEOVER")); } @@ -433,27 +562,26 @@ export class PolypodsGame extends GameBase { if (m === "pass") { this.results.push({type: "pass"}); } else { - // placement - const originalBoard = cloneState(this.board) as board; - this.board.set(m, {player: this.currplayer, type: "foot"}); - this.board = this.updatePolypods(this.board); // First pass to update the attacking polypod let attacked: Set; - [this.board, this.remains, attacked] = this.attackFeet(this.board, this.remains); - this.board = this.updatePolypods(this.board); // Second pass to update any attacked polypods let captured: Set; - [this.board, captured] = this.removeDeadPolypods(this.board); - - if (this.variants.includes("stoney-footed")) { - /* Stoney-footed: all original feet (before the attack) of a dead polypod get a marker */ - for (const cell of captured) { - const pc = originalBoard.get(cell)!; - if (pc.type === "foot") { - this.remains.add(cell); - } - } + const moves = m.split(";"); + if (moves.length === 2) { + // energized double-move + const [board1, remains1, attacked1, captured1] = this.applyMove(moves[0], this.board, this.remains); + remains1.delete(moves[0]); + let attacked2; + let captured2; + [this.board, this.remains, attacked2, captured2] = this.applyMove(moves[1], board1, remains1); + attacked = new Set([...attacked1, ...attacked2]); + captured = new Set([...captured1, ...captured2]); + } else { + // single placement + [this.board, this.remains, attacked, captured] = this.applyMove(m, this.board, this.remains); } - this.results.push({type: "place", where: m}); + if (partial) { return this; } + + this.results.push({type: "place", where: m.replace(";", ",")}); const allCaptured = [...attacked, ...captured]; if (allCaptured.length > 0) { this.results.push({type: "capture", where: allCaptured.join()}); @@ -484,7 +612,7 @@ export class PolypodsGame extends GameBase { let tie1 = 0; let tie2 = 0; for (const cell of this.graph.graph.nodes()) { - if (this.isEmpty(cell)) { + if (!this.board.has(cell) && !this.remains.has(cell)) { const nbPs: Set = new Set(this.graph.neighbours(cell).filter((nb) => ( this.board.has(nb))).map((nb) => (this.board.get(nb)!.player))); if (nbPs.has(1) && !nbPs.has(2)) { @@ -555,6 +683,10 @@ export class PolypodsGame extends GameBase { } else if (c.player === 2 && c.type === "core") { pieces.push("D"); } + if (this.variants.includes("energized") && this.remains.has(cell)) { + // Mark the energized piece by stacking a marker on top + pieces[pieces.length - 1] += "E"; + } } else if (this.remains.has(cell)) { pieces.push("E"); } else { @@ -613,12 +745,14 @@ export class PolypodsGame extends GameBase { rep.annotations = []; for (const move of this.stack[this.stack.length - 1]._results) { if (move.type === "place") { - const [x, y] = this.graph.algebraic2coords(move.where!); - rep.annotations.push({type: "enter", targets: [{row: y, col: x}]}); + for (const movePart of move.where!.split(",")) { + const [x, y] = this.graph.algebraic2coords(movePart); + rep.annotations.push({type: "enter", shape: "circle", opacity: 0.5, targets: [{row: y, col: x}]}); + } } else if (move.type === "capture") { for (const cell of move.where!.split(",")) { const [x, y] = this.graph.algebraic2coords(cell); - rep.annotations.push({ type: "exit", targets: [{ row: y, col: x }] }); + rep.annotations.push({ type: "exit", shape: "circle", opacity: 0.5, targets: [{ row: y, col: x }] }); } } } From 72f0772106723e723b3cd15f34f1a2ac8f2318d3 Mon Sep 17 00:00:00 2001 From: th555 Date: Tue, 17 Nov 2026 14:16:49 +0100 Subject: [PATCH 07/16] implemenet scavenging polypods and more elaborate turn annotations --- .../en/apresults/apresults-path-map.json | 2 +- locales/en/apgames.json | 11 +- src/games/polypods.ts | 167 ++++++++++++++++-- 3 files changed, 159 insertions(+), 21 deletions(-) diff --git a/locale-src/en/apresults/apresults-path-map.json b/locale-src/en/apresults/apresults-path-map.json index 7779c7ff..b607f181 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-15", + "generatedAt": "2026-11-17", "schemaVersion": 1, "entries": [ { diff --git a/locales/en/apgames.json b/locales/en/apgames.json index e1c4bba6..a2566c63 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -2996,8 +2996,15 @@ "DEADPOLYPOD": "Invalid placement: the resulting polypod would have more cores than feet.", "ENEMYCORE": "You may not place next to an opponent core.", "NOFOLLOWUP": "Energized Polypods: when eating a remains marker, a valid bonus move must be available next to the same polypod.", - "BONUS": "You must make an additional placement on an empty cell adjacent to the active polypod.", - "MUSTEAT": "The first placement of a multi-action turn must be on a remains marker." + "BONUS": "Energized: you must make an additional placement on an empty cell adjacent to the active polypod.", + "BONUS_INVALID": "Not a valid second action: ", + "BONUSNOREMAINS": "The second placement of a multi-action turn may not be on a remains marker.", + "BONUS_NOT_ADJACENT": "The second placement of must be adjacent to the active polypod.", + "MUSTEAT": "The first placement of a multi-action turn must be on a remains marker.", + "SCAVENGING_MARKER": "Scavenging: you may only place on a remains marker if no attack would occur.", + "SELECTREMAINS": "Scavenging: after a non-attacking move, select an adjacent remains marker to remove (if available).", + "SELECTREMAINSINVALID": "Scavenging: you must select one of the remains markers adjacent to the placed piece.", + "SCAVENGEDOUBLE": "Scavenging: a double move can only happen when not attacking, and then eating an adjacent remains marker." }, "pontedd": { "BAD_BRIDGE_BLOCKED": "There may be no tiles under the bridge.", diff --git a/src/games/polypods.ts b/src/games/polypods.ts index bb0cbb22..473da5f9 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -14,8 +14,15 @@ export const gameApgamesEn = { DEADPOLYPOD: "Invalid placement: the resulting polypod would have more cores than feet.", ENEMYCORE: "You may not place next to an opponent core.", NOFOLLOWUP: "Energized Polypods: when eating a remains marker, a valid bonus move must be available next to the same polypod.", - BONUS: "You must make an additional placement on an empty cell adjacent to the active polypod.", - MUSTEAT: "The first placement of a multi-action turn must be on a remains marker." + BONUS: "Energized: you must make an additional placement on an empty cell adjacent to the active polypod.", + BONUS_INVALID: "Not a valid second action: ", + BONUSNOREMAINS: "The second placement of a multi-action turn may not be on a remains marker.", + BONUS_NOT_ADJACENT: "The second placement of must be adjacent to the active polypod.", + MUSTEAT: "The first placement of a multi-action turn must be on a remains marker.", + SCAVENGING_MARKER: "Scavenging: you may only place on a remains marker if no attack would occur.", + SELECTREMAINS: "Scavenging: after a non-attacking move, select an adjacent remains marker to remove (if available).", + SELECTREMAINSINVALID: "Scavenging: you must select one of the remains markers adjacent to the placed piece.", + SCAVENGEDOUBLE: "Scavenging: a double move can only happen when not attacking, and then eating an adjacent remains marker." }, variants: { "size-6": { @@ -299,7 +306,7 @@ export class PolypodsGame extends GameBase { private removeDeadPolypods(board: board, remains: remains, attacked: Set): [board, remains, Set] { /* Remove polypods that have more cores than feet */ const newBoard = cloneState(board) as board; - const newRemains = cloneState(remains) as remains; + let newRemains = cloneState(remains) as remains; const captured = new Set; const capturedFeet = new Set; this.allPolypods(newBoard).forEach((polypod) => { @@ -334,6 +341,11 @@ export class PolypodsGame extends GameBase { } } } + if (this.variants.includes("scavenging")) { + /* In this variant all removed pieces are converted to remains */ + newRemains = new Set([...newRemains, ...captured]); + } + return [newBoard, newRemains, captured]; } @@ -367,7 +379,21 @@ export class PolypodsGame extends GameBase { } else { newmove = move + ";" + cell; } - const result = this.validateMove(newmove) as IClickResult; + let result = this.validateMove(newmove) as IClickResult; + /* Special case: in the scavenging variant, if a remains marker must be selected + and there is exactly 1 available, automatically select it */ + if (!newmove.includes(";") && this.variants.includes("scavenging") && result.complete === -1) { + let adjRemains: string[] = []; + for (const nb of this.graph.neighbours(cell)) { + if (this.remains.has(nb)) { + adjRemains.push(nb); + } + } + if (adjRemains.length === 1) { + newmove += ";" + adjRemains[0]; + result = this.validateMove(newmove) as IClickResult; + } + } if (! result.valid) { result.move = move; if (move !== "") { @@ -398,7 +424,8 @@ export class PolypodsGame extends GameBase { if (board.has(cell)) { return {valid: false, message: i18next.t("apgames:validation._general.OCCUPIED", {where: cell})}; } - } else if (board.has(cell) || remains.has(cell)) { + } else if (board.has(cell) || (remains.has(cell) && !this.variants.includes("scavenging"))) { + // In scavenging a placement may be on a remains under some conditions, this will be checked separately return {valid: false, message: i18next.t("apgames:validation._general.OCCUPIED", {where: cell})}; } @@ -421,16 +448,17 @@ export class PolypodsGame extends GameBase { return {valid: true, message: i18next.t("apgames:validation._general.VALID_MOVE")}; } - private isValidBonusMove(cell: string, board: board, remains: remains): boolean { + private isValidBonusMove(cell: string, board: board, remains: remains): IValidationResult { /* Note, does not check that the move is adjacent to the active polypod, this must be checked separately */ if (!(board.has(cell) || remains.has(cell))) { const bonusResult = this.validPlacement(cell, board, remains); - if (bonusResult.valid) { - return true; - } + return bonusResult + } else if (remains.has(cell)) { + return {valid: false, message: i18next.t("apgames:validation.polypods.BONUSNOREMAINS")}; + } else { + return {valid: false, message: i18next.t("apgames:validation._general.OCCUPIED", {where: cell})}; } - return false; } public validateMove(m: string): IValidationResult { @@ -473,17 +501,44 @@ export class PolypodsGame extends GameBase { } } } - if (this.isValidBonusMove(moves[1], boardAfter, remainsAfter) && adjacentCells.has(moves[1])) { + const bonusResult = this.isValidBonusMove(moves[1], boardAfter, remainsAfter); + if (bonusResult.valid && adjacentCells.has(moves[1])) { result.valid = true; result.complete = 1; result.message = i18next.t("apgames:validation._general.VALID_MOVE"); return result; + } else if (!adjacentCells.has(moves[1])) { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.BONUS_NOT_ADJACENT"); + return result; } else { result.valid = false; - result.message = i18next.t("apgames:validation.polypods.BONUS"); + result.message = i18next.t("apgames:validation.polypods.BONUS_INVALID") + bonusResult.message; return result; } - } else if (moves.length !== 1) { + } else if (moves.length === 2 && this.variants.includes("scavenging")) { + /* First move must be on an empty space and not attack */ + const firstResult = this.validateMove(moves[0]); + if (firstResult.valid === false) { + return firstResult; + }; + if (firstResult.complete !== -1) { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.SCAVENGEDOUBLE"); + return result; + } + /* Second action must select an adjacent remains marker */ + if (this.remains.has(moves[1]) && this.graph.graph.hasEdge(moves[0], moves[1])) { + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } else { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.SELECTREMAINSINVALID"); + return result; + } + }else if (moves.length !== 1) { result.valid = false; result.message = i18next.t("apgames:validation._general.INVALID_MOVE"); return result; @@ -525,6 +580,57 @@ export class PolypodsGame extends GameBase { } } + if (this.variants.includes("scavenging")) { + /* Four possibilities: + - Move that doesn't attack and doesn't consume a marker (since none are around) + - Move that doesn't attack and consumes an adjacent marker + - Move that doesn't attack and consumes a marker at its own location + - Move that does attack and does not consume a marker + */ + const attack = this.isAttackingMove(cell); + const onRemains = this.remains.has(cell); + let remainsAround = false; + for (const nb of this.graph.neighbours(cell)) { + if (this.remains.has(nb)) { + remainsAround = true; + break; + } + } + + if (attack) { + if (onRemains) { + result.valid = false; + result.message = i18next.t("apgames:validation.polypods.SCAVENGING_MARKER"); + return result; + } else { + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } + } else { + if (onRemains) { + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } else { + if (remainsAround) { + result.valid = true; + result.complete = -1; + result.canrender = true; + result.message = i18next.t("apgames:validation.polypods.SELECTREMAINS"); + return result; + } else { + result.valid = true; + result.complete = 1; + result.message = i18next.t("apgames:validation._general.VALID_MOVE"); + return result; + } + } + } + } + result.valid = true; result.complete = 1; result.message = i18next.t("apgames:validation._general.VALID_MOVE"); @@ -541,9 +647,20 @@ export class PolypodsGame extends GameBase { newBoard = this.updatePolypods(newBoard); let captured: Set; [newBoard, newRemains, captured] = this.removeDeadPolypods(newBoard, newRemains, attacked); + if (this.variants.includes("scavenging")) { + newRemains.delete(cell); + } return [newBoard, newRemains, attacked, captured]; } + private isAttackingMove(cell: string): boolean { + let newBoard = cloneState(this.board) as board; + newBoard.set(cell, {player: this.currplayer, type: "foot"}); + newBoard = this.updatePolypods(newBoard); + const [_board, _remains, attacked] = this.attackFeet(newBoard, this.remains); + return (attacked.size > 0); + } + public move(m: string, {partial = false, trusted = false} = {}): PolypodsGame { if (this.gameover) { throw new UserFacingError("MOVES_GAMEOVER", i18next.t("apgames:validation._general.MOVES_GAMEOVER")); @@ -559,13 +676,14 @@ export class PolypodsGame extends GameBase { } this.results = []; + let oldBoard: board = cloneState(this.board) as board; if (m === "pass") { this.results.push({type: "pass"}); } else { let attacked: Set; let captured: Set; const moves = m.split(";"); - if (moves.length === 2) { + if (moves.length === 2 && this.variants.includes("energized")) { // energized double-move const [board1, remains1, attacked1, captured1] = this.applyMove(moves[0], this.board, this.remains); remains1.delete(moves[0]); @@ -574,6 +692,10 @@ export class PolypodsGame extends GameBase { [this.board, this.remains, attacked2, captured2] = this.applyMove(moves[1], board1, remains1); attacked = new Set([...attacked1, ...attacked2]); captured = new Set([...captured1, ...captured2]); + } else if (moves.length === 2 && this.variants.includes("scavenging")) { + // Scavenging move that removes a marker + [this.board, this.remains, attacked, captured] = this.applyMove(moves[0], this.board, this.remains); + this.remains.delete(moves[1]); } else { // single placement [this.board, this.remains, attacked, captured] = this.applyMove(m, this.board, this.remains); @@ -582,13 +704,22 @@ export class PolypodsGame extends GameBase { if (partial) { return this; } this.results.push({type: "place", where: m.replace(";", ",")}); + // Annotate feet upgraded to cores, and cores downgraded to feet. + oldBoard.forEach((piece, cell) => { + if (oldBoard.has(cell) && this.board.has(cell)) { + if (oldBoard.get(cell)!.type === "foot" && this.board.get(cell)!.type === "core") { + this.results.push({type: "place", where: cell}); + } else if (oldBoard.get(cell)!.type === "core" && this.board.get(cell)!.type === "foot") { + this.results.push({type: "capture", where: cell}); + } + } + }); const allCaptured = [...attacked, ...captured]; - if (allCaptured.length > 0) { - this.results.push({type: "capture", where: allCaptured.join()}); + for (const cell of allCaptured) { + this.results.push({type: attacked.has(cell) ? "place" : "capture", where: cell}); } } - // update currplayer this.lastmove = m; this.currplayer = this.otherPlayer(); @@ -747,7 +878,7 @@ export class PolypodsGame extends GameBase { if (move.type === "place") { for (const movePart of move.where!.split(",")) { const [x, y] = this.graph.algebraic2coords(movePart); - rep.annotations.push({type: "enter", shape: "circle", opacity: 0.5, targets: [{row: y, col: x}]}); + rep.annotations.push({type: "enter", shape: "circle", opacity: 1.0, targets: [{row: y, col: x}]}); } } else if (move.type === "capture") { for (const cell of move.where!.split(",")) { From 85be789687de70afdea060fbdc9df68c9fcbb121 Mon Sep 17 00:00:00 2001 From: th555 Date: Tue, 17 Nov 2026 14:25:54 +0100 Subject: [PATCH 08/16] make all up/downgrade annotations light --- src/games/polypods.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 473da5f9..a0a76965 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -707,9 +707,7 @@ export class PolypodsGame extends GameBase { // Annotate feet upgraded to cores, and cores downgraded to feet. oldBoard.forEach((piece, cell) => { if (oldBoard.has(cell) && this.board.has(cell)) { - if (oldBoard.get(cell)!.type === "foot" && this.board.get(cell)!.type === "core") { - this.results.push({type: "place", where: cell}); - } else if (oldBoard.get(cell)!.type === "core" && this.board.get(cell)!.type === "foot") { + if (oldBoard.get(cell)!.type !== this.board.get(cell)!.type) { this.results.push({type: "capture", where: cell}); } } From 45cd6b3921536ac37d721ca6c0b941ae2df810a2 Mon Sep 17 00:00:00 2001 From: th555 Date: Tue, 17 Nov 2026 17:25:39 +0100 Subject: [PATCH 09/16] move generation (except scavenging) --- src/games/polypods.ts | 91 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index a0a76965..19a9f15d 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -155,7 +155,7 @@ export class PolypodsGame extends GameBase { ], categories: ["goal>score>eog", "mechanic>place", "board>shape>rect", "board>connect>snub"], - flags: ["scores", "no-moves", "experimental"] + flags: ["scores", "automove", "experimental"] }; public numplayers = 2; @@ -412,6 +412,14 @@ export class PolypodsGame extends GameBase { } } + private polypodAliveAfter(board: board, cell: string): boolean { + /* Check that the grown polypod is still alive */ + let boardAfter = cloneState(board) as board; + boardAfter.set(cell, {player: this.currplayer, type: "foot"}); + boardAfter = this.updatePolypods(boardAfter); + return this.polypodAlive(boardAfter, this.polypodAt(boardAfter, cell)); + } + private validPlacement(cell: string, board: board, remains: remains): IValidationResult { /* Check whether a single placement is valid. Does not check whether a valid followup move is available for energized polypods. */ @@ -437,11 +445,7 @@ export class PolypodsGame extends GameBase { } } - // Check that the grown polypod is still alive - let boardAfter = cloneState(board) as board; - boardAfter.set(cell, {player: this.currplayer, type: "foot"}); - boardAfter = this.updatePolypods(boardAfter); - if (!this.polypodAlive(boardAfter, this.polypodAt(boardAfter, cell))) { + if (!this.polypodAliveAfter(board, cell)) { return {valid: false, message: i18next.t("apgames:validation.polypods.DEADPOLYPOD", {where: cell})}; } @@ -727,6 +731,77 @@ export class PolypodsGame extends GameBase { return this; } + public moves(player?: playerid): string[] { + if (player === undefined) { + player = this.currplayer; + } + if (this.gameover) { return []; } + + const moves: string[] = []; + + const validCells = new Set(this.graph.graph.nodes().filter((c) => ( + !this.board.has(c) && !this.remains.has(c)))); + const nextToEnemyCore = new Set; // These are always disallowed + const nextToFriendlyPiece = new Set; // These must be checked separately for polypod deaths + this.graph.graph.nodes().forEach((cell) => { + if (this.board.has(cell)) { + const piece = this.board.get(cell)!; + if (piece.player === this.otherPlayer() && piece.type === "core") { + for (const nb of this.graph.neighbours(cell)) { + validCells.delete(nb); + nextToEnemyCore.add(nb); + } + } else if (piece.player === this.currplayer) { + for (const nb of this.graph.neighbours(cell)) { + validCells.delete(nb); + nextToFriendlyPiece.add(nb); + } + } + } + }); + + for (const cell of nextToFriendlyPiece) { + if (!this.board.has(cell) && !nextToEnemyCore.has(cell) && !this.remains.has(cell) && this.polypodAliveAfter(this.board, cell)) { + validCells.add(cell); + } + } + + if (this.variants.includes("scavenging")) { + // 1. make sets of all validCells that generate a capture + // 2. if there are remains adjacent, add separate moves for each of them + // 3. if not, add the move plainly + // 4. for each existing remains check if it can be a non-attacking move and add it + } else { + moves.push(...validCells); + } + + if (this.variants.includes("energized")) { + for (const cell of this.remains) { + if (!nextToEnemyCore.has(cell) && this.polypodAliveAfter(this.board, cell)) { + const [boardAfter, remainsAfter] = this.applyMove(cell, this.board, this.remains); + const activePolypod = this.polypodAt(boardAfter, cell); + const adjacentCells = new Set; + for (const cell of activePolypod) { + for (const nb of this.graph.neighbours(cell)) { + if (!activePolypod.has(nb)) { + adjacentCells.add(nb); + } + } + } + for (const adjCell of adjacentCells) { + const bonusResult = this.isValidBonusMove(adjCell, boardAfter, remainsAfter); + if (bonusResult.valid === true) { + moves.push(cell + ";" + adjCell); + } + } + } + } + } + + moves.push("pass"); + return moves; + } + protected checkEOG(): PolypodsGame { if ( (this.lastmove === "pass") && (this.stack[this.stack.length - 1].lastmove === "pass") ) { this.gameover = true; @@ -861,9 +936,9 @@ export class PolypodsGame extends GameBase { scale: 1.2 }, E: { - name: "piece", + name: "piece-borderless", colour: 3, - scale: 0.5 + scale: 0.4 } }, pieces: pstr From 1ec7758d36ae360efd925d80ecbae26e26f97ea5 Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 00:51:51 +0100 Subject: [PATCH 10/16] scavenging move generation --- src/games/polypods.ts | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 19a9f15d..27ad9256 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -383,7 +383,7 @@ export class PolypodsGame extends GameBase { /* Special case: in the scavenging variant, if a remains marker must be selected and there is exactly 1 available, automatically select it */ if (!newmove.includes(";") && this.variants.includes("scavenging") && result.complete === -1) { - let adjRemains: string[] = []; + const adjRemains: string[] = []; for (const nb of this.graph.neighbours(cell)) { if (this.remains.has(nb)) { adjRemains.push(nb); @@ -761,16 +761,61 @@ export class PolypodsGame extends GameBase { }); for (const cell of nextToFriendlyPiece) { - if (!this.board.has(cell) && !nextToEnemyCore.has(cell) && !this.remains.has(cell) && this.polypodAliveAfter(this.board, cell)) { + if (!this.board.has(cell) && !nextToEnemyCore.has(cell) && + !this.remains.has(cell) && this.polypodAliveAfter(this.board, cell)) { validCells.add(cell); } } if (this.variants.includes("scavenging")) { - // 1. make sets of all validCells that generate a capture - // 2. if there are remains adjacent, add separate moves for each of them + // 1. make sets of all cells that generate a capture and that don't + // 2. for non-captures, if there are remains adjacent, add separate moves for each of them // 3. if not, add the move plainly // 4. for each existing remains check if it can be a non-attacking move and add it + + const attacks = new Set(); + const nonAttacks = new Set(); + for (const cell of this.graph.graph.nodes()) { + if (!this.board.has(cell) && !nextToEnemyCore.has(cell) && !this.remains.has(cell) && + this.polypodAliveAfter(this.board, cell)) { + if (nextToFriendlyPiece.has(cell) && this.isAttackingMove(cell)) { + attacks.add(cell); + } else { + nonAttacks.add(cell); + } + } + } + + moves.push(...attacks); + + for (const cell of nonAttacks) { + const adjRemains: string[] = []; + for (const nb of this.graph.neighbours(cell)) { + if (this.remains.has(nb)) { + adjRemains.push(nb); + } + } + if (adjRemains.length === 0) { + moves.push(cell); + } else { + for (const adjCell of adjRemains) { + moves.push(cell + ";" + adjCell); + } + } + } + + for (const cell of this.remains) { + if (!nextToEnemyCore.has(cell) && this.polypodAliveAfter(this.board, cell) + && !this.isAttackingMove(cell)) { + moves.push(cell); + } + } + + for (const cell of validCells) { + if (!attacks.has(cell) && !nonAttacks.has(cell)) { + moves.push(cell); + } + } } else { moves.push(...validCells); } From ff7878fe1ebf8e929ab59a5e03e98bafa4faab51 Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 12:06:11 +0100 Subject: [PATCH 11/16] fix validation bug --- src/games/polypods.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 27ad9256..9c318b26 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -46,6 +46,9 @@ export const gameApgamesEn = { "size-12": { name: "12x12 board", }, + "size-19": { + name: "19x19 board", + }, "#variant": { description: "Directly attacked feet leave permanent remains.", name: "Polypods Base Game" @@ -380,7 +383,7 @@ export class PolypodsGame extends GameBase { newmove = move + ";" + cell; } let result = this.validateMove(newmove) as IClickResult; - /* Special case: in the scavenging variant, if a remains marker must be selected + /* In the scavenging variant, if a remains marker must be selected and there is exactly 1 available, automatically select it */ if (!newmove.includes(";") && this.variants.includes("scavenging") && result.complete === -1) { const adjRemains: string[] = []; @@ -394,6 +397,30 @@ export class PolypodsGame extends GameBase { result = this.validateMove(newmove) as IClickResult; } } + /* In the energized variant, if a bonus move must be selected + and there is exactly 1 available, automatically select it */ + if (!newmove.includes(";") && this.variants.includes("energized") && result.complete === -1) { + const [boardAfter, remainsAfter] = this.applyMove(newmove, this.board, this.remains); + const activePolypod = this.polypodAt(boardAfter, newmove); + const adjacentCells = new Set; + for (const cell of activePolypod) { + for (const nb of this.graph.neighbours(cell)) { + if (!activePolypod.has(nb)) { + adjacentCells.add(nb); + } + } + } + const bonusMoves: string[] = []; + for (const adjCell of adjacentCells) { + if (this.isValidBonusMove(adjCell, boardAfter, remainsAfter).valid) { + bonusMoves.push(adjCell); + } + } + if (bonusMoves.length === 1) { + newmove += ";" + bonusMoves[0]; + } + } + if (! result.valid) { result.move = move; if (move !== "") { @@ -563,7 +590,7 @@ export class PolypodsGame extends GameBase { let validBonusMove = false; for (const cell of polypod) { for (const nb of this.graph.neighbours(cell)) { - if (this.isValidBonusMove(nb, boardAfter, remainsAfter)) { + if (this.isValidBonusMove(nb, boardAfter, remainsAfter).valid) { validBonusMove = true; break; } From e18357465a5ea8bfb70e8837a9f3299ef120ac12 Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 12:47:17 +0100 Subject: [PATCH 12/16] custom colour scheme --- .../en/apresults/apresults-path-map.json | 2 +- locales/en/apgames.json | 3 + src/games/polypods.ts | 77 ++++++++++++++++--- 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/locale-src/en/apresults/apresults-path-map.json b/locale-src/en/apresults/apresults-path-map.json index b607f181..515a8177 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-17", + "generatedAt": "2026-11-18", "schemaVersion": 1, "entries": [ { diff --git a/locales/en/apgames.json b/locales/en/apgames.json index a2566c63..38c778ef 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -8156,6 +8156,9 @@ "size-12": { "name": "12x12 board" }, + "size-19": { + "name": "19x19 board" + }, "#variant": { "description": "Directly attacked feet leave permanent remains.", "name": "Polypods Base Game" diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 9c318b26..860368d5 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -1,7 +1,7 @@ import { GameBase, IAPGameState, IClickResult, IIndividualState, IScores, IValidationResult } from "./_base.js"; import type { APGamesInformation } from "../schemas/gameinfo.js"; -import { APRenderRep } from "@abstractplay/renderer/build/schemas/schema"; +import { APRenderRep, Colourfuncs } from "@abstractplay/renderer/build/schemas/schema"; import type { APMoveResult } from "../schemas/moveresults.js"; import { reviver, UserFacingError, cloneState } from "../common/index.js"; import i18next from "i18next"; @@ -46,9 +46,6 @@ export const gameApgamesEn = { "size-12": { name: "12x12 board", }, - "size-19": { - name: "19x19 board", - }, "#variant": { description: "Directly attacked feet leave permanent remains.", name: "Polypods Base Game" @@ -157,6 +154,30 @@ export class PolypodsGame extends GameBase { }, ], + customizations: [ + { + num: 1, + default: "#007f00", + explanation: "Player 1 colour", + player: 1 + }, + { + num: 2, + default: "#ffffff", + explanation: "Player 2 colour", + player: 2 + }, + { + num: 3, + default: "#777777", + explanation: "Colour of the remains markers" + }, + { + name: "board", + default: "#cfc39e", + explanation: "Board colour" + } + ], categories: ["goal>score>eog", "mechanic>place", "board>shape>rect", "board>connect>snub"], flags: ["scores", "automove", "experimental"] }; @@ -938,7 +959,37 @@ export class PolypodsGame extends GameBase { }; } + public getPlayerColour(p: playerid): number|Colourfuncs { + if (p === 1) { + return { + func: "custom", + default: "#007f00", + palette: 1 + } + } + if (p === 2) { + return { + func: "custom", + default: "#ffffff", + palette: 2 + } + } + if (p === 3) { + return { + func: "custom", + default: "#777777", + palette: 3 + } + } + return p; + } + public render(): APRenderRep { + + const p1 = this.getPlayerColour(1); + const p2 = this.getPlayerColour(2); + const p3 = this.getPlayerColour(3); + // Build piece string let pstr = ""; const cells = this.graph.listCells(true); @@ -979,6 +1030,14 @@ export class PolypodsGame extends GameBase { width: this.boardsize, height: this.boardsize, blocked: [{row: 0, col: 0}], + backFill: { + type: "board", + colour: { + func: "custom", + default: "#cfc39e", + palette: "_context_board" + } + } }; if (this.boardsize % 2 === 0) { board.blocked.push({row: this.boardsize-1, col: this.boardsize-1}); @@ -989,27 +1048,27 @@ export class PolypodsGame extends GameBase { legend: { A: { name: "piece", - colour: 1, + colour: p1, scale: 0.85 }, B: { name: "piece-chariot", - colour: 1, + colour: p1, scale: 1.2 }, C: { name: "piece", - colour: 2, + colour: p2, scale: 0.85 }, D: { name: "piece-chariot", - colour: 2, + colour: p2, scale: 1.2 }, E: { name: "piece-borderless", - colour: 3, + colour: p3, scale: 0.4 } }, From 2bbdd5a8ba38e32c98277e7aa4e0f18b431271af Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 14:42:39 +0100 Subject: [PATCH 13/16] polypods test all variants --- src/games/polypods.ts | 23 ++-- test/games/polypods.test.ts | 242 ++++++++++++++++++++++++++++++++++++ 2 files changed, 251 insertions(+), 14 deletions(-) create mode 100644 test/games/polypods.test.ts diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 860368d5..27cfa00b 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -1,7 +1,7 @@ import { GameBase, IAPGameState, IClickResult, IIndividualState, IScores, IValidationResult } from "./_base.js"; import type { APGamesInformation } from "../schemas/gameinfo.js"; -import { APRenderRep, Colourfuncs } from "@abstractplay/renderer/build/schemas/schema"; +import { APRenderRep, BoardBasic, Colourfuncs } from "@abstractplay/renderer/build/schemas/schema"; import type { APMoveResult } from "../schemas/moveresults.js"; import { reviver, UserFacingError, cloneState } from "../common/index.js"; import i18next from "i18next"; @@ -265,7 +265,7 @@ export class PolypodsGame extends GameBase { return graph; } - private updatePolypods(board: board): board { + public updatePolypods(board: board): board { /* Set the pieces to feet or core depending on friendly connectivity */ const newBoard = cloneState(board) as board; newBoard.forEach((piece, cell) => { @@ -974,13 +974,6 @@ export class PolypodsGame extends GameBase { palette: 2 } } - if (p === 3) { - return { - func: "custom", - default: "#777777", - palette: 3 - } - } return p; } @@ -988,7 +981,6 @@ export class PolypodsGame extends GameBase { const p1 = this.getPlayerColour(1); const p2 = this.getPlayerColour(2); - const p3 = this.getPlayerColour(3); // Build piece string let pstr = ""; @@ -1024,7 +1016,7 @@ export class PolypodsGame extends GameBase { } // Build rep - const board = { + const board: BoardBasic = { style: "snubsquare", snubStart: "T", width: this.boardsize, @@ -1040,7 +1032,7 @@ export class PolypodsGame extends GameBase { } }; if (this.boardsize % 2 === 0) { - board.blocked.push({row: this.boardsize-1, col: this.boardsize-1}); + board.blocked!.push({row: this.boardsize-1, col: this.boardsize-1}); } const rep: APRenderRep = { renderer: "stacking-offset", @@ -1068,7 +1060,11 @@ export class PolypodsGame extends GameBase { }, E: { name: "piece-borderless", - colour: p3, + colour: { + func: "custom", + default: "#777777", + palette: 3 + }, scale: 0.4 } }, @@ -1095,7 +1091,6 @@ export class PolypodsGame extends GameBase { delete rep.annotations; } } - console.log("Score:", this.sidebarScores()[0].scores); return rep; } diff --git a/test/games/polypods.test.ts b/test/games/polypods.test.ts new file mode 100644 index 00000000..1d6eb448 --- /dev/null +++ b/test/games/polypods.test.ts @@ -0,0 +1,242 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import "mocha"; +import { expect } from "chai"; +import { PolypodsGame } from '../../src/games'; + +function state(p1s: string[], p2s: string[], remains: string[], variants: string[] = []): PolypodsGame { + const g = new PolypodsGame(undefined, variants); + for(const m of p1s){ + g.board.set(m, {player: 1, type: "foot"}); + } + for(const m of p2s){ + g.board.set(m, {player: 2, type: "foot"}); + } + for(const m of remains){ + g.remains.add(m); + } + g.board = g.updatePolypods(g.board); + return g; +} + +/* Various end conditions. +Test with both p1 and p2 as the current player: +current player wins with normal stone +neutral stone, current player wins with only loop +neutral stone, other player wins with only loop +neutral stone, current player wins with shortest loop +neutral stone, other player wins with shortest loop +neutral stone, current player wins with equally long loop but fewer neutrals +neutral stone, other player wins with equally long loop but fewer neutrals +neutral stone, two loops of equal size and #neutrals, p2 wins +*/ + +describe.only("Polypods", () => { + it("set feet and cores based on connectivity", () => { + const moves = ["b6", "f4", "c6", "f5", "b5", "g4", "c4", "g5", "a5", "f6", "b7"] + const g = new PolypodsGame() + for(const m of moves) { + g.move(m); + } + for (const c of ["b5", "b6", "f5", "g4"]) { + expect(g.board.get(c)!.type).to.equal("core") + } + for (const c of ["a5", "b7", "c4", "c6", "f4", "f6", "g5"]) { + expect(g.board.get(c)!.type).to.equal("foot") + } + }) + + it("can't place adjacent to opponent core", () => { + const g = state( + [], + ['d4', 'd5', 'd6'], + []); + const results = g.validateMove("e5"); + expect(results.valid).to.be.false; + }) + + it("can't place on remains", () => { + const g = state( + [], + [], + ['e4']); + const results = g.validateMove('e4'); + expect(results.valid).to.be.false; + }) + + it("polypod death", () => { + const ppod = ['c5', 'c6', 'd6', 'd7', 'e6', 'e7']; + const g = state( + ['b4', 'c4'], + ppod, + []); + g.move('d4') + for (const c of ppod) { + expect(g.board.has(c)).to.be.false; + } + }) + + it("polypod core revert to feet", () => { + const g = state( + ['d3', 'e3'], + ['c6', 'd6', 'd5', 'e4'], + [] + ); + expect(g.board.get('d5')!.type).to.equal("core") + g.move('f3') + expect(g.board.get('d5')!.type).to.equal("foot") + }) + + it("can't grow if it would have too few feet", () => { + const g = state( + ['c6', 'd6', 'd5', 'e4'], + [], + [] + ); + const results = g.validateMove('f4'); + expect(results.valid).to.be.false; + }) + + it("base game markers", () => { + const ppod = ['c5', 'c6', 'd6', 'd7', 'e6', 'e7']; + const g = state( + ['b4', 'c4'], + ppod, + [] + ); + g.move('d4') + const expectRemains = new Set(['c5']); + expect(g.remains).to.deep.equal(expectRemains) + }) + + it("stoney-footed markers", () => { + const ppod = ['c5', 'c6', 'd6', 'd7', 'e6', 'e7']; + const g = state( + ['b4', 'c4'], + ppod, + [], + ['stoney-footed'], + ); + g.move('d4') + const expectRemains = new Set(['c5', 'c6', 'e7']); + expect(g.remains).to.deep.equal(expectRemains) + }) + + it("energized markers", () => { + const ppod = ['c5', 'c6', 'd6', 'd7', 'e6', 'e7']; + const g = state( + ['b4', 'c4'], + ppod, + [], + ['energized'], + ); + g.move('d4') + const expectRemains = new Set(['c5', 'c6', 'e7', 'd6']); + expect(g.remains).to.deep.equal(expectRemains) + }) + + it("scavenging markers", () => { + const ppod = ['c5', 'c6', 'd6', 'd7', 'e6', 'e7']; + const g = state( + ['b4', 'c4'], + ppod, + [], + ['scavenging'], + ); + g.move('d4') + const expectRemains = new Set(['c5', 'c6', 'd6', 'd7', 'e6', 'e7']); + expect(g.remains).to.deep.equal(expectRemains) + }) + + it("energized bonus move", () => { + const g = state( + ['d3', 'd4'], + [], + ['e4'], + ['energized'], + ); + const results = g.validateMove('e4'); + expect(results.valid).to.be.true; + expect(results.complete).to.equal(-1); + const results2 = g.validateMove('e4;d2'); + expect(results2.complete).to.equal(1); + expect(results2.valid).to.be.true; + }) + + it("energized bonus move not available", () => { + const g = state( + ['a2', 'b2', 'b1'], + ['a4', 'b4', 'c4', 'd3', 'd2', 'd1'], + ['a1'], + ['energized'], + ); + const results = g.validateMove('a1'); + expect(results.valid).to.be.false; + }) + + it("energized bonus move not on a marker", () => { + const g = state( + ['a2', 'b2', 'b1'], + [], + ['a1', 'b3'], + ['energized'], + ); + const results = g.validateMove('a1'); + expect(results.valid).to.be.true; + expect(results.complete).to.equal(-1); + + const results2 = g.validateMove('a1;b3'); + expect(results2.valid).to.be.false; + + const results3 = g.validateMove('a1;c2'); + expect(results3.valid).to.be.true; + expect(results3.complete).to.equal(1); + }) + + it("scavenging capture doesn't remove marker", () => { + const g = state( + ['d4', 'd5'], + ['e4'], + ['e6'], + ['scavenging'], + ); + g.move('e5'); + expect(g.remains).to.deep.equal(new Set(['e6', 'e4'])) + }) + + it("scavenging non-capture must remove marker", () => { + const g = state( + ['d5'], + ['e4'], + ['e6'], + ['scavenging'], + ); + const result = g.validateMove('e5'); + expect(result.valid).to.be.true + expect(result.complete).to.equal(-1) + }) + + it("scavenging non-capture on marker", () => { + const g = state( + ['d5'], + ['e4'], + ['e5'], + ['scavenging'], + ); + const result = g.validateMove('e5'); + expect(result.valid).to.be.true + expect(result.complete).to.equal(1) + }) + + it("scavenging cannot capture while placing on marker", () => { + const g = state( + ['d4', 'd5'], + ['e4'], + ['e5'], + ['scavenging'], + ); + const result = g.validateMove('e5'); + expect(result.valid).to.be.false + }) +}); + From 46a7e1d65a0bc9db1ddfeac245816ae037b7582a Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 14:44:49 +0100 Subject: [PATCH 14/16] tags --- src/games/polypods.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index 27cfa00b..c8f0315b 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -178,7 +178,7 @@ export class PolypodsGame extends GameBase { explanation: "Board colour" } ], - categories: ["goal>score>eog", "mechanic>place", "board>shape>rect", "board>connect>snub"], + categories: ["goal>score>eog", "goal>majority", "mechanic>place", "board>shape>rect", "board>connect>snub"], flags: ["scores", "automove", "experimental"] }; From 004f14b43c6ca59a2dd89b251884ec167e36eef7 Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 14:46:03 +0100 Subject: [PATCH 15/16] build --- locales/en/apgames.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/locales/en/apgames.json b/locales/en/apgames.json index 38c778ef..a2566c63 100644 --- a/locales/en/apgames.json +++ b/locales/en/apgames.json @@ -8156,9 +8156,6 @@ "size-12": { "name": "12x12 board" }, - "size-19": { - "name": "19x19 board" - }, "#variant": { "description": "Directly attacked feet leave permanent remains.", "name": "Polypods Base Game" From 4d60c2809c829e32810713774084d0f2fb324504 Mon Sep 17 00:00:00 2001 From: th555 Date: Wed, 18 Nov 2026 15:06:35 +0100 Subject: [PATCH 16/16] linter shenanigans --- src/games/polypods.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/games/polypods.ts b/src/games/polypods.ts index c8f0315b..2474cfda 100644 --- a/src/games/polypods.ts +++ b/src/games/polypods.ts @@ -694,11 +694,13 @@ export class PolypodsGame extends GameBase { newBoard.set(cell, {player: this.currplayer, type: "foot"}); newBoard = this.updatePolypods(newBoard); let newRemains: remains - let attacked: Set; - [newBoard, newRemains, attacked] = this.attackFeet(newBoard, remains); + const attackResult = this.attackFeet(newBoard, remains); + [newBoard, newRemains] = attackResult; + const attacked = attackResult[2]; newBoard = this.updatePolypods(newBoard); - let captured: Set; - [newBoard, newRemains, captured] = this.removeDeadPolypods(newBoard, newRemains, attacked); + const removeResult = this.removeDeadPolypods(newBoard, newRemains, attacked); + [newBoard, newRemains] = removeResult; + const captured = removeResult[2]; if (this.variants.includes("scavenging")) { newRemains.delete(cell); } @@ -709,7 +711,7 @@ export class PolypodsGame extends GameBase { let newBoard = cloneState(this.board) as board; newBoard.set(cell, {player: this.currplayer, type: "foot"}); newBoard = this.updatePolypods(newBoard); - const [_board, _remains, attacked] = this.attackFeet(newBoard, this.remains); + const attacked = this.attackFeet(newBoard, this.remains)[2]; return (attacked.size > 0); } @@ -728,7 +730,7 @@ export class PolypodsGame extends GameBase { } this.results = []; - let oldBoard: board = cloneState(this.board) as board; + const oldBoard: board = cloneState(this.board) as board; if (m === "pass") { this.results.push({type: "pass"}); } else { @@ -1101,7 +1103,7 @@ export class PolypodsGame extends GameBase { } public getPlayerScore(player: playerid): number { - let score = [...this.board.values()].filter((c) => (c.player === player && c.type === "core")).length; + const score = [...this.board.values()].filter((c) => (c.player === player && c.type === "core")).length; return score; }