1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
} from "@/utils/alea";
5 export class CwdaRules
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]))
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
)) {
66 case V
.C_ROOK: return this.getPotentialC_rookMoves([x
, y
]);
67 case V
.C_KNIGHT: return this.getPotentialC_knightMoves([x
, y
]);
68 case V
.C_BISHOP: return this.getPotentialC_bishopMoves([x
, y
]);
69 case V
.C_QUEEN: return this.getPotentialC_queenMoves([x
, y
]);
70 default: return super.getPotentialMovesFrom([x
, y
]);
105 getPotentialC_rookMoves(sq
) {
107 this.getSlideNJumpMoves(sq
, V
.steps
[V
.BISHOP
]).concat(
108 this.getSlideNJumpMoves(sq
, V
.steps
['d'], "oneStep"))
112 getPotentialC_knightMoves(sq
) {
114 this.getSlideNJumpMoves(sq
, V
.steps
['a'], "oneStep").concat(
115 this.getSlideNJumpMoves(sq
, V
.steps
[V
.ROOK
], "oneStep"))
119 getPotentialC_bishopMoves(sq
) {
121 this.getSlideNJumpMoves(sq
, V
.steps
['d'], "oneStep").concat(
122 this.getSlideNJumpMoves(sq
, V
.steps
['a'], "oneStep")).concat(
123 this.getSlideNJumpMoves(sq
, V
.steps
[V
.BISHOP
], "oneStep"))
127 getPotentialC_queenMoves(sq
) {
129 this.getSlideNJumpMoves(sq
, V
.steps
[V
.BISHOP
]).concat(
130 this.getSlideNJumpMoves(sq
, V
.steps
[V
.KNIGHT
], "oneStep"))
134 getCastleMoves([x
, y
]) {
135 const color
= this.getColor(x
, y
);
136 const finalSquares
= [
137 // Black castle long in an unusual way:
138 (color
== 'w' ? [2, 3] : [1, 2]),
139 [V
.size
.y
- 2, V
.size
.y
- 3]
141 return super.getCastleMoves([x
, y
], finalSquares
);
144 isAttacked(sq
, color
) {
146 super.isAttacked(sq
, color
) ||
147 this.isAttackedByC_rook(sq
, color
) ||
148 this.isAttackedByC_knight(sq
, color
) ||
149 this.isAttackedByC_bishop(sq
, color
) ||
150 this.isAttackedByC_queen(sq
, color
)
154 isAttackedByC_rook(sq
, color
) {
156 this.isAttackedBySlideNJump(sq
, color
, V
.C_ROOK
, V
.steps
[V
.BISHOP
]) ||
157 this.isAttackedBySlideNJump(
158 sq
, color
, V
.C_ROOK
, V
.steps
['d'], "oneStep")
162 isAttackedByC_knight(sq
, color
) {
164 this.isAttackedBySlideNJump(
165 sq
, color
, V
.C_KNIGHT
, V
.steps
[V
.ROOK
], "oneStep") ||
166 this.isAttackedBySlideNJump(
167 sq
, color
, V
.C_KNIGHT
, V
.steps
['a'], "oneStep")
171 isAttackedByC_bishop(sq
, color
) {
173 this.isAttackedBySlideNJump(
174 sq
, color
, V
.C_BISHOP
, V
.steps
['d'], "oneStep") ||
175 this.isAttackedBySlideNJump(
176 sq
, color
, V
.C_BISHOP
, V
.steps
['a'], "oneStep") ||
177 this.isAttackedBySlideNJump(
178 sq
, color
, V
.C_BISHOP
, V
.steps
['f'], "oneStep")
182 isAttackedByC_queen(sq
, color
) {
184 this.isAttackedBySlideNJump(sq
, color
, V
.C_QUEEN
, V
.steps
[V
.BISHOP
]) ||
185 this.isAttackedBySlideNJump(
186 sq
, color
, V
.C_QUEEN
, V
.steps
[V
.KNIGHT
], "oneStep")
190 static get VALUES() {
191 return Object
.assign(
203 static get SEARCH_DEPTH() {