Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pauldwhitman/5131586 to your computer and use it in GitHub Desktop.
Save pauldwhitman/5131586 to your computer and use it in GitHub Desktop.
Part of the "Chess in C" blog post series. Calculates the square used by the pawn if it moves by one or three squares. Intentionally contains an array out of bounds bug.
/* Calculate a pawn move */
/* For every row */
for (i = 0;i <= 7; i++) {
/* And every column */
for (j = 0;j <= 7; j++){
/* If this square contains a pawn.. */
if (board[i][j] == PAWN) {
/* ..mark the square below as being a potential move */
board[i+1][j] = POTENTIAL_MOVE_PAWN;
/* ..and if the pawn is in its starting position.. */
if (i == 1) {
/* ..mark the square two below as being a potential move */
board[i+2][j] = POTENTIAL_MOVE_PAWN;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment