1 import { Pacifist1Rules
} from "@/variants/Pacifist1";
3 export class Pacifist2Rules
extends Pacifist1Rules
{
5 // Sum values of white pieces attacking a square,
6 // and remove (sum of) black pieces values.
8 const getSign
= (color
) => {
9 return (color
== 'w' ? 1 : -1);
13 V
.steps
[V
.KNIGHT
].forEach(s
=> {
14 const [i
, j
] = [x
+ s
[0], y
+ s
[1]];
15 if (V
.OnBoard(i
, j
) && this.getPiece(i
, j
) == V
.KNIGHT
)
16 res
+= getSign(this.getColor(i
, j
)) * V
.VALUES
[V
.KNIGHT
];
19 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]).forEach(s
=> {
20 const [i
, j
] = [x
+ s
[0], y
+ s
[1]];
21 if (V
.OnBoard(i
, j
) && this.getPiece(i
, j
) == V
.KING
)
22 res
+= getSign(this.getColor(i
, j
)) * V
.VALUES
[V
.KING
];
25 for (let c
of ['w', 'b']) {
26 for (let shift
of [-1, 1]) {
27 const sign
= getSign(c
);
28 const [i
, j
] = [x
+ sign
, y
+ shift
];
31 this.getPiece(i
, j
) == V
.PAWN
&&
32 this.getColor(i
, j
) == c
34 res
+= sign
* V
.VALUES
[V
.PAWN
];
38 // Other pieces (sliders):
39 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]).forEach(s
=> {
40 let [i
, j
] = [x
+ s
[0], y
+ s
[1]];
41 let compatible
= [V
.QUEEN
];
42 compatible
.push(s
[0] == 0 || s
[1] == 0 ? V
.ROOK : V
.BISHOP
);
43 let firstCol
= undefined;
44 while (V
.OnBoard(i
, j
)) {
45 if (this.board
[i
][j
] != V
.EMPTY
) {
46 const pieceIJ
= this.getPiece(i
, j
);
47 if (!(compatible
.includes(pieceIJ
))) break;
48 const colIJ
= this.getColor(i
, j
);
49 if (!firstCol
) firstCol
= colIJ
;
50 if (colIJ
== firstCol
) res
+= getSign(colIJ
) * V
.VALUES
[pieceIJ
];