Skip to content

Instantly share code, notes, and snippets.

@pauldwhitman
Last active October 12, 2015 13:48
Show Gist options
  • Save pauldwhitman/4036296 to your computer and use it in GitHub Desktop.
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.
/* 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