|
|
@ -1,5 +1,6 @@ |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
const int BOARD_SIZE = 3; |
|
|
|
char board[3][3] = {{'1', '2', '3'}, |
|
|
|
{'4', '5', '6'}, |
|
|
|
{'7', '8', '9'}}; |
|
|
@ -52,8 +53,6 @@ char checkWinner() { |
|
|
|
} |
|
|
|
|
|
|
|
// Funktion zur Überprüfung, ob das Spiel unentschieden ist |
|
|
|
const int BOARD_SIZE = 3; |
|
|
|
|
|
|
|
int isBoardFull() { |
|
|
|
for (int i = 0; i < BOARD_SIZE; i++) { |
|
|
|
for (int j = 0; j < BOARD_SIZE; j++) { |
|
|
@ -67,7 +66,7 @@ int isBoardFull() { |
|
|
|
|
|
|
|
|
|
|
|
// Funktion zum Zug eines Spielers |
|
|
|
enum switchPlayer(enum currentPlayer) { |
|
|
|
char switchPlayer(char currentPlayer) { |
|
|
|
return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; |
|
|
|
} |
|
|
|
|
|
|
@ -80,14 +79,14 @@ int isValidMove(int choice) { |
|
|
|
|
|
|
|
void makeMove() { |
|
|
|
int choice; |
|
|
|
printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); |
|
|
|
printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); |
|
|
|
scanf("%d", &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'; |
|
|
|
board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; |
|
|
|
currentPlayer = switchPlayer(currentPlayer); |
|
|
|
|
|
|
|
} else { |
|
|
|