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
22 changes: 16 additions & 6 deletions locales/en/apgames.json
Original file line number Diff line number Diff line change
Expand Up @@ -3151,13 +3151,23 @@
"size-8": {
"name": "Hex board (base-8), 8 blockers"
},
"#ruleset": {
"description": "Original rules.",
"name": "Standard Rules"
"#blockers": {
"name": "Use standard number of blockers"
},
"blocker-0": {
"name": "Don't use blockers"
},
"blocker-2": {
"name": "Use 2 blockers"
},
"blocker-4": {
"name": "Use 4 blockers"
},
"blocker-6": {
"name": "Use 6 blockers"
},
"no-block": {
"description": "No blockers are used.",
"name": "No blockers"
"blocker-8": {
"name": "Use 8 blockers"
}
},
"twixt": {
Expand Down
32 changes: 24 additions & 8 deletions src/games/twinflames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export class TwinFlamesGame extends GameBase {
{ uid: "#board", },
{ uid: "size-7", group: "board" },
{ uid: "size-8", group: "board" },
{ uid: "no-block", group: "ruleset" },
{ uid: "#blockers", },
{ uid: "blocker-0", group: "blockers" },
{ uid: "blocker-2", group: "blockers" },
{ uid: "blocker-4", group: "blockers" },
{ uid: "blocker-6", group: "blockers" },
{ uid: "blocker-8", group: "blockers" },
],
flags: ["no-moves"]
};
Expand Down Expand Up @@ -128,9 +133,19 @@ export class TwinFlamesGame extends GameBase {
return 6;
}

private getRuleset(): "default" | "no-block" {
if (this.variants.includes("no-block")) { return "no-block"; }
return "default";
private getBlockersSize(): number {
// Get board size from variants.
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("blocker"));
if (sizeVariants.length > 0) {
const size = sizeVariants[0].match(/\d+/);
return parseInt(size![0], 10);
}
if (isNaN(this.boardSize)) {
throw new Error(`Could not determine the number of blockers from variant "${this.variants[0]}"`);
}
}
return -1;
}

private getGraph(): HexTriGraph {
Expand All @@ -144,22 +159,23 @@ export class TwinFlamesGame extends GameBase {

private getRandomPlacement(): Map<string, playerid> {
const board = new Map<string, playerid>();
const nBlockers = this.getBlockersSize(); // -1 means using the default value for the board size

if ( this.getRuleset() !== "no-block" ) {
if ( nBlockers !== 0 ) {
const boardSize = this.getBoardSize(); // this.boardSize is not available yet
const g = new HexTriGraph(boardSize, 2*boardSize - 2);

let shooterCount = 4;
let shooterCount = nBlockers === -1 ? 4 : nBlockers;
let rows = ['b', 'c', 'd', 'e', 'f', 'g', 'h'];
let cols_by_rows = [5, 6, 7, 8, 7, 6, 5]; // size of rows, excluding edges

if ( boardSize === 7 ) {
shooterCount = 6;
shooterCount = nBlockers === -1 ? 6 : nBlockers;
rows = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
cols_by_rows = [6, 7, 8, 9, 10, 9, 8, 7, 6];
}
if ( boardSize === 8 ) {
shooterCount = 8;
shooterCount = nBlockers === -1 ? 8 : nBlockers;
rows = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'];
cols_by_rows = [7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7];
}
Expand Down
Loading