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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions locales/en/apgames.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"irensei": "Irensei is a mixture of Go and Gomoku. Get a seven in a row inside the middle 15x15 region of the Go board to win. To reduce the first player's advantage, the first player loses if they make an overline (even if it extends beyond the 15x15 region), but the second player may win by overline.",
"jacynth": "A Decktet card game where opponents vye for control of the city of Jacynth. Place cards, exert influence, and control the most area to win.",
"kachit": "A chess-like game played on a 4x4 board where you try to eliminate the opposing king or promote your own. Pieces can change their orientation after moving.",
"konane": "A traditional Hawaiian game that was almost completely lost to time but for the memory of a single woman. Played on a square board, each player captures by jumping over their opponent's pieces. Last to move wins.",
"konane": "A traditional Hawaiian game that was almost completely lost to time but for the memory of a single woman, Kaʻahaʻaina Naihe of Kailua-Kona. Played on a rectangular board, each player captures by jumping over their opponent's pieces. Last to move wins.",
"krypte": "A 4-in-a-row game where pieces enter from active sides that rotate after each turn, and placing a piece flips all adjacent pieces.",
"lasca": "A Draughts variant where captured pieces remain on the board and can be freed later. Immobilize your opponent to win.",
"lielow": "A wartime tale of Machiavellian usurpership. You win if your piece lands on your opponent's king. You also win if your opponent chooses to move their king off the board.",
Expand Down Expand Up @@ -255,7 +255,7 @@
"gyges": "The goal squares are adjacent to all the cells in the back row. The renderer cannot currently handle \"floating\" cells.",
"homeworlds": "The win condition is what's called \"Sinister Homeworlds.\" You only win by defeating the opponent to your left. If someone else does that, the game continues, but your left-hand opponent now shifts clockwise. For example, in a four-player game, if I'm South, then I win if I eliminate West. But if the North player ends up eliminating West, the game continues, but now my left-hand opponent is North.",
"jacynth": "More information on the Decktet system can be found on the [official Decktet website](https://www.decktet.com). Cards in players' hands are hidden from observers and opponents.",
"konane": "Several competing opening protocols exist, but the most common ruleset is described in the BGG reference and is what is implemented here.",
"konane": "Several competing opening protocols exist, but the most common ruleset is the Naihe Ruleset, used by tournaments at the Bishop Museum in Hawaii and described in the BGG reference. This is what is implemented here.",
"lasca": "Maneuverability is a measure of how close your pieces are to promoting. Your maximum maneuverability is the board size times the number of stacks you control.\n\nMaterial is calculated by giving you a point for every friendly piece in a stack you control, plus an extra point if you have an officer on top of that stack.",
"loa": "In the centre of the 9x9 board is a \"black hole.\". Landing on the black hole means the piece is removed from the game. Simultaneous connections are scored as a draw.",
"magnate": "The terminology of some Magnate actions has been altered for clarity and brevity. Completely developing a new property is called the \"Buy\" action; purchasing a deed for a new property is called \"Deed\", developing deeds (that is, adding tokens to a deeded property, whether it results in the deed becoming fully developed or not) is called \"Add\". (Selling a card and trading suit tokens 3 for 1 are unchanged.)\n\nIn order to speed up the process of rolling for resources, there are two additional actions:\n* \"Prefer\" is for setting your preference of which suit token to take when a deed pays out on your opponent's roll. If you do not set an explicit preference, the code will choose the rarer token for you based on your non-crown suits and current supply of tokens. The currently preferred token is circled in the UI, but your personal preference is never visible to the other player.\n* \"Choose\" is a mandatory first action for collecting suit tokens when a deed pays out on your own roll. (In all cases where you need to choose a suit token that is not already among your tokens, you still click on the appropriate token pile.)\n\nBecause you can perform several actions during a ply in any order, there is also an \"Undo\" action to back out your most recent action, whether or not it was complete.\n\nNote that only the final resource die result is displayed, but the distribution of expected outcomes is still that of rolling 2d10 and taking the higher value. Taxation happens when the lower of 2d10 comes up 1; a suit die is rolled (or two, in the double taxation variant), and the suit(s) will be displayed underneath the resource result. The roll is logged at the end of a player's turn, and is attributed to the next player (who would have rolled in the physical game). Except for a \"Choose\", no user action is required; resources are added and/or removed automatically by the server in between turns.\n\nWhen a player is ahead in a district, the Pawn or Excuse for that district is outlined in that player's color. The first tiebreaker score (total property value) is displayed in parentheses after the district score. The second tiebreaker is total number of tokens remaining.",
Expand Down Expand Up @@ -1484,10 +1484,28 @@
},
"konane": {
"#board": {
"name": "Size 6 board"
"name": "6x6 board",
"description": "Opening: Players will remove stones from the center square or the corners to start."
},
"size-7": {
"name": "7x6 board",
"description": "Opening: The center two spaces will start empty."
},
"size-8": {
"name": "Size 8 board"
"name": "8x8 board",
"description": "Opening: Players will remove stones from the center square or the corners to start."
},
"size-9": {
"name": "11x8 board",
"description": "Opening: The center two spaces will start empty."
},
"size-11": {
"name": "11x8 board",
"description": "Opening: The center two spaces will start empty."
},
"size-15": {
"name": "15x12 board",
"description": "Opening: The center two spaces will start empty."
}
},
"lasca": {
Expand Down Expand Up @@ -2884,11 +2902,12 @@
"name": "Hexhex 5 (61 spaces)"
},
"hex7": {
"name": "Hexhex 7 (127 spaces)"
"name": "Hexhex 7 (127 spaces)",
"description": "Can be selected for 3 and 4 player games."
},
"hex8": {
"name": "Hexhex 8 (169 spaces)",
"description": "For 3 and 4 player games, the hex8 board will be selected automatically."
"description": "Can be selected for 3 and 4 player games."
},
"open": {
"name": "Open start",
Expand Down Expand Up @@ -5983,6 +6002,7 @@
"UNBROKEN": "Lines of pieces must be unbroken by empty cells."
},
"wunchunk": {
"BALANCE": "Player 1 may not create two friendly chunks with their second placement.",
"BOARD_FULL": "The board is full.",
"INITIAL_INSTRUCTIONS_choose": "Use the buttons to choose whether to play first or second.",
"INITIAL_INSTRUCTIONS_play_one": "You may place up to {{count}} piece this turn. Click the piece at the side of the board and then an empty cell to place it. Or just click an empty cell to place one of your own pieces.",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "npm run json2ts && npm run build-ts && npm run lint",
"build-ts": "tsc && npm pack",
"test0": "mocha -r ts-node/register test/common/graphs/recttri.test.ts",
"test0": "mocha -r ts-node/register test/games/wunchunk.test.ts",
"test": "mocha -r ts-node/register test/**/*.test.ts",
"lint": "npx eslint .",
"dist-dev": "rimraf dist && webpack",
Expand Down
130 changes: 86 additions & 44 deletions src/games/konane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class KonaneGame extends GameBase {
name: "Konane",
uid: "konane",
playercounts: [2],
version: "20241029",
version: "20260308",
dateAdded: "2024-11-01",
// i18next.t("apgames:descriptions.konane")
description: "apgames:descriptions.konane",
Expand All @@ -45,13 +45,30 @@ export class KonaneGame extends GameBase {
categories: ["goal>immobilize", "mechanic>capture", "other>traditional", "board>shape>rect"],
flags: ["automove"],
variants: [
{
uid: "size-7",
group: "board"
},
{
uid: "size-8",
group: "board"
},
{
uid: "size-9",
group: "board"
},
{
uid: "size-11",
group: "board"
},
{
uid: "size-15",
group: "board"
}
]
};

public version = parseInt(KonaneGame.gameinfo.version, 10);
public numplayers = 2;
public currplayer: PlayerId = 1;
public board!: Map<string, PlayerId>;
Expand All @@ -61,7 +78,8 @@ export class KonaneGame extends GameBase {
public variants: string[] = [];
public stack!: Array<IMoveState>;
public results: Array<APMoveResult> = [];
private boardSize = 0;
private boardWidth = 0;
private boardHeight = 0;
private _points: [number, number][] = [];
private _highlight: string | undefined;

Expand All @@ -71,12 +89,17 @@ export class KonaneGame extends GameBase {
if (variants !== undefined) {
this.variants = [...variants];
}
this.boardSize = this.getBoardSize();
this.setBoardSize();
const board: Map<string, PlayerId> = new Map();
let color = 2 as PlayerId;
for (let x = 0; x < this.boardSize; x++) {
for (let y = 0; y < this.boardSize; y++) {
board.set(GameBase.coords2algebraic(x, y, this.boardSize), color);
for (let x = 0; x < this.boardWidth; x++) {
for (let y = 0; y < this.boardHeight; y++) {
if ((this.boardWidth !== 7 || (y !== 2 && y !== 3) || x !== 3) &&
(this.boardWidth !== 9 || (y !== 3 && y !== 4) || x !== 4) &&
(this.boardWidth !== 11 || (y !== 3 && y !== 4) || x !== 5) &&
(this.boardWidth !== 15 || (y !== 5 && y !== 6) || x !== 7)) {
board.set(GameBase.coords2algebraic(x, y, this.boardHeight), color);
}
color = (color === 1) ? 2 : 1;
}
color = (color === 1) ? 2 : 1;
Expand All @@ -102,7 +125,7 @@ export class KonaneGame extends GameBase {
this.variants = state.variants;
this.stack = [...state.stack];
}
this.boardSize = this.getBoardSize();
this.setBoardSize();
this.load();
this.buildGraph();
}
Expand All @@ -116,24 +139,24 @@ export class KonaneGame extends GameBase {
}

const state = this.stack[idx];
this.version = parseInt(state._version, 10);
this.currplayer = state.currplayer;

this.board = deepclone(state.board) as Map<string, PlayerId>;
this.lastmove = state.lastmove;
this.results = [...state._results];
return this;
}

private buildGraph(): SquareOrthGraph {
this.graph = new SquareOrthGraph(this.boardSize, this.boardSize);
this.graph = new SquareOrthGraph(this.boardWidth, this.boardHeight);
return this.graph;
}

private getGraph(boardSize?: number): SquareOrthGraph {
if (boardSize === undefined) {
private getGraph(boardWidth?: number, boardHeight?: number): SquareOrthGraph {
if (boardWidth === undefined || boardHeight === undefined) {
return (this.graph === undefined) ? this.buildGraph() : this.graph;
} else {
return new SquareOrthGraph(boardSize, boardSize);
return new SquareOrthGraph(boardWidth, boardHeight);
}
}

Expand All @@ -151,19 +174,32 @@ export class KonaneGame extends GameBase {
}
}

private getBoardSize(): number {
// Get board size from variants.
private setBoardSize(): KonaneGame {
this.boardWidth = 6;
this.boardHeight = 6;

if ( (this.variants !== undefined) && (this.variants.length > 0) && (this.variants[0] !== undefined) && (this.variants[0].length > 0) ) {
const sizeVariants = this.variants.filter(v => v.includes("size"))
const sizeVariants = this.variants.filter(v => v.includes("size"));
if (sizeVariants.length > 0) {
const size = sizeVariants[0].match(/\d+/);
return parseInt(size![0], 10);
const sizeString = sizeVariants[0].match(/\d+/);
this.boardWidth = parseInt(sizeString![0], 10);
if (this.boardWidth === 6 || this.boardWidth === 8) {
this.boardHeight = this.boardWidth;
} else if (this.boardWidth === 7) {
this.boardHeight = 6;
} else if (this.boardWidth === 9) {
this.boardHeight = 8;
} else if (this.boardWidth === 11) {
this.boardHeight = 8;
} else if (this.boardWidth === 15) {
this.boardHeight = 12;
}
}
if (isNaN(this.boardSize)) {
if (isNaN(this.boardWidth) || isNaN(this.boardHeight)) {
throw new Error(`Could not determine the board size from variant "${this.variants[0]}"`);
}
}
return 6;
return this;
}

public moves(player?: PlayerId): string[] {
Expand All @@ -173,20 +209,22 @@ export class KonaneGame extends GameBase {
}

const moves: string[] = [];
if (this.stack.length === 1) {
moves.push("a1");
if (this.boardSize === 6) {
moves.push("c3");
moves.push("d4");
moves.push("f6");
} else {
moves.push("d4");
moves.push("e5");
moves.push("h8");
}
} else if (this.stack.length === 2) {
for (const m of this.getGraph().neighbours(this.stack[1].lastmove!)) {
moves.push(m);
if ((this.boardWidth === 6 || this.boardWidth === 8) && this.stack.length < 3) {
if (this.stack.length === 1) {
moves.push("a1");
if (this.boardWidth === 6) {
moves.push("c3");
moves.push("d4");
moves.push("f6");
} else if (this.boardWidth === 8) {
moves.push("d4");
moves.push("e5");
moves.push("h8");
}
} else if (this.stack.length === 2) {
for (const m of this.getGraph().neighbours(this.stack[1].lastmove!)) {
moves.push(m);
}
}
} else {
for (const cell of (this.listCells() as string[]).filter(c => this.board.has(c) && this.board.get(c) === this.currplayer)) {
Expand Down Expand Up @@ -251,10 +289,12 @@ export class KonaneGame extends GameBase {

if (m.length === 0) {
result.valid = true;
if (this.stack.length === 1) {
result.message = i18next.t("apgames:validation.konane.FIRST_MOVE");
} else if (this.stack.length === 2) {
result.message = i18next.t("apgames:validation.konane.SECOND_MOVE");
if ((this.boardWidth === 6 || this.boardWidth === 8) && this.stack.length < 3) {
if (this.stack.length === 1) {
result.message = i18next.t("apgames:validation.konane.FIRST_MOVE");
} else if (this.stack.length === 2) {
result.message = i18next.t("apgames:validation.konane.SECOND_MOVE");
}
} else {
result.message = i18next.t("apgames:validation.konane.NORMAL_MOVE");
}
Expand All @@ -263,10 +303,12 @@ export class KonaneGame extends GameBase {

const moves = this.moves();
if (!moves.includes(m)) {
if (this.stack.length === 1) {
result.message = i18next.t("apgames:validation.konane.FIRST_MOVE");
} else if (this.stack.length === 2) {
result.message = i18next.t("apgames:validation.konane.SECOND_MOVE");
if ((this.boardWidth === 6 || this.boardWidth === 8) && this.stack.length < 3) {
if (this.stack.length === 1) {
result.message = i18next.t("apgames:validation.konane.FIRST_MOVE");
} else if (this.stack.length === 2) {
result.message = i18next.t("apgames:validation.konane.SECOND_MOVE");
}
} else if (m.length > 0 && moves.filter(move => move.startsWith(m)).length > 0) {
result.valid = true;
result.canrender = true;
Expand Down Expand Up @@ -381,7 +423,7 @@ export class KonaneGame extends GameBase {

public moveState(): IMoveState {
return {
_version: KonaneGame.gameinfo.version,
_version: `${this.version}`,
_results: [...this.results],
_timestamp: new Date(),
currplayer: this.currplayer,
Expand Down Expand Up @@ -426,8 +468,8 @@ export class KonaneGame extends GameBase {
const rep: APRenderRep = {
board: {
style: "squares",
width: this.boardSize,
height: this.boardSize
width: this.boardWidth,
height: this.boardHeight
},
legend: {
A: { name: "piece", colour: 1 },
Expand Down
Loading