From 1d74dc8f317cc7356568d61576297228269c2ec3 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Fri, 3 Jan 2025 20:32:38 +0100 Subject: [PATCH] Fixed checkWin method and README --- 4GEWINNT.php | 78 +++++++++++++++++++++++++++++----------------------- README.md | 2 +- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/4GEWINNT.php b/4GEWINNT.php index 429603c..43d0642 100644 --- a/4GEWINNT.php +++ b/4GEWINNT.php @@ -147,39 +147,47 @@ function placechip($col){ } function checkwin($row, $col){ - return $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 1][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 2][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 3][$col] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 1][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 2][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 3][$col] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row][$col + 1] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row][$col + 2] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row][$col + 3] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row][$col - 1] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row][$col - 2] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row][$col - 3] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 1][$col + 1] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 2][$col + 2] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 3][$col + 3] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 1][$col - 1] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 2][$col - 2] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 3][$col - 3] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 1][$col - 1] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 2][$col - 2] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row + 3][$col - 3] === $_SESSION["currentplayer"] || - $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 1][$col + 1] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 2][$col + 2] === $_SESSION["currentplayer"] - && $_SESSION["board"][$row - 3][$col + 3] === $_SESSION["currentplayer"] ? true : false; - + for ($row = 0; $row <= 5; $row++) { + for ($col = 0; $col <= 6; $col++) { + if ( + $row <= 2 && + $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 1][$col] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 2][$col] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 3][$col] === $_SESSION["currentplayer"] + ) { + return true; + } else if ( + $col <= 3 && + $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row][$col + 1] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row][$col + 2] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row][$col + 3] === $_SESSION["currentplayer"] + ) { + return true; + } else if ( + $row <= 2 && + $col <= 3 && + $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 1][$col + 1] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 2][$col + 2] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 3][$col + 3] === $_SESSION["currentplayer"] + ) { + return true; + } else if ( + $row <= 2 && + $col <= 3 && + $_SESSION["board"][$row][$col + 3] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 1][$col + 2] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 2][$col + 1] === $_SESSION["currentplayer"] && + $_SESSION["board"][$row + 3][$col] === $_SESSION["currentplayer"] + ) { + return true; + } + } + } + + return false; } function swapplayer(){ @@ -207,7 +215,7 @@ function botturn(){ - 4-GEWINNT + 4GEWINNT