Last active
December 14, 2015 18:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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