From 5c7aa87a03e1763b8c28abe414063ce8dfa0e8e8 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Thu, 2 Feb 2023 17:50:17 +0100 Subject: [PATCH] added fillAlmostFull to prevent playerwin --- src/c/ticTacToe.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index f811deb..f51d022 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -412,4 +412,263 @@ void fillAlmostFull(char field[3][3], bool* pt) { return; } } + + if (field[0][0] == 'O') { + if (field[0][1] == 'O') { + field[0][2] = 'X'; + *pt = true; + return; + } + else if (field[0][2] == 'O') { + field[0][1] = 'X'; + *pt = true; + return; + } + else if (field[1][0] == 'O') { + field[2][0] = 'X'; + *pt = true; + return; + } + else if (field[2][0] == 'O') { + field[1][0] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[2][2] = 'X'; + *pt = true; + return; + } + else if (field[2][2] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + } + if (field[0][1] == 'O') { + if (field[0][0] == 'O') { + field[0][2] = 'X'; + *pt = true; + return; + } + else if (field[0][2] == 'O') { + field[0][0] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[2][1] = 'X'; + *pt = true; + return; + } + else if (field[2][1] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + } + if (field[0][2] == 'O') { + if (field[0][0] == 'O') { + field[0][1] = 'X'; + *pt = true; + return; + } + else if (field[0][1] == 'O') { + field[0][0] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[2][0] = 'X'; + *pt = true; + return; + } + else if (field[2][0] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + else if (field[1][2] == 'O') { + field[2][2] = 'X'; + *pt = true; + return; + } + else if (field[2][2] == 'O') { + field[1][2] = 'X'; + *pt = true; + return; + } + } + if (field[1][0] == 'O') { + if (field[1][1] == 'O') { + field[1][2] = 'X'; + *pt = true; + return; + } + else if (field[1][2] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + else if (field[0][0] == 'O') { + field[2][0] = 'X'; + *pt = true; + return; + } + else if (field[2][0] == 'O') { + field[0][0] = 'X'; + *pt = true; + return; + } + } + if (field[1][1] == 'O') { + if (field[1][0] == 'O') { + field[1][2] = 'X'; + *pt = true; + return; + } + else if (field[1][2] == 'O') { + field[1][0] = 'X'; + *pt = true; + return; + } + else if (field[0][1] == 'O') { + field[2][1] = 'X'; + *pt = true; + return; + } + else if (field[2][1] == 'O') { + field[0][1] = 'X'; + *pt = true; + return; + } + else if (field[0][0] == 'O') { + field[2][2] = 'X'; + *pt = true; + return; + } + else if (field[2][2] == 'O') { + field[0][0] = 'X'; + *pt = true; + return; + } + else if (field[0][2] == 'O') { + field[2][0] = 'X'; + *pt = true; + return; + } + else if (field[2][0] == 'O') { + field[0][2] = 'X'; + *pt = true; + return; + } + } + if (field[1][2] == 'O') { + if (field[1][0] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[1][0] = 'X'; + *pt = true; + return; + } + else if (field[0][2] == 'O') { + field[2][2] = 'X'; + *pt = true; + return; + } + else if (field[2][2] == 'O') { + field[0][2] = 'X'; + *pt = true; + return; + } + } + if (field[2][0] == 'O') { + if (field[2][1] == 'O') { + field[2][2] = 'X'; + *pt = true; + return; + } + else if (field[2][2] == 'O') { + field[2][1] = 'X'; + *pt = true; + return; + } + else if (field[0][0] == 'O') { + field[1][0] = 'X'; + *pt = true; + return; + } + else if (field[1][0] == 'O') { + field[0][0] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[0][2] = 'X'; + *pt = true; + return; + } + else if (field[0][2] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + } + if (field[2][1] == 'O') { + if (field[2][0] == 'O') { + field[2][2] = 'X'; + *pt = true; + return; + } + else if (field[2][2] == 'O') { + field[2][0] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[0][1] = 'X'; + *pt = true; + return; + } + else if (field[0][1] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + } + if (field[2][2] == 'O') { + if (field[2][0] == 'O') { + field[2][1] = 'X'; + *pt = true; + return; + } + else if (field[2][1] == 'O') { + field[2][0] = 'X'; + *pt = true; + return; + } + else if (field[0][2] == 'O') { + field[1][2] = 'X'; + *pt = true; + return; + } + else if (field[1][2] == 'O') { + field[0][2] = 'X'; + *pt = true; + return; + } + else if (field[1][1] == 'O') { + field[0][0] = 'X'; + *pt = true; + return; + } + else if (field[0][0] == 'O') { + field[1][1] = 'X'; + *pt = true; + return; + } + } }