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(options
) {
15 const antikingFen
= Antiking2Rules
.GenRandInitFen(options
);
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
], 1)
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
);
61 const lastRank
= (c
== 'w' ? 0 : 7);
62 if (p
!= V
.KING
&& (p
!= V
.PAWN
|| x
!= lastRank
)) {
66 new PiPo({ x: x
, y: y
, c: c
, p: V
.JOKER
}),
67 new PiPo({ x: i
, y: j
, c: c
, p: p
})
70 new PiPo({ x: i
, y: j
, c: c
, p: V
.JOKER
}),
71 new PiPo({ x: x
, y: y
, c: c
, p: p
})
79 return moving
.concat(swapping
);
84 // Was my king swapped?
85 if (move.vanish
.length
== 2 && move.vanish
[1].p
== V
.KING
)
86 this.kingPos
[move.appear
[1].c
] = [move.appear
[1].x
, move.appear
[1].y
];
91 if (move.vanish
.length
== 2 && move.vanish
[1].p
== V
.KING
)
92 this.kingPos
[move.vanish
[1].c
] = [move.vanish
[1].x
, move.vanish
[1].y
];
96 return Object
.assign({ j: 2 }, ChessRules
.VALUES
);
99 static get SEARCH_DEPTH() {