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 PawnSpecs() {
23 { promotions: [V
.QUEEN
] }
28 return ChessRules
.PIECES
.concat(V
.PROMOTED
);
31 static get PROMOTED() {
35 static GenRandInitFen(randomness
) {
37 return "rnbqkbnr/8/pppppppp/8/8/PPPPPPPP/8/RNBKQBNR w 0";
39 let pieces
= { w: new Array(8), b: new Array(8) };
40 for (let c
of ["w", "b"]) {
41 if (c
== 'b' && randomness
== 1) {
42 pieces
['b'] = pieces
['w'];
46 // Get random squares for every piece, totally freely (no castling)
47 let positions
= shuffle(ArrayFun
.range(8));
48 const composition
= ['b', 'b', 'r', 'r', 'n', 'n', 'k', 'q'];
49 for (let i
= 0; i
< 8; i
++) pieces
[c
][positions
[i
]] = composition
[i
];
52 pieces
["b"].join("") +
53 "/8/pppppppp/8/8/PPPPPPPP/8/" +
54 pieces
["w"].join("").toUpperCase() +
63 getPotentialMovesFrom([x
, y
]) {
64 if (this.getPiece(x
, y
) == V
.PROMOTED
)
65 return this.getPotentialQueenMoves([x
, y
]);
66 return super.getPotentialMovesFrom([x
, y
]);
69 getPotentialPawnMoves([x
, y
]) {
70 const color
= this.turn
;
71 const shiftX
= V
.PawnSpecs
.directions
[color
];
72 const sixthRank
= (color
== 'w' ? 2 : 5);
73 const tr
= (x
+ shiftX
== sixthRank
? { p: V
.PROMOTED
, c: color
} : null);
75 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
)
77 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
], tr
));
79 for (let shiftY
of [-1, 1]) {
81 y
+ shiftY
>= 0 && y
+ shiftY
< 8 &&
82 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
83 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
85 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], tr
));
91 getPotentialBishopMoves(sq
) {
92 const forward
= (this.turn
== 'w' ? -1 : 1);
93 return this.getSlideNJumpMoves(
95 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
100 getPotentialQueenMoves(sq
) {
101 return this.getSlideNJumpMoves(
108 isAttackedByBishop(sq
, color
) {
109 const forward
= (color
== 'w' ? 1 : -1);
110 return this.isAttackedBySlideNJump(
114 V
.steps
[V
.BISHOP
].concat([ [forward
, 0] ]),
119 isAttackedByQueen(sq
, color
) {
120 return this.isAttackedBySlideNJump(
129 static get VALUES() {