Browse Source

Write checkHorizontal function

main^2
fdai7726 11 months ago
committed by Peter Wiebe
parent
commit
4b07fb4fd1
  1. 16
      src/main/c/VierGewinnt.c

16
src/main/c/VierGewinnt.c

@ -150,3 +150,19 @@ int dropPiece(char board[ROWS][COLS], int col, char player) {
return 0; // Column is full
}
// Write checkHorizontal function
int checkHorizontal(char board[ROWS][COLS], char player) {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col <= COLS - 4; col++) {
if (board[row][col] == player &&
board[row][col + 1] == player &&
board[row][col + 2] == player &&
board[row][col + 3] == player) {
return 1; // Gewonnen
}
}
}
return 0;
}
Loading…
Cancel
Save