Open faizalzakaria opened 7 years ago
Bishop attempt
` //this will work only with the same piece color but will jump ahead if trying to capture a peice behind another opposing peice isBlocked(piece,x,y,toX,toY,board){ let horzontalIncrement = toX > x ? 1 : -1; let verticalIncrement = toY > y ? 1 : -1; let startx = x let starty = y let color = piece.isWhite; while(Math.abs(toX - startx) > 0 && Math.abs(toY - starty) > 0){ startx+= horzontalIncrement; starty+= verticalIncrement; if(board[startx][starty] != undefined){ //if there is something there if(board[startx][starty].isWhite == color){ console.log("blocked by the same color") return true; }else{ console.log("oposite color in front") return false }
}else{
console.log("not blocked")
return false
}
}
}`
Example,
The Queen should not be able to cross the Knight