1 import { ArrayFun
} from "@/utils/array";
2 import { randInt
, shuffle
} from "@/utils/alea";
3 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
5 export const VariantRules
= class EightpiecesRules
extends ChessRules
{
17 return ChessRules
.PIECES
.concat([V
.JAILER
, V
.SENTRY
, V
.LANCER
]);
20 static get LANCER_DIRS() {
34 const piece
= this.board
[i
][j
].charAt(1);
35 // Special lancer case: 8 possible orientations
36 if (Object
.keys(V
.LANCER_DIRS
).includes(piece
)) return V
.LANCER
;
42 ([V
.JAILER
, V
.SENTRY
, V
.LANCER
].includes(b
[1])
43 ? "Eightpieces/" : "") + b
47 setOtherVariables(fen
) {
48 super.setOtherVariables(fen
);
49 // subTurn == 2 only when a sentry moved, and is about to push something
51 // Stack pieces' forbidden squares after a sentry move at each turn
55 canTake([x1
,y1
], [x2
, y2
]) {
56 if (this.subTurn
== 2)
57 // Sentry push: pieces can capture own color (only)
58 return this.getColor(x1
, y1
) == this.getColor(x2
, y2
);
59 return super.canTake([x1
,y1
], [x2
, y2
]);
62 static GenRandInitFen(randomness
) {
63 // TODO: special conditions
66 // TODO: rook + jailer
68 this.kingPos
= { w: [-1, -1], b: [-1, -1] };
69 const fenRows
= V
.ParseFen(fen
).position
.split("/");
70 for (let i
= 0; i
< fenRows
.length
; i
++) {
71 let k
= 0; //column index on board
72 for (let j
= 0; j
< fenRows
[i
].length
; j
++) {
73 switch (fenRows
[i
].charAt(j
)) {
76 this.kingPos
["b"] = [i
, k
];
80 this.kingPos
["w"] = [i
, k
];
83 const num
= parseInt(fenRows
[i
].charAt(j
));
84 if (!isNaN(num
)) k
+= num
- 1;
92 getPotentialMovesFrom([x
,y
]) {
93 // if subTurn == 2, allow only
96 // getPotentialMoves, isAttacked: TODO
97 getPotentialCastleMoves(sq
) { //TODO: adapt, with jailer
100 updateVariables(move) {
101 // TODO: stack sentryPath if subTurn == 2 --> all squares between move.start et move.end, sauf si c'est un pion
104 // TODO: special pass move: take jailer with king
106 // subTurn : if sentry moved to some enemy piece --> enregistrer déplacement sentry, subTurn == 2, puis déplacer pièce adverse --> 1st 1/2 of turn, vanish sentry tout simplement.
107 // --> le turn ne change pas !
108 // 2nd half: move only
109 // FEN flag: sentryPath from init pushing to final enemy square --> forbid some moves (getPotentialMoves)
111 static get VALUES() {
112 return Object
.assign(
113 { l: 4.8, s: 2.8, j: 3.8 }, //Jeff K. estimations