1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
2 import { Antiking2Rules
} from "@/variants/Antiking2";
4 export class JokerRules
extends ChessRules
{
6 static get PawnSpecs() {
10 { promotions: ChessRules
.PawnSpecs
.promotions
.concat([V
.JOKER
]) }
14 static GenRandInitFen(randomness
) {
15 const antikingFen
= Antiking2Rules
.GenRandInitFen(randomness
);
16 return antikingFen
.replace('a', 'J').replace('A', 'j');
24 return ChessRules
.PIECES
.concat([V
.JOKER
]);
28 return (b
.charAt(1) == 'j' ? "Joker/" : "") + b
;
31 getPotentialMovesFrom([x
, y
]) {
32 const piece
= this.getPiece(x
, y
);
33 if (piece
== V
.JOKER
) return this.getPotentialJokerMoves([x
, y
]);
34 let moves
= super.getPotentialMovesFrom([x
, y
]);
35 if (piece
== V
.PAWN
) {
37 const alreadyOneJoker
= this.board
.some(row
=>
38 row
.some(cell
=> cell
== c
+ 'j'));
39 if (alreadyOneJoker
) moves
= moves
.filter(m
=> m
.appear
[0].p
!= V
.JOKER
)
44 canTake([x1
, y1
], [x2
, y2
]) {
45 if (this.getPiece(x1
, y1
) == V
.JOKER
) return false;
46 return super.canTake([x1
, y1
], [x2
, y2
]);
49 getPotentialJokerMoves([x
, y
]) {
51 super.getSlideNJumpMoves([x
, y
], V
.steps
[V
.KNIGHT
], "oneStep")
52 .concat(super.getSlideNJumpMoves([x
, y
],
53 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])));
56 for (let i
=0; i
<8; i
++) {
57 for (let j
=0; j
<8; j
++) {
58 // Following test is OK because only one Joker on board at a time
59 if (this.board
[i
][j
] != V
.EMPTY
&& this.getColor(i
, j
) == c
) {
60 const p
= this.getPiece(i
, j
);
64 new PiPo({ x: x
, y: y
, c: c
, p: V
.JOKER
}),
65 new PiPo({ x: i
, y: j
, c: c
, p: p
})
68 new PiPo({ x: i
, y: j
, c: c
, p: V
.JOKER
}),
69 new PiPo({ x: x
, y: y
, c: c
, p: p
})
76 return moving
.concat(swapping
);
80 return Object
.assign({ j: 2 }, ChessRules
.VALUES
);
83 static get SEARCH_DEPTH() {