1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
2 import { XiangqiRules
} from "@/variants/Xiangqi"
4 export class MinixiangqiRules
extends XiangqiRules
{
8 // Draw all inter-squares lines, shifted:
9 for (let i
= 0; i
< V
.size
.x
; i
++)
10 lines
.push([[i
+0.5, 0.5], [i
+0.5, V
.size
.y
-0.5]]);
11 for (let j
= 0; j
< V
.size
.y
; j
++)
12 lines
.push([[0.5, j
+0.5], [V
.size
.x
-0.5, j
+0.5]]);
14 lines
.push([[0.5, 2.5], [2.5, 4.5]]);
15 lines
.push([[0.5, 4.5], [2.5, 2.5]]);
16 lines
.push([[4.5, 2.5], [6.5, 4.5]]);
17 lines
.push([[4.5, 4.5], [6.5, 2.5]]);
21 // No elephants or advisors
23 return [V
.PAWN
, V
.ROOK
, V
.KNIGHT
, V
.KING
, V
.CANNON
];
27 return "Xiangqi/" + b
;
34 getPotentialMovesFrom(sq
) {
35 switch (this.getPiece(sq
[0], sq
[1])) {
36 case V
.PAWN: return this.getPotentialPawnMoves(sq
);
37 case V
.ROOK: return super.getPotentialRookMoves(sq
);
38 case V
.KNIGHT: return super.getPotentialKnightMoves(sq
);
39 case V
.KING: return super.getPotentialKingMoves(sq
);
40 case V
.CANNON: return super.getPotentialCannonMoves(sq
);
42 return []; //never reached
45 getPotentialPawnMoves([x
, y
]) {
46 const c
= this.getColor(x
, y
);
47 const shiftX
= (c
== 'w' ? -1 : 1);
48 const lastRank
= (c
== 'w' && x
== 0 || c
== 'b' && x
== 6);
50 if (!lastRank
) steps
.push([shiftX
, 0]);
51 if (y
> 0) steps
.push([0, -1]);
52 if (y
< 9) steps
.push([0, 1]);
53 return super.getSlideNJumpMoves([x
, y
], steps
, "oneStep");
56 insidePalace(x
, y
, c
) {
60 (c
== 'w' && x
>= 4) ||
76 // Back to ChessRules method:
79 for (let i
= 0; i
< V
.size
.x
; i
++) {
80 for (let j
= 0; j
< V
.size
.y
; j
++) {
81 if (this.board
[i
][j
] != V
.EMPTY
)
82 evaluation
+= (c
== 'w' ? 1 : -1) * V
.VALUES
[this.getPiece(i
, j
)];
88 // Also no randomization here
89 static GenRandInitFen() {
90 return "rcnkncr/p1ppp1p/7/7/7/P1PPP1P/RCNKNCR w 0";