1 import GiveawayRules
from "/variants/Giveaway/class.js";
2 import AbstractSpecialCaptureRules
from "/variants/_SpecialCaptures.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 if (this.options
["randomness"] == 0)
37 return "rnbkqbnm/pppppppp/8/8/8/8/PPPPPPPP/MNBQKBNR";
38 const options
= Object
.assign({mode: "suicide"}, this.options
);
39 const gr
= new GiveawayRules({options: options
, genFenOnly: true});
40 let res
= gr
.genRandInitBaseFen();
42 for (let c
of ['w', 'b']) {
43 const rookChar
= (c
== 'w' ? 'R' : 'r');
44 switch (Random
.randInt(2)) {
46 immPos
[c
] = res
.fen
.indexOf(rookChar
);
49 immPos
[c
] = res
.fen
.lastIndexOf(rookChar
);
53 res
.fen
= res
.fen
.substring(0, immPos
['b']) + 'i' +
54 res
.fen
.substring(immPos
['b'] + 1, immPos
['w']) + 'I' +
55 res
.fen
.substring(immPos
['w'] + 1);
60 return Object
.assign({},
64 "class": "pawn", //pincer
66 {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
70 "class": "rook", //coordinator
74 [1, 0], [0, 1], [-1, 0], [0, -1],
75 [1, 1], [1, -1], [-1, 1], [-1, -1]
81 "class": "knight", //long-leaper
85 "class": "bishop", //chameleon
89 "class": "queen", //withdrawer
93 "class": "immobilizer",
100 // Is piece on square (x,y) immobilized?
101 isImmobilized([x
, y
]) {
102 const piece
= this.getPiece(x
, y
);
103 const color
= this.getColor(x
, y
);
104 const oppCol
= C
.GetOppCol(color
);
105 const adjacentSteps
= this.pieces()['k'].moves
[0].steps
;
106 for (let step
of adjacentSteps
) {
107 const [i
, j
] = [x
+ step
[0], this.getY(y
+ step
[1])];
109 this.onBoard(i
, j
) &&
110 this.board
[i
][j
] != "" &&
111 this.getColor(i
, j
) == oppCol
113 const oppPiece
= this.getPiece(i
, j
);
114 if (oppPiece
== 'i') {
115 // Moving is possible only if this immobilizer is neutralized
116 for (let step2
of adjacentSteps
) {
117 const [i2
, j2
] = [i
+ step2
[0], this.getY(j
+ step2
[1])];
118 if (i2
== x
&& j2
== y
)
119 continue; //skip initial piece!
121 this.onBoard(i2
, j2
) &&
122 this.board
[i2
][j2
] != "" &&
123 this.getColor(i2
, j2
) == color
125 if (['b', 'i'].includes(this.getPiece(i2
, j2
)))
129 return true; //immobilizer isn't neutralized
131 // Chameleons can't be immobilized twice,
132 // because there is only one immobilizer
133 if (oppPiece
== 'b' && piece
== 'i')
140 canTake([x1
, y1
], [x2
, y2
]) {
141 // Deactivate standard captures, except for king:
143 this.getPiece(x1
, y1
) == 'k' &&
144 this.getColor(x1
, y1
) != this.getColor(x2
, y2
)
148 postProcessPotentialMoves(moves
) {
149 if (moves
.length
== 0)
151 switch (moves
[0].vanish
[0].p
) {
153 this.addPincerCaptures(moves
);
156 this.addCoordinatorCaptures(moves
);
159 const [x
, y
] = [moves
[0].start
.x
, moves
[0].start
.y
];
160 moves
= moves
.concat(this.getLeaperCaptures([x
, y
]));
163 moves
= this.getChameleonCaptures(moves
, "pull");
166 this.addPushmePullyouCaptures(moves
, false, "pull");