1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
, shuffle
} from "@/utils/alea";
5 export class MakrukRules
extends ChessRules
{
7 static get HasFlags() {
11 static get HasEnpassant() {
15 static get Monochrome() {
19 static get Notoodark() {
23 static get PawnSpecs() {
27 { promotions: [V
.QUEEN
] }
32 return ChessRules
.PIECES
.concat(V
.PROMOTED
);
35 static get PROMOTED() {
39 static GenRandInitFen(randomness
) {
41 return "rnbqkbnr/8/pppppppp/8/8/PPPPPPPP/8/RNBKQBNR w 0";
43 let pieces
= { w: new Array(8), b: new Array(8) };
44 for (let c
of ["w", "b"]) {
45 if (c
== 'b' && randomness
== 1) {
46 pieces
['b'] = pieces
['w'];
50 // Get random squares for every piece, totally freely (no castling)
51 let positions
= shuffle(ArrayFun
.range(8));
52 const composition
= ['b', 'b', 'r', 'r', 'n', 'n', 'k', 'q'];
53 for (let i
= 0; i
< 8; i
++) pieces
[c
][positions
[i
]] = composition
[i
];
56 pieces
["b"].join("") +
57 "/8/pppppppp/8/8/PPPPPPPP/8/" +
58 pieces
["w"].join("").toUpperCase() +
67 getPotentialMovesFrom([x
, y
]) {
68 if (this.getPiece(x
, y
) == V
.PROMOTED
)
69 return this.getPotentialQueenMoves([x
, y
]);
70 return super.getPotentialMovesFrom([x
, y
]);
73 getPotentialPawnMoves([x
, y
]) {
74 const color
= this.turn
;
75 const shiftX
= V
.PawnSpecs
.directions
[color
];
76 const sixthRank
= (color
== 'w' ? 2 : 5);
77 const tr
= (x
+ shiftX
== sixthRank
? { p: V
.PROMOTED
, c: color
} : null);
79 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
)
81 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
], tr
));
83 for (let shiftY
of [-1, 1]) {
85 y
+ shiftY
>= 0 && y
+ shiftY
< 8 &&
86 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
87 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
89 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], tr
));
95 getPotentialBishopMoves(sq
) {
96 const forward
= (this.turn
== 'w' ? -1 : 1);
97 return this.getSlideNJumpMoves(
99 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
104 getPotentialQueenMoves(sq
) {
105 return this.getSlideNJumpMoves(
112 isAttacked(sq
, color
) {
114 super.isAttacked(sq
, color
) || this.isAttackedByPromoted(sq
, color
)
118 isAttackedByBishop(sq
, color
) {
119 const forward
= (color
== 'w' ? 1 : -1);
120 return this.isAttackedBySlideNJump(
124 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
129 isAttackedByQueen(sq
, color
) {
130 return this.isAttackedBySlideNJump(
139 isAttackedByPromoted(sq
, color
) {
140 return super.isAttackedBySlideNJump(
149 static get VALUES() {