faizalzakaria / react-chess-app

React Chess App For me to learn React.
0 stars 0 forks source link

All pieces except Knight shouldn't be able to cross other piece. #3

Open faizalzakaria opened 7 years ago

faizalzakaria commented 7 years ago

Example,

screen shot 2017-07-08 at 6 26 17 pm

The Queen should not be able to cross the Knight

kbanico commented 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
  }
}

}`

screen shot 2017-07-10 at 7 56 04 pm