diff --git a/html/testBotScripts/connectfour.html b/html/testBotScripts/connectfour.html index f7f751e..638e4dc 100644 --- a/html/testBotScripts/connectfour.html +++ b/html/testBotScripts/connectfour.html @@ -83,6 +83,11 @@ function playingAT(col){ var symbol="O"; } + if(board[5][col]!== ""){ + addLog('Player ' + currentPlayer + ', symbol ' + symbol + ' wants to play on column ' + col + ' but that column is already full. He loses.'); + return; + } + //find the first line empty var i=0; for(i = 0; i < 6 , board[i][col] !== ""; i++){ @@ -185,7 +190,18 @@ function playingAT(col){ wins(currentPlayer); return; } - + + //if it was the last cell + var full=true; + for (var i = 0; i < 7; i ++){ + if( board[5][i] == "" ){ + full = false; + } + } + if (full){ + addLog('match nul'); + return; + } //change player if(currentPlayer == 1){ @@ -249,7 +265,7 @@ function startGame(){ } //create board var table=createElem('table',{'class':'battleGrid', 'id': 'board'}); - for (var i=6; i > -1; i--){ + for (var i=5; i > -1; i--){ var tr=createElem('tr'); for (var j=0;j<7; j++){ var td=createElem('td',{'id': 'td' + j + '_' + i}); diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 4f7381a..61edf4e 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -254,14 +254,38 @@ switch ($_POST['act']){ } }else{ - $anwserToJS=array( - 'continue' => 1, - 'strikeX' => $strikeX, - 'strikeY' => $strikeY, - 'strikeSymbol'=> $you, - 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer - ); + + //Was it the last cell? + $full=true; + foreach ($_SESSION['map'][5] as $cell) { + if ($cell == ""){ + $full=false; + break; + } + } + + if($full){ + + save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],0); + $anwserToJS=array( + 'continue' => 0, + 'strikeX' => $strikeX, + 'strikeY' => $strikeY, + 'strikeSymbol'=> $you, + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." match nul" + ); + + }else{ + + $anwserToJS=array( + 'continue' => 1, + 'strikeX' => $strikeX, + 'strikeY' => $strikeY, + 'strikeSymbol'=> $you, + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer + ); + } } }else{