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
{
6 static get HasFlags() {
10 static get HasEnpassant() {
14 static get PawnSpecs() {
26 return ChessRules
.PIECES
.concat(V
.PROMOTED
);
29 static get PROMOTED() {
33 static GenRandInitFen(randomness
) {
35 return "rnbqkbnr/8/pppppppp/8/8/PPPPPPPP/8/RNBKQBNR w 0";
37 let pieces
= { w: new Array(8), b: new Array(8) };
38 for (let c
of ["w", "b"]) {
39 if (c
== 'b' && randomness
== 1) {
40 pieces
['b'] = pieces
['w'];
44 // Get random squares for every piece, totally freely (no castling)
45 let positions
= shuffle(ArrayFun
.range(8));
46 const composition
= ['b', 'b', 'r', 'r', 'n', 'n', 'k', 'q'];
47 for (let i
= 0; i
< 8; i
++) pieces
[c
][positions
[i
]] = composition
[i
];
50 pieces
["b"].join("") +
51 "/8/pppppppp/8/8/PPPPPPPP/8/" +
52 pieces
["w"].join("").toUpperCase() +
61 getPotentialMovesFrom([x
, y
]) {
62 if (this.getPiece(x
, y
) == V
.PROMOTED
)
63 return this.getPotentialQueenMoves([x
, y
]);
64 return super.getPotentialMovesFrom([x
, y
]);
67 getPotentialPawnMoves([x
, y
]) {
68 const color
= this.turn
;
69 const shiftX
= V
.PawnSpecs
.directions
[color
];
70 const sixthRank
= (color
== 'w' ? 2 : 5);
71 const tr
= (x
+ shiftX
== sixthRank
? { p: V
.PROMOTED
, c: color
} : null);
73 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
)
75 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
], tr
));
77 for (let shiftY
of [-1, 1]) {
79 y
+ shiftY
>= 0 && y
+ shiftY
< 8 &&
80 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
81 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
83 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], tr
));
89 getPotentialBishopMoves(sq
) {
90 const forward
= (this.turn
== 'w' ? -1 : 1);
91 return this.getSlideNJumpMoves(
93 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
98 getPotentialQueenMoves(sq
) {
99 return this.getSlideNJumpMoves(
106 isAttackedByBishop(sq
, color
) {
107 const forward
= (color
== 'w' ? 1 : -1);
108 return this.isAttackedBySlideNJump(
112 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
117 isAttackedByQueen(sq
, color
) {
118 return this.isAttackedBySlideNJump(
127 static get VALUES() {