From 4cdef01b3a4c00d51b701701ed1780c878177253 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 19:14:53 +0000 Subject: [PATCH] refactoring: correct the errors --- src/main/c/GameTic_Tac_Toe/game.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f72b814..443fe8d 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -1,5 +1,6 @@ #include +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 {