So I'm working on a chess program and am working on legal moves, so far I have pawns and knights fully implemented but am having a little bit more trouble with the rook, how the pieces move on the board is the user selects a piece that piece is on tempSquare, and selects the square they want to move it to (selectedSquare), I then do a check to see if that piece is a rook, if it is then it goes through the code below. 12 is a vertical move, and 1 is a horizontal move. The problem with this code is that if there is a free square beside the rook it can move anywhere, and when it moves horizontal it doesn't register blocked squares, I've been trying to think of a different way to approach this problem for the last couple of days, well at least when I have time to do so, anyone have any ideas on how I should go about solving this?