1 import { Pacifist1Rules
} from "@/variants/Pacifist1";
3 export class Pacifist2Rules
extends Pacifist1Rules
{
4 // Sum values of white pieces attacking a square,
5 // and remove (sum of) black pieces values.
7 const getSign
= (color
) => {
8 return (color
== 'w' ? 1 : -1);
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
];
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
];
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
];
30 this.getPiece(i
, j
) == V
.PAWN
&&
31 this.getColor(i
, j
) == c
33 res
+= sign
* V
.VALUES
[V
.PAWN
];
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
];