Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pauldwhitman/5131593 to your computer and use it in GitHub Desktop.
Save pauldwhitman/5131593 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. Includes check to see whether pawn has reached the end of board/final row.
/* 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) {
/* ..and the pawn is NOT on the final row.. */
if (i != 7) {
/* ..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