Skip to content

Instantly share code, notes, and snippets.

@pauldwhitman
Last active December 14, 2015 18:19
Show Gist options
  • Save pauldwhitman/5128333 to your computer and use it in GitHub Desktop.
Save pauldwhitman/5128333 to your computer and use it in GitHub Desktop.
Part of the "Chess in C" blog post series. Calculates the possible up-left diagonal destinations of a bishop.
/* Calculate possible up-left diagonal destinations
* This requires the loop to iterate backwards as we are
* checking cells BEFORE the bishop */
for (i=7; i>=0; i--) {
for (j=7; j>=0; j--){
/* If 1) the cell to right is inbounds of the array and
* 2) the cell isn't not on the final row */
if ((j+1 != 8) && (i != 7)) {
/* ...AND the above-right cell has a bishop OR a breadcrumb ... */
if (board[i+1][j+1] == BISHOP || board[i+1][j+1] == POTENTIAL_MOVE_BISHOP) {
/* ...then leave a breadcrumb (50) */
board[i][j] = POTENTIAL_MOVE_BISHOP;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment