Add Queenpawns + small fix to vs pawns variants + remove HQ inventor (webmaster but...
[vchess.git] / client / src / variants / Pacifist2.js
1 import { Pacifist1Rules } from "@/variants/Pacifist1";
2
3 export class Pacifist2Rules extends Pacifist1Rules {
4 // Sum values of white pieces attacking a square,
5 // and remove (sum of) black pieces values.
6 sumAttacks([x, y]) {
7 const getSign = (color) => {
8 return (color == 'w' ? 1 : -1);
9 };
10 let res = 0;
11 // Knights:
12 V.steps[V.KNIGHT].forEach(s => {
13 const [i, j] = [x + s[0], y + s[1]];
14 if (V.OnBoard(i, j) && this.getPiece(i, j) == V.KNIGHT)
15 res += getSign(this.getColor(i, j)) * V.VALUES[V.KNIGHT];
16 });
17 // Kings:
18 V.steps[V.ROOK].concat(V.steps[V.BISHOP]).forEach(s => {
19 const [i, j] = [x + s[0], y + s[1]];
20 if (V.OnBoard(i, j) && this.getPiece(i, j) == V.KING)
21 res += getSign(this.getColor(i, j)) * V.VALUES[V.KING];
22 });
23 // Pawns:
24 for (let c of ['w', 'b']) {
25 for (let shift of [-1, 1]) {
26 const sign = getSign(c);
27 const [i, j] = [x + sign, y + shift];
28 if (
29 V.OnBoard(i, j) &&
30 this.getPiece(i, j) == V.PAWN &&
31 this.getColor(i, j) == c
32 ) {
33 res += sign * V.VALUES[V.PAWN];
34 }
35 }
36 }
37 // Other pieces (sliders):
38 V.steps[V.ROOK].concat(V.steps[V.BISHOP]).forEach(s => {
39 let [i, j] = [x + s[0], y + s[1]];
40 let compatible = [V.QUEEN];
41 compatible.push(s[0] == 0 || s[1] == 0 ? V.ROOK : V.BISHOP);
42 let firstCol = undefined;
43 while (V.OnBoard(i, j)) {
44 if (this.board[i][j] != V.EMPTY) {
45 const pieceIJ = this.getPiece(i, j);
46 if (!(compatible.includes(pieceIJ))) break;
47 const colIJ = this.getColor(i, j);
48 if (!firstCol) firstCol = colIJ;
49 if (colIJ == firstCol) res += getSign(colIJ) * V.VALUES[pieceIJ];
50 else break;
51 }
52 i += s[0];
53 j += s[1];
54 }
55 });
56 return res;
57 }
58 };