1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
} from "@/utils/alea";
5 export class ColorboundRules
extends ChessRules
{
7 static get PawnSpecs() {
13 ChessRules
.PawnSpecs
.promotions
.concat(
14 [V
.C_ROOK
, V
.C_KNIGHT
, V
.C_BISHOP
, V
.C_QUEEN
])
20 if ([V
.C_ROOK
, V
.C_KNIGHT
, V
.C_BISHOP
, V
.C_QUEEN
].includes(b
[1]))
21 return "Colorbound/" + b
;
25 static GenRandInitFen(randomness
) {
27 return "dhaskahd/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 ahah -";
29 // Mapping white --> black (at least at start):
38 const baseFen
= ChessRules
.GenRandInitFen(randomness
);
40 baseFen
.substr(0, 8).split('').map(p
=> piecesMap
[p
]).join('') +
48 static get C_KNIGHT() {
51 static get C_BISHOP() {
54 static get C_QUEEN() {
60 ChessRules
.PIECES
.concat([V
.C_ROOK
, V
.C_KNIGHT
, V
.C_BISHOP
, V
.C_QUEEN
])
64 getPotentialMovesFrom([x
, y
]) {
65 switch (this.getPiece(x
, y
)) {
67 return this.getPotentialC_rookMoves([x
, y
]);
69 return this.getPotentialC_knightMoves([x
, y
]);
71 return this.getPotentialC_bishopMoves([x
, y
]);
73 return this.getPotentialC_queenMoves([x
, y
]);
75 return super.getPotentialMovesFrom([x
, y
]);
110 getPotentialC_rookMoves(sq
) {
112 this.getSlideNJumpMoves(sq
, V
.steps
[V
.BISHOP
]).concat(
113 this.getSlideNJumpMoves(sq
, V
.steps
['d'], "oneStep"))
117 getPotentialC_knightMoves(sq
) {
119 this.getSlideNJumpMoves(sq
, V
.steps
['a'], "oneStep").concat(
120 this.getSlideNJumpMoves(sq
, V
.steps
[V
.ROOK
], "oneStep"))
124 getPotentialC_bishopMoves(sq
) {
126 this.getSlideNJumpMoves(sq
, V
.steps
['d'], "oneStep").concat(
127 this.getSlideNJumpMoves(sq
, V
.steps
['a'], "oneStep")).concat(
128 this.getSlideNJumpMoves(sq
, V
.steps
[V
.BISHOP
], "oneStep"))
132 getPotentialC_queenMoves(sq
) {
134 this.getSlideNJumpMoves(sq
, V
.steps
[V
.BISHOP
]).concat(
135 this.getSlideNJumpMoves(sq
, V
.steps
[V
.KNIGHT
], "oneStep"))
139 getCastleMoves([x
, y
]) {
140 const color
= this.getColor(x
, y
);
141 const finalSquares
= [
142 // Black castle long in an unusual way:
143 (color
== 'w' ? [2, 3] : [1, 2]),
144 [V
.size
.y
- 2, V
.size
.y
- 3]
146 return super.getCastleMoves([x
, y
], finalSquares
);
149 isAttacked(sq
, color
) {
151 super.isAttacked(sq
, color
) ||
152 this.isAttackedByC_rook(sq
, color
) ||
153 this.isAttackedByC_knight(sq
, color
) ||
154 this.isAttackedByC_bishop(sq
, color
) ||
155 this.isAttackedByC_queen(sq
, color
)
159 isAttackedByC_rook(sq
, color
) {
161 this.isAttackedBySlideNJump(sq
, color
, V
.C_ROOK
, V
.steps
[V
.BISHOP
]) ||
162 this.isAttackedBySlideNJump(
163 sq
, color
, V
.C_ROOK
, V
.steps
['d'], "oneStep")
167 isAttackedByC_knight(sq
, color
) {
169 this.isAttackedBySlideNJump(
170 sq
, color
, V
.C_KNIGHT
, V
.steps
[V
.ROOK
], "oneStep") ||
171 this.isAttackedBySlideNJump(
172 sq
, color
, V
.C_KNIGHT
, V
.steps
['a'], "oneStep")
176 isAttackedByC_bishop(sq
, color
) {
178 this.isAttackedBySlideNJump(
179 sq
, color
, V
.C_BISHOP
, V
.steps
['d'], "oneStep") ||
180 this.isAttackedBySlideNJump(
181 sq
, color
, V
.C_BISHOP
, V
.steps
['a'], "oneStep") ||
182 this.isAttackedBySlideNJump(
183 sq
, color
, V
.C_BISHOP
, V
.steps
['f'], "oneStep")
187 isAttackedByC_queen(sq
, color
) {
189 this.isAttackedBySlideNJump(sq
, color
, V
.C_QUEEN
, V
.steps
[V
.BISHOP
]) ||
190 this.isAttackedBySlideNJump(
191 sq
, color
, V
.C_QUEEN
, V
.steps
[V
.KNIGHT
], "oneStep")
195 static get VALUES() {
196 return Object
.assign(
208 static get SEARCH_DEPTH() {