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'],
39 randomness: this.options
["randomness"],
43 if (this.options
["randomness"] <= 1) {
44 // Fix immobilizers/rooks pattern
45 const toExchange1
= s
.w
.indexOf('r'),
46 toExchange2
= s
.w
.indexOf('i');
47 s
.w
[toExchange1
] = 'i';
48 s
.w
[toExchange2
] = 'r';
51 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
52 s
.w
.join("").toUpperCase(),
58 return Object
.assign({},
62 "class": "pawn", //pincer
64 {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
68 "class": "rook", //coordinator
72 [1, 0], [0, 1], [-1, 0], [0, -1],
73 [1, 1], [1, -1], [-1, 1], [-1, -1]
79 "class": "knight", //long-leaper
83 "class": "bishop", //chameleon
87 "class": "queen", //withdrawer
91 "class": "immobilizer",
98 // Is piece on square (x,y) immobilized?
99 isImmobilized([x
, y
]) {
100 const piece
= this.getPiece(x
, y
);
101 const color
= this.getColor(x
, y
);
102 const oppCol
= C
.GetOppTurn(color
);
103 const adjacentSteps
= this.pieces()['k'].moves
[0].steps
;
104 for (let step
of adjacentSteps
) {
105 const [i
, j
] = [x
+ step
[0], this.getY(y
+ step
[1])];
107 this.onBoard(i
, j
) &&
108 this.board
[i
][j
] != "" &&
109 this.getColor(i
, j
) == oppCol
111 const oppPiece
= this.getPiece(i
, j
);
112 if (oppPiece
== 'i') {
113 // Moving is possible only if this immobilizer is neutralized
114 for (let step2
of adjacentSteps
) {
115 const [i2
, j2
] = [i
+ step2
[0], this.getY(j
+ step2
[1])];
116 if (i2
== x
&& j2
== y
)
117 continue; //skip initial piece!
119 this.onBoard(i2
, j2
) &&
120 this.board
[i2
][j2
] != "" &&
121 this.getColor(i2
, j2
) == color
123 if (['b', 'i'].includes(this.getPiece(i2
, j2
)))
127 return true; //immobilizer isn't neutralized
129 // Chameleons can't be immobilized twice,
130 // because there is only one immobilizer
131 if (oppPiece
== 'b' && piece
== 'i')
138 canTake([x1
, y1
], [x2
, y2
]) {
139 // Deactivate standard captures, except for king:
141 this.getPiece(x1
, y1
) == 'k' &&
142 this.getColor(x1
, y1
) != this.getColor(x2
, y2
)
146 postProcessPotentialMoves(moves
) {
147 if (moves
.length
== 0)
149 switch (moves
[0].vanish
[0].p
) {
151 this.addPincerCaptures(moves
);
154 this.addCoordinatorCaptures(moves
);
157 const [x
, y
] = [moves
[0].start
.x
, moves
[0].start
.y
];
158 moves
= moves
.concat(this.getLeaperCaptures([x
, y
]));
161 moves
= this.getChameleonCaptures(moves
, "pull");
164 this.addPushmePullyouCaptures(moves
, false, "pull");