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 Monochrome() {
18 static get PawnSpecs() {
22 { promotions: [V
.QUEEN
] }
27 return ChessRules
.PIECES
.concat(V
.PROMOTED
);
30 static get PROMOTED() {
34 static GenRandInitFen(randomness
) {
36 return "rnbqkbnr/8/pppppppp/8/8/PPPPPPPP/8/RNBKQBNR w 0";
38 let pieces
= { w: new Array(8), b: new Array(8) };
39 for (let c
of ["w", "b"]) {
40 if (c
== 'b' && randomness
== 1) {
41 pieces
['b'] = pieces
['w'];
45 // Get random squares for every piece, totally freely (no castling)
46 let positions
= shuffle(ArrayFun
.range(8));
47 const composition
= ['b', 'b', 'r', 'r', 'n', 'n', 'k', 'q'];
48 for (let i
= 0; i
< 8; i
++) pieces
[c
][positions
[i
]] = composition
[i
];
51 pieces
["b"].join("") +
52 "/8/pppppppp/8/8/PPPPPPPP/8/" +
53 pieces
["w"].join("").toUpperCase() +
62 getPotentialMovesFrom([x
, y
]) {
63 if (this.getPiece(x
, y
) == V
.PROMOTED
)
64 return this.getPotentialQueenMoves([x
, y
]);
65 return super.getPotentialMovesFrom([x
, y
]);
68 getPotentialPawnMoves([x
, y
]) {
69 const color
= this.turn
;
70 const shiftX
= V
.PawnSpecs
.directions
[color
];
71 const sixthRank
= (color
== 'w' ? 2 : 5);
72 const tr
= (x
+ shiftX
== sixthRank
? { p: V
.PROMOTED
, c: color
} : null);
74 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
)
76 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
], tr
));
78 for (let shiftY
of [-1, 1]) {
80 y
+ shiftY
>= 0 && y
+ shiftY
< 8 &&
81 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
82 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
84 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], tr
));
90 getPotentialBishopMoves(sq
) {
91 const forward
= (this.turn
== 'w' ? -1 : 1);
92 return this.getSlideNJumpMoves(
94 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
99 getPotentialQueenMoves(sq
) {
100 return this.getSlideNJumpMoves(
107 isAttackedByBishop(sq
, color
) {
108 const forward
= (color
== 'w' ? 1 : -1);
109 return this.isAttackedBySlideNJump(
113 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
118 isAttackedByQueen(sq
, color
) {
119 return this.isAttackedBySlideNJump(
128 static get VALUES() {