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 | ||
2c947b3a BA |
34 | getPotentialPawnMoves([x, y]) { |
35 | const c = this.getColor(x, y); | |
36 | const shiftX = (c == 'w' ? -1 : 1); | |
37 | const lastRank = (c == 'w' && x == 0 || c == 'b' && x == 6); | |
38 | let steps = []; | |
39 | if (!lastRank) steps.push([shiftX, 0]); | |
40 | if (y > 0) steps.push([0, -1]); | |
41 | if (y < 9) steps.push([0, 1]); | |
4313762d | 42 | return super.getSlideNJumpMoves([x, y], steps, 1); |
2c947b3a BA |
43 | } |
44 | ||
45 | insidePalace(x, y, c) { | |
46 | return ( | |
47 | (y >= 2 && y <= 4) && | |
48 | ( | |
49 | (c == 'w' && x >= 4) || | |
50 | (c == 'b' && x <= 2) | |
51 | ) | |
52 | ); | |
53 | } | |
54 | ||
55 | static get VALUES() { | |
56 | return { | |
57 | p: 2, | |
58 | r: 9, | |
59 | n: 4, | |
60 | c: 4.5, | |
61 | k: 1000 | |
62 | }; | |
63 | } | |
64 | ||
65 | // Back to ChessRules method: | |
66 | evalPosition() { | |
67 | let evaluation = 0; | |
68 | for (let i = 0; i < V.size.x; i++) { | |
69 | for (let j = 0; j < V.size.y; j++) { | |
ded43c88 BA |
70 | if (this.board[i][j] != V.EMPTY) { |
71 | const sign = this.getColor(i, j) == "w" ? 1 : -1; | |
72 | evaluation += sign * V.VALUES[this.getPiece(i, j)]; | |
73 | } | |
2c947b3a BA |
74 | } |
75 | } | |
76 | return evaluation; | |
77 | } | |
78 | ||
1269441e BA |
79 | static get SEARCH_DEPTH() { |
80 | return 3; | |
81 | } | |
82 | ||
2c947b3a BA |
83 | // Also no randomization here |
84 | static GenRandInitFen() { | |
85 | return "rcnkncr/p1ppp1p/7/7/7/P1PPP1P/RCNKNCR w 0"; | |
86 | } | |
87 | ||
88 | }; |