From d95ca2b2e9ae4828b6429db856b94fb57961bb71 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Thu, 2 Feb 2023 16:20:44 +0100 Subject: [PATCH] added get computer input --- src/c/ticTacToe.c | 12 ++++++++++++ src/c/ticTacToe.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index 7d2105f..3f3066a 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -138,3 +138,15 @@ int wasGameWon(char field[3][3]){ return winner; } +void getComputerInput(char field[3][3]){ + bool symbolSet = false; + while (!symbolSet){ + int row, col; + row = rand() % 3; + col = rand() % 3; + if (field[row][col] == '-'){ + field[row][col] = 'X'; + symbolSet = true; + } + } +} diff --git a/src/c/ticTacToe.h b/src/c/ticTacToe.h index ec68f18..222383d 100644 --- a/src/c/ticTacToe.h +++ b/src/c/ticTacToe.h @@ -15,5 +15,6 @@ void initField(char field[3][3]); void getPlayerInput(char field[3][3]); bool validatePlayerInput(int row, int col); int wasGameWon(char field[3][3]); +void getComputerInput(char field[3][3]); #endif \ No newline at end of file