|
@ -77,21 +77,18 @@ int isValidMove(int choice) { |
|
|
return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); |
|
|
return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void makeMove() { |
|
|
|
|
|
int choice; |
|
|
|
|
|
printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); |
|
|
|
|
|
scanf("%d", &choice); |
|
|
|
|
|
|
|
|
void makeMove(int choice) { |
|
|
|
|
|
|
|
|
// Konvertiere die Zahl in Zeilen- und Spaltenindex |
|
|
|
|
|
if (isValidMove(choice)) { |
|
|
|
|
|
int row = (choice - 1) / BOARD_SIZE; |
|
|
|
|
|
int col = (choice - 1) % BOARD_SIZE; |
|
|
|
|
|
board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; |
|
|
|
|
|
currentPlayer = switchPlayer(currentPlayer); |
|
|
|
|
|
|
|
|
// Konvertiere die Zahl in Zeilen- und Spaltenindex |
|
|
|
|
|
if (isValidMove(choice)) { |
|
|
|
|
|
int row = (choice - 1) / BOARD_SIZE; |
|
|
|
|
|
int col = (choice - 1) % BOARD_SIZE; |
|
|
|
|
|
board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; |
|
|
|
|
|
currentPlayer = switchPlayer(currentPlayer); |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
printf("Ungueltiger Zug! Bitte waehle erneut.\n"); |
|
|
|
|
|
makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
printf("Ungueltiger Zug! Bitte waehle erneut.\n"); |
|
|
|
|
|
makeMove(get_move()); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -100,6 +97,13 @@ int isGameOver() { |
|
|
return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); |
|
|
return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int get_move(){ |
|
|
|
|
|
int choice; |
|
|
|
|
|
printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); |
|
|
|
|
|
scanf("%d", &choice); |
|
|
|
|
|
return choice; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void printGameResult(char winner) { |
|
|
void printGameResult(char winner) { |
|
|
if (winner == PLAYER_X || winner == PLAYER_O) { |
|
|
if (winner == PLAYER_X || winner == PLAYER_O) { |
|
|
printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); |
|
|
printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); |
|
@ -111,7 +115,7 @@ void printGameResult(char winner) { |
|
|
void playGame() { |
|
|
void playGame() { |
|
|
while (!isGameOver()) { |
|
|
while (!isGameOver()) { |
|
|
displayBoard(); |
|
|
displayBoard(); |
|
|
makeMove(); |
|
|
|
|
|
|
|
|
makeMove(get_move()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
displayBoard(); |
|
|
displayBoard(); |
|
|