1 import ChessRules
from "/base_rules.js";
2 import GiveawayRules
from "/variants/Giveaway/class.js";
3 import AbstractSpecialCaptureRules
from "/variants/_SpecialCaptures.js";
4 import {Random
} from "/utils/alea.js";
5 import PiPo
from "/utils/PiPo.js";
6 import Move
from "/utils/Move.js";
8 export default class BaroqueRules
extends AbstractSpecialCaptureRules
{
10 static get Options() {
12 select: C
.Options
.Select
,
15 label: "Capture king",
38 genRandInitBaseFen() {
39 if (this.options
["randomness"] == 0)
40 return "rnbkqbnm/pppppppp/8/8/8/8/PPPPPPPP/MNBQKBNR";
41 const options
= Object
.assign({mode: "suicide"}, this.options
);
42 const gr
= new GiveawayRules({options: options
, genFenOnly: true});
43 let res
= gr
.genRandInitBaseFen();
45 for (let c
of ['w', 'b']) {
46 const rookChar
= (c
== 'w' ? 'R' : 'r');
47 switch (Random
.randInt(2)) {
49 immPos
[c
] = res
.fen
.indexOf(rookChar
);
52 immPos
[c
] = res
.fen
.lastIndexOf(rookChar
);
56 res
.fen
= res
.fen
.substring(0, immPos
['b']) + 'i' +
57 res
.fen
.substring(immPos
['b'] + 1, immPos
['w']) + 'I' +
58 res
.fen
.substring(immPos
['w'] + 1);
63 return Object
.assign({},
67 "class": "pawn", //pincer
69 {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
73 "class": "rook", //coordinator
77 [1, 0], [0, 1], [-1, 0], [0, -1],
78 [1, 1], [1, -1], [-1, 1], [-1, -1]
84 "class": "knight", //long-leaper
88 "class": "bishop", //chameleon
92 "class": "queen", //withdrawer
96 "class": "immobilizer",
103 // Is piece on square (x,y) immobilized?
104 isImmobilized([x
, y
]) {
105 const piece
= this.getPiece(x
, y
);
106 const color
= this.getColor(x
, y
);
107 const oppCol
= C
.GetOppCol(color
);
108 const adjacentSteps
= this.pieces()['k'].moves
[0].steps
;
109 for (let step
of adjacentSteps
) {
110 const [i
, j
] = [x
+ step
[0], this.getY(y
+ step
[1])];
112 this.onBoard(i
, j
) &&
113 this.board
[i
][j
] != "" &&
114 this.getColor(i
, j
) == oppCol
116 const oppPiece
= this.getPiece(i
, j
);
117 if (oppPiece
== 'i') {
118 // Moving is possible only if this immobilizer is neutralized
119 for (let step2
of adjacentSteps
) {
120 const [i2
, j2
] = [i
+ step2
[0], this.getY(j
+ step2
[1])];
121 if (i2
== x
&& j2
== y
)
122 continue; //skip initial piece!
124 this.onBoard(i2
, j2
) &&
125 this.board
[i2
][j2
] != "" &&
126 this.getColor(i2
, j2
) == color
128 if (['b', 'i'].includes(this.getPiece(i2
, j2
)))
132 return true; //immobilizer isn't neutralized
134 // Chameleons can't be immobilized twice,
135 // because there is only one immobilizer
136 if (oppPiece
== 'b' && piece
== 'i')
143 canTake([x1
, y1
], [x2
, y2
]) {
144 // Deactivate standard captures, except for king:
146 this.getPiece(x1
, y1
) == 'k' &&
147 this.getColor(x1
, y1
) != this.getColor(x2
, y2
)
151 postProcessPotentialMoves(moves
) {
152 if (moves
.length
== 0)
154 switch (moves
[0].vanish
[0].p
) {
156 this.addPincerCaptures(moves
);
159 this.addCoordinatorCaptures(moves
);
162 const [x
, y
] = [moves
[0].start
.x
, moves
[0].start
.y
];
163 moves
= moves
.concat(this.getLeaperCaptures([x
, y
]));
166 moves
= this.getChameleonCaptures(moves
, "pull");
169 this.addPushmePullyouCaptures(moves
, false, "pull");