@@ -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