Skip to content

Instantly share code, notes, and snippets.

@pauldwhitman
Last active December 14, 2015 22:39
Show Gist options
  • Save pauldwhitman/5160366 to your computer and use it in GitHub Desktop.
Save pauldwhitman/5160366 to your computer and use it in GitHub Desktop.
Part of the "Chess in C" blog post series. Code to calculate the up-right diagonal.
/* Calculate possible up-right 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 left is inbounds of the array and
* 2) the cell isn't not on the final row */
if ((j-1 != -1) && (i != 7)) {
/* ...and the below-left cell has a bishop OR a breadcrumb... */
if (board[i+1][j-1] == BISHOP || board[i+1][j-1] == POTENTIAL_MOVE_BISHOP_UR) {
/* ...then leave a breadcrumb */
board[i][j] = POTENTIAL_MOVE_BISHOP_UR;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment