From 47f60a02531ff98690e658c7d95336c703d18c5a Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Thu, 2 Feb 2023 18:33:43 +0100 Subject: [PATCH] added play function --- src/c/ticTacToe.c | 25 +++++++++++++++++++++++++ src/c/ticTacToe.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index 402c591..915e796 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -20,6 +20,7 @@ void printField(char field[3][3]){ } printf("\n"); } + printf("/n"); } void initField(char field[3][3]) { @@ -864,3 +865,27 @@ void fillAlmostFull(char field[3][3], bool* pt) { } } } + +int play() { + printPrompt(); + int counter = 0; + char field[3][3]; + initField(field); + int winner = NOWINNERYET; + while (winner == NOWINNERYET) { + if (counter % 2 == 0) { + printField(field); + getPlayerInput(field); + winner = wasGameWon(field); + } + else if (counter % 2 == 1) { + printField(field); + getComputerInput(field); + winner = wasGameWon(field); + } + counter += 1; + } + printField(field); + printf("%d", winner); + return winner; +} \ No newline at end of file diff --git a/src/c/ticTacToe.h b/src/c/ticTacToe.h index 6db536c..007b9cb 100644 --- a/src/c/ticTacToe.h +++ b/src/c/ticTacToe.h @@ -17,5 +17,6 @@ bool validatePlayerInput(int row, int col); int wasGameWon(char field[3][3]); void getComputerInput(char field[3][3]); void fillAlmostFull(char field[3][3], bool *pt); +int play(); #endif \ No newline at end of file