Fixed checkWin method and README

main
Selim Eser 2025-01-03 20:32:38 +01:00
parent 3c33261f38
commit 1d74dc8f31
2 changed files with 44 additions and 36 deletions

View File

@ -147,39 +147,47 @@ function placechip($col){
} }
function checkwin($row, $col){ function checkwin($row, $col){
return $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] for ($row = 0; $row <= 5; $row++) {
&& $_SESSION["board"][$row + 1][$col] === $_SESSION["currentplayer"] for ($col = 0; $col <= 6; $col++) {
&& $_SESSION["board"][$row + 2][$col] === $_SESSION["currentplayer"] if (
&& $_SESSION["board"][$row + 3][$col] === $_SESSION["currentplayer"] || $row <= 2 &&
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row - 1][$col] === $_SESSION["currentplayer"] $_SESSION["board"][$row + 1][$col] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row - 2][$col] === $_SESSION["currentplayer"] $_SESSION["board"][$row + 2][$col] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row - 3][$col] === $_SESSION["currentplayer"] || $_SESSION["board"][$row + 3][$col] === $_SESSION["currentplayer"]
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] ) {
&& $_SESSION["board"][$row][$col + 1] === $_SESSION["currentplayer"] return true;
&& $_SESSION["board"][$row][$col + 2] === $_SESSION["currentplayer"] } else if (
&& $_SESSION["board"][$row][$col + 3] === $_SESSION["currentplayer"] || $col <= 3 &&
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row][$col - 1] === $_SESSION["currentplayer"] $_SESSION["board"][$row][$col + 1] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row][$col - 2] === $_SESSION["currentplayer"] $_SESSION["board"][$row][$col + 2] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row][$col - 3] === $_SESSION["currentplayer"] || $_SESSION["board"][$row][$col + 3] === $_SESSION["currentplayer"]
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] ) {
&& $_SESSION["board"][$row + 1][$col + 1] === $_SESSION["currentplayer"] return true;
&& $_SESSION["board"][$row + 2][$col + 2] === $_SESSION["currentplayer"] } else if (
&& $_SESSION["board"][$row + 3][$col + 3] === $_SESSION["currentplayer"] || $row <= 2 &&
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] $col <= 3 &&
&& $_SESSION["board"][$row - 1][$col - 1] === $_SESSION["currentplayer"] $_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row - 2][$col - 2] === $_SESSION["currentplayer"] $_SESSION["board"][$row + 1][$col + 1] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row - 3][$col - 3] === $_SESSION["currentplayer"] || $_SESSION["board"][$row + 2][$col + 2] === $_SESSION["currentplayer"] &&
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] $_SESSION["board"][$row + 3][$col + 3] === $_SESSION["currentplayer"]
&& $_SESSION["board"][$row + 1][$col - 1] === $_SESSION["currentplayer"] ) {
&& $_SESSION["board"][$row + 2][$col - 2] === $_SESSION["currentplayer"] return true;
&& $_SESSION["board"][$row + 3][$col - 3] === $_SESSION["currentplayer"] || } else if (
$_SESSION["board"][$row][$col] === $_SESSION["currentplayer"] $row <= 2 &&
&& $_SESSION["board"][$row - 1][$col + 1] === $_SESSION["currentplayer"] $col <= 3 &&
&& $_SESSION["board"][$row - 2][$col + 2] === $_SESSION["currentplayer"] $_SESSION["board"][$row][$col + 3] === $_SESSION["currentplayer"] &&
&& $_SESSION["board"][$row - 3][$col + 3] === $_SESSION["currentplayer"] ? true : false; $_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(){ function swapplayer(){
@ -207,7 +215,7 @@ function botturn(){
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>4-GEWINNT</title> <title>4GEWINNT</title>
<style> <style>
body { body {
all: initial; all: initial;
@ -272,7 +280,7 @@ function botturn(){
</head> </head>
<body> <body>
<h1>4-GEWINNT</h1> <h1>4GEWINNT</h1>
<div id="board"> <div id="board">
<form method="post"> <form method="post">
<?php <?php

View File

@ -2,7 +2,7 @@
Built in PHP. Built in PHP.
## How to host local live server ## How to host local server
> Make sure PHP is installed. > Make sure PHP is installed.