+ // 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] ];
+ const steps = VariantRules.steps[VariantRules.ROOK];
+ const [sizeX,sizeY] = VariantRules.size;
+ for (let dir of dirs)
+ {
+ const [i1,j1] = [x-dir[0],y-dir[1]]; //"before"
+ const [i2,j2] = [x+dir[0],y+dir[1]]; //"after"
+ if (i1>=0 && i1<sizeX && i2>=0 && i2<sizeX
+ && j1>=0 && j1<sizeY && j2>=0 && j2<sizeY)
+ {
+ if ((this.board[i1][j1]!=VariantRules.EMPTY
+ && colors.includes(this.getColor(i1,j1))
+ && this.board[i2][j2]==VariantRules.EMPTY)
+ ||
+ (this.board[i2][j2]!=VariantRules.EMPTY
+ && colors.includes(this.getColor(i2,j2))
+ && this.board[i1][j1]==VariantRules.EMPTY))
+ {
+ // Search a movable enemy pawn landing on the empty square
+ for (let step of steps)
+ {
+ let [ii,jj] = (this.board[i1][j1]==VariantRules.EMPTY ? [i1,j1] : [i2,j2]);
+ let [i3,j3] = [ii+step[0],jj+step[1]];
+ while (i3>=0 && i3<sizeX && j3>=0 && j3<sizeY
+ && this.board[i3][j3]==VariantRules.EMPTY)
+ {
+ i3 += step[0];
+ 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]))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;