This may be a little hard to explain without a picture but, I am in the process of checking to see if the king is in check. To do so, I am starting at the king's location and going up, left, down, right, then all the diagonal patterns.
To simplify my code, I have a path checker method which takes in a starting location and ending location and returns true if there are any threats to the king in that path. So, I am calling this method like:
board.incheckPath(kingLocation, new Location(8, kingY))
This would check from the king to the top row, same column. I have a similar statement for left, down, and right.
The problem is I am trying to use the same fashion for the diagonal patterns, and I can't figure out a simple algorithm to figure out where the last location is. If you are higher than you are to the right, then if you go up and right diagonally, you're going to hit the top row before you hit the right most column. I figured out the algorithm for that location is:
if x > y {
row = 8; column = 8-(x-y)
} else {
row = 8-(x-y); column = 8;
}
Because where you land at is going to be the difference between x and y away from either the top row or right column. But I cannot figure out what the result would be for going up and left, down and left, or down and right.
Suppose, you coordinates are
Extending your solution it will looks like