// or if move.end.x == enemy king rank.
const color = this.getColor(sq[0], sq[1]);
const oppCol = V.GetOppCol(color);
- // check == -1 if (row, or col) unchecked, 1 if checked and occupied,
- // 0 if checked and clear
- let check = [-1, -1];
return moves.filter(m => {
if (
m.end.y != this.kingPos[oppCol][1] &&
) {
return true;
}
+ // check == -1 if (row, or col) unchecked, 1 if checked and occupied,
+ // 0 if checked and clear
+ let check = [-1, -1];
// TODO: factor two next "if"...
if (m.end.x == this.kingPos[oppCol][0]) {
if (check[0] < 0) {
// Do the check:
check[0] = 0;
- let [kingPos1, kingPos2] =
- [this.kingPos[color][1], this.kingPos[oppCol][1]];
+ let [kingPos1, kingPos2] = [m.end.y, this.kingPos[oppCol][1]];
if (kingPos1 > kingPos2) [kingPos1, kingPos2] = [kingPos2, kingPos1];
for (let i = kingPos1 + 1; i < kingPos2; i++) {
if (this.board[m.end.x][i] != V.EMPTY) {
if (check[1] < 0) {
// Do the check:
check[1] = 0;
- let [kingPos1, kingPos2] =
- [this.kingPos[color][0], this.kingPos[oppCol][0]];
+ let [kingPos1, kingPos2] = [m.end.x, this.kingPos[oppCol][0]];
if (kingPos1 > kingPos2) [kingPos1, kingPos2] = [kingPos2, kingPos1];
for (let i = kingPos1 + 1; i < kingPos2; i++) {
if (this.board[i][m.end.y] != V.EMPTY) {
let i = x + step[0];
let j = y + step[1];
while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
- moves.push(this.getBasicMove([x, y], [i, j]));
i += step[0];
j += step[1];
}
i += step[0];
j += step[1];
while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
+ moves.push(this.getBasicMove([x, y], [i, j]));
i += step[0];
j += step[1];
}
evalPosition() {
let evaluation = super.evalPosition();
- if (this.turn == 'b')
+ if (this.turn == 'b' && !!this.reserve)
// Add reserves:
evaluation += this.reserve['b'][V.SOLDIER] * V.VALUES[V.SOLDIER];
return evaluation;