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(){
-