Hey y'all. I've decided to try and code a drafts game. However, I'm getting some rather odd output. Now, I know I could be doing this more efficiently, but right now I'm just interested in working code
Anyway, the basic problem is that when I try and detect a piece, it will only detect on the first row.
So, if I try "row = 1, col = 1", the piece will be detected. However, if I try "row = 2, col = 2", the piece will not be detected. I don't understand why though :S
This is not for homework or such, just my own personal want to learn to code. Any help is greatly appreciated
Code:#include <stdio.h> void populateboard(void); void printboard(void); void makemove(void); /* board[row][column] */ int board[8][8] = {0}; int turn = 1; int main(void) { populateboard(); system("CLS"); printboard(); makemove(); printf("\n"); system("PAUSE"); return 0; } void populateboard(void) { int i, j; for (i = 0; i <= 2; i += 2) { for (j = 0; j <= 7; j += 2) { board[i][j] = 1; } } for (j = 1; j <= 7; j += 2) { board[1][j] = 1; } for (i = 5; i <= 7; i += 2) { for (j = 0; j <= 7; j += 2) { board[i][j] = 2; } } for (j = 1; j <= 7; j += 2) { board[6][j] = 2; } return; } void printboard(void) { int i, j; printf(" 1 2 3 4 5 6 7 8"); printf("\n ---------------------------------\n"); for (i = 0; i <= 7; ++i) { for (j = 0; j <= 7; ++j) { if (j == 0) { printf("%i ", i + 1); } printf("| %c ", board[i][j]); if (j == 7) { printf("|\n ---------------------------------\n"); } } } return; } void makemove(void) { int row, col; start: ; printf("\n%c's turn\n\nEnter row: ", turn); scanf("%i", &row); printf("Enter column: "); scanf("%i", &col); printf("\nrow: %i\ncol: %i\n", row, col); if (board[row + 1][col + 1] == turn) { printf("Piece exists"); } else { printf("Piece does not exist"); goto start; } return; }



LinkBack URL
About LinkBacks



