Skip to content

Commit 4df6107

Browse files
authored
Merge pull request #390 from jpneto/develop
Added options to Twin Flames
2 parents 2122a2e + e177ac1 commit 4df6107

2 files changed

Lines changed: 40 additions & 14 deletions

File tree

locales/en/apgames.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,13 +3151,23 @@
31513151
"size-8": {
31523152
"name": "Hex board (base-8), 8 blockers"
31533153
},
3154-
"#ruleset": {
3155-
"description": "Original rules.",
3156-
"name": "Standard Rules"
3154+
"#blockers": {
3155+
"name": "Use standard number of blockers"
3156+
},
3157+
"blocker-0": {
3158+
"name": "Don't use blockers"
3159+
},
3160+
"blocker-2": {
3161+
"name": "Use 2 blockers"
3162+
},
3163+
"blocker-4": {
3164+
"name": "Use 4 blockers"
3165+
},
3166+
"blocker-6": {
3167+
"name": "Use 6 blockers"
31573168
},
3158-
"no-block": {
3159-
"description": "No blockers are used.",
3160-
"name": "No blockers"
3169+
"blocker-8": {
3170+
"name": "Use 8 blockers"
31613171
}
31623172
},
31633173
"twixt": {

src/games/twinflames.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ export class TwinFlamesGame extends GameBase {
5151
{ uid: "#board", },
5252
{ uid: "size-7", group: "board" },
5353
{ uid: "size-8", group: "board" },
54-
{ uid: "no-block", group: "ruleset" },
54+
{ uid: "#blockers", },
55+
{ uid: "blocker-0", group: "blockers" },
56+
{ uid: "blocker-2", group: "blockers" },
57+
{ uid: "blocker-4", group: "blockers" },
58+
{ uid: "blocker-6", group: "blockers" },
59+
{ uid: "blocker-8", group: "blockers" },
5560
],
5661
flags: ["no-moves"]
5762
};
@@ -128,9 +133,19 @@ export class TwinFlamesGame extends GameBase {
128133
return 6;
129134
}
130135

131-
private getRuleset(): "default" | "no-block" {
132-
if (this.variants.includes("no-block")) { return "no-block"; }
133-
return "default";
136+
private getBlockersSize(): number {
137+
// Get board size from variants.
138+
if ( (this.variants !== undefined) && (this.variants.length > 0) && (this.variants[0] !== undefined) && (this.variants[0].length > 0) ) {
139+
const sizeVariants = this.variants.filter(v => v.includes("blocker"));
140+
if (sizeVariants.length > 0) {
141+
const size = sizeVariants[0].match(/\d+/);
142+
return parseInt(size![0], 10);
143+
}
144+
if (isNaN(this.boardSize)) {
145+
throw new Error(`Could not determine the number of blockers from variant "${this.variants[0]}"`);
146+
}
147+
}
148+
return -1;
134149
}
135150

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

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

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

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

156172
if ( boardSize === 7 ) {
157-
shooterCount = 6;
173+
shooterCount = nBlockers === -1 ? 6 : nBlockers;
158174
rows = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
159175
cols_by_rows = [6, 7, 8, 9, 10, 9, 8, 7, 6];
160176
}
161177
if ( boardSize === 8 ) {
162-
shooterCount = 8;
178+
shooterCount = nBlockers === -1 ? 8 : nBlockers;
163179
rows = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'];
164180
cols_by_rows = [7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7];
165181
}

0 commit comments

Comments
 (0)