&& this.getColor(i,j) == oppCol)
{
const oppPiece = this.getPiece(i,j);
- if (oppPiece == V.BISHOP && piece == V.IMMOBILIZER)
- return true;
- if (oppPiece == V.IMMOBILIZER && ![V.BISHOP,V.IMMOBILIZER].includes(piece))
+ if (oppPiece == V.IMMOBILIZER)
{
// Moving is impossible only if this immobilizer is not neutralized
for (let step2 of adjacentSteps)
{
const [i2,j2] = [i+step2[0],j+step2[1]];
+ if (i2 == x && j2 == y)
+ continue; //skip initial piece!
if (i2>=0 && i2<sizeX && j2>=0 && j2<sizeY
&& this.board[i2][j2] != V.EMPTY && this.getColor(i2,j2) == color)
{
}
return true; //immobilizer isn't neutralized
}
+ // Chameleons can't be immobilized twice, because there is only one immobilizer
+ if (oppPiece == V.BISHOP && piece == V.IMMOBILIZER)
+ return true;
}
}
return false;
// Check piece-king rectangle (if any) corners for enemy pieces
if (m.end.x == kp[0] || m.end.y == kp[1])
return; //"flat rectangle"
- const corner1 = [Math.max(m.end.x,kp[0]), Math.min(m.end.y,kp[1])];
- const corner2 = [Math.min(m.end.x,kp[0]), Math.max(m.end.y,kp[1])];
+ const corner1 = [m.end.x, kp[1]];
+ const corner2 = [kp[0], m.end.y];
for (let [i,j] of [corner1,corner2])
{
if (this.board[i][j] != VariantRules.EMPTY && this.getColor(i,j) == oppCol)
{
// Square (x,y) must be surroundable by two enemy pieces,
// and one of them at least should be a pawn (moving).
- const dirs = [ [1,0],[0,1],[1,1],[-1,1] ];
- const steps = VariantRules.steps[VariantRules.ROOK]
- .concat(VariantRules.steps[VariantRules.BISHOP]);
+ const dirs = [ [1,0],[0,1] ];
+ const steps = VariantRules.steps[VariantRules.ROOK];
const [sizeX,sizeY] = VariantRules.size;
for (let dir of dirs)
{
j3 += step[1];
}
if (i3>=0 && i3<sizeX && j3>=0 && j3<sizeY
+ && colors.includes(this.getColor(i3,j3))
&& this.getPiece(i3,j3) == VariantRules.PAWN
&& !this.isImmobilized([i3,j3]))
{
{
// Try in opposite direction:
let [i,j] = [x-step[0],y-step[1]];
- while (i>=0 && i<sizeX && j>=0 && j<sizeY && this.board[i][j] == V.EMPTY)
- {
- i -= step[0];
- j -= step[1];
- }
- if (i>=0 && i<sizeX && j>=0 && j<sizeY && colors.includes(this.getColor(i,j))
- && this.getPiece(i,j) == V.KNIGHT)
+ while (i>=0 && i<sizeX && j>=0 && j<sizeY)
{
- if (!this.isImmobilized([i,j]))
- return true;
+ while (i>=0 && i<sizeX && j>=0 && j<sizeY && this.board[i][j] == V.EMPTY)
+ {
+ i -= step[0];
+ j -= step[1];
+ }
+ if (i>=0 && i<sizeX && j>=0 && j<sizeY)
+ {
+ if (colors.includes(this.getColor(i,j)))
+ {
+ if (this.getPiece(i,j) == V.KNIGHT && !this.isImmobilized([i,j]))
+ return true;
+ continue outerLoop;
+ }
+ // [else] Our color, could be captured *if there was an empty space*
+ if (this.board[i+step[0]][j+step[1]] != V.EMPTY)
+ continue outerLoop;
+ i -= step[0];
+ j -= step[1];
+ }
}
}
}