From fec03368ca2cd1c5a0c2648c81f7709e179c9dd6 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:18:52 +0000 Subject: [PATCH] refactoring: using an auxiliary function for diagonal lines --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0765c17..215f890 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,8 +32,11 @@ char checkWinner() { if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien - if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; - else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + char diagonal1Winner = checkLine(board[0][0], board[1][1], board[2][2]); + char diagonal2Winner = checkLine(board[0][2], board[1][1], board[2][0]); + + if (diagonal1Winner != ' ') return diagonal1Winner; + if (diagonal2Winner != ' ') return diagonal2Winner; // Kein Gewinner return ' ';