Last active
December 14, 2015 18:48
-
-
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.
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 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