1 import AbstractSpecialCaptureRules
from "/variants/_SpecialCaptures.js";
2 import {FenUtil
} from "/utils/setupPieces.js";
3 import {Random
} from "/utils/alea.js";
5 export default class BaroqueRules
extends AbstractSpecialCaptureRules
{
9 select: C
.Options
.Select
,
12 label: "Capture king",
35 genRandInitBaseFen() {
36 const s
= FenUtil
.setupPieces(
37 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'i'], {diffCol: ['b']});
38 if (this.options
["randomness"] <= 1) {
39 // Fix immobilizers/rooks pattern
40 const toExchange1
= s
.w
.indexOf('r'),
41 toExchange2
= s
.w
.indexOf('i');
42 s
.w
[toExchange1
] = 'i';
43 s
.w
[toExchange2
] = 'r';
46 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
47 s
.w
.join("").toUpperCase(),
53 return Object
.assign({},
57 "class": "pawn", //pincer
59 {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
63 "class": "rook", //coordinator
67 [1, 0], [0, 1], [-1, 0], [0, -1],
68 [1, 1], [1, -1], [-1, 1], [-1, -1]
74 "class": "knight", //long-leaper
78 "class": "bishop", //chameleon
82 "class": "queen", //withdrawer
86 "class": "immobilizer",
93 // Is piece on square (x,y) immobilized?
94 isImmobilized([x
, y
]) {
95 const piece
= this.getPiece(x
, y
);
96 const color
= this.getColor(x
, y
);
97 const oppCol
= C
.GetOppCol(color
);
98 const adjacentSteps
= this.pieces()['k'].moves
[0].steps
;
99 for (let step
of adjacentSteps
) {
100 const [i
, j
] = [x
+ step
[0], this.getY(y
+ step
[1])];
102 this.onBoard(i
, j
) &&
103 this.board
[i
][j
] != "" &&
104 this.getColor(i
, j
) == oppCol
106 const oppPiece
= this.getPiece(i
, j
);
107 if (oppPiece
== 'i') {
108 // Moving is possible only if this immobilizer is neutralized
109 for (let step2
of adjacentSteps
) {
110 const [i2
, j2
] = [i
+ step2
[0], this.getY(j
+ step2
[1])];
111 if (i2
== x
&& j2
== y
)
112 continue; //skip initial piece!
114 this.onBoard(i2
, j2
) &&
115 this.board
[i2
][j2
] != "" &&
116 this.getColor(i2
, j2
) == color
118 if (['b', 'i'].includes(this.getPiece(i2
, j2
)))
122 return true; //immobilizer isn't neutralized
124 // Chameleons can't be immobilized twice,
125 // because there is only one immobilizer
126 if (oppPiece
== 'b' && piece
== 'i')
133 canTake([x1
, y1
], [x2
, y2
]) {
134 // Deactivate standard captures, except for king:
136 this.getPiece(x1
, y1
) == 'k' &&
137 this.getColor(x1
, y1
) != this.getColor(x2
, y2
)
141 postProcessPotentialMoves(moves
) {
142 if (moves
.length
== 0)
144 switch (moves
[0].vanish
[0].p
) {
146 this.addPincerCaptures(moves
);
149 this.addCoordinatorCaptures(moves
);
152 const [x
, y
] = [moves
[0].start
.x
, moves
[0].start
.y
];
153 moves
= moves
.concat(this.getLeaperCaptures([x
, y
]));
156 moves
= this.getChameleonCaptures(moves
, "pull");
159 this.addPushmePullyouCaptures(moves
, false, "pull");