Some fixes + draft Avalanche
[vchess.git] / client / src / variants / Minixiangqi.js
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 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]);
42 return super.getSlideNJumpMoves([x, y], steps, "oneStep");
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++) {
70 if (this.board[i][j] != V.EMPTY)
71 evaluation += (c == 'w' ? 1 : -1) * V.VALUES[this.getPiece(i, j)];
72 }
73 }
74 return evaluation;
75 }
76
77 static get SEARCH_DEPTH() {
78 return 3;
79 }
80
81 // Also no randomization here
82 static GenRandInitFen() {
83 return "rcnkncr/p1ppp1p/7/7/7/P1PPP1P/RCNKNCR w 0";
84 }
85
86 };