1 // TODO: bishop OK, but queen should move vertical/horizontal and capture diagonally.
2 // ==> then the pawn promotion is a real promotion (enhancement).
4 import { ChessRules
} from "@/base_rules";
6 export const VariantRules
= class ShatranjRules
extends ChessRules
{
7 static get HasFlags() {
11 static get HasEnpassant() {
15 static get ElephantSteps() {
24 static GenRandInitFen() {
25 return ChessRules
.GenRandInitFen().replace("w 1111 -", "w");
28 getPotentialPawnMoves([x
, y
]) {
29 const color
= this.turn
;
31 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
32 const shiftX
= color
== "w" ? -1 : 1;
33 const startRank
= color
== "w" ? sizeX
- 2 : 1;
34 const lastRank
= color
== "w" ? 0 : sizeX
- 1;
35 // Promotion in minister (queen) only:
36 const finalPiece
= x
+ shiftX
== lastRank
? V
.QUEEN : V
.PAWN
;
38 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
41 this.getBasicMove([x
, y
], [x
+ shiftX
, y
], {
48 for (let shiftY
of [-1, 1]) {
52 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
53 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
56 this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], {
67 getPotentialBishopMoves(sq
) {
68 let moves
= this.getSlideNJumpMoves(sq
, V
.ElephantSteps
, "oneStep");
69 // Complete with "repositioning moves": like a queen, without capture
70 let repositioningMoves
= this.getSlideNJumpMoves(
74 ).filter(m
=> m
.vanish
.length
== 1);
75 return moves
.concat(repositioningMoves
);
78 getPotentialQueenMoves(sq
) {
79 return this.getSlideNJumpMoves(
86 getPotentialKingMoves(sq
) {
87 return this.getSlideNJumpMoves(
89 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
94 isAttackedByBishop(sq
, colors
) {
95 return this.isAttackedBySlideNJump(
104 isAttackedByQueen(sq
, colors
) {
105 return this.isAttackedBySlideNJump(
114 static get VALUES() {