Commit | Line | Data |
---|---|---|
2c947b3a BA |
1 | import { ChessRules, PiPo, Move } from "@/base_rules"; |
2 | import { XiangqiRules } from "@/variants/Xiangqi" | |
3 | ||
4 | export class MinixiangqiRules extends XiangqiRules { | |
5 | ||
6 | static get Lines() { | |
7 | let lines = []; | |
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]]); | |
13 | // Add palaces: | |
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]]); | |
18 | return lines; | |
19 | } | |
20 | ||
21 | // No elephants or advisors | |
22 | static get PIECES() { | |
23 | return [V.PAWN, V.ROOK, V.KNIGHT, V.KING, V.CANNON]; | |
24 | } | |
25 | ||
26 | getPpath(b) { | |
27 | return "Xiangqi/" + b; | |
28 | } | |
29 | ||
30 | static get size() { | |
31 | return { x: 7, y: 7}; | |
32 | } | |
33 | ||
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); | |
41 | } | |
42 | return []; //never reached | |
43 | } | |
44 | ||
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); | |
49 | let steps = []; | |
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"); | |
54 | } | |
55 | ||
56 | insidePalace(x, y, c) { | |
57 | return ( | |
58 | (y >= 2 && y <= 4) && | |
59 | ( | |
60 | (c == 'w' && x >= 4) || | |
61 | (c == 'b' && x <= 2) | |
62 | ) | |
63 | ); | |
64 | } | |
65 | ||
66 | static get VALUES() { | |
67 | return { | |
68 | p: 2, | |
69 | r: 9, | |
70 | n: 4, | |
71 | c: 4.5, | |
72 | k: 1000 | |
73 | }; | |
74 | } | |
75 | ||
76 | // Back to ChessRules method: | |
77 | evalPosition() { | |
78 | let evaluation = 0; | |
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)]; | |
83 | } | |
84 | } | |
85 | return evaluation; | |
86 | } | |
87 | ||
88 | // Also no randomization here | |
89 | static GenRandInitFen() { | |
90 | return "rcnkncr/p1ppp1p/7/7/7/P1PPP1P/RCNKNCR w 0"; | |
91 | } | |
92 | ||
93 | }; |