Last active
October 12, 2015 13:48
-
-
Save pauldwhitman/4036296 to your computer and use it in GitHub Desktop.
Part of the "Chess in C" blog post series. Checks whether a square has a rook in the row or column.
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 a rook move */ | |
/* Variables to store rook position of row 3 and column 4 */ | |
board[4][0] = ROOK; | |
int pieceRow = 4; | |
int pieceColumn = 0; | |
/* For every row */ | |
for (i = 0;i <= 7; i++) { | |
/* And every column */ | |
for (j = 0;j <= 7; j++){ | |
/* ...if the row contains the rook, mark the cell | |
* as a possible destination | |
* (except if the cell contains the piece) */ | |
if (i == pieceRow && j != pieceColumn) { | |
board[i][j] = BREADCRUMB; | |
} | |
/* ...if the column contains the rook, mark the cell | |
* as a possible destination | |
* (except if the cell contains the piece) */ | |
if (i != pieceRow && j == pieceColumn) { | |
board[i][j] = BREADCRUMB; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment