From c0530819cd1bf52e37085e812075447aaac7da35 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 8 Jun 2016 15:41:04 +0200 Subject: [PATCH 1/3] draw --- html/testBotScripts/connectfour.html | 18 ++++++++++++- src/arenas/connectFour/act.php | 38 +++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/html/testBotScripts/connectfour.html b/html/testBotScripts/connectfour.html index f7f751e..fa1a849 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 = true; + } + } + if (full){ + addLog('match nul'); + return; + } //change player if(currentPlayer == 1){ 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{ From e0fb83182f2882b1608b34ebb15689d7d106a780 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 8 Jun 2016 15:42:47 +0200 Subject: [PATCH 2/3] draw --- html/testBotScripts/connectfour.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/testBotScripts/connectfour.html b/html/testBotScripts/connectfour.html index fa1a849..c9f3fa3 100644 --- a/html/testBotScripts/connectfour.html +++ b/html/testBotScripts/connectfour.html @@ -195,7 +195,7 @@ function playingAT(col){ var full=true; for (var i = 0; i < 7; i ++){ if( board[5][i] == "" ){ - full = true; + full = false; } } if (full){ From 35d2783d4efd4db091fd8068cd119af4ecf8fa0c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 8 Jun 2016 15:47:53 +0200 Subject: [PATCH 3/3] oups --- html/testBotScripts/connectfour.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/testBotScripts/connectfour.html b/html/testBotScripts/connectfour.html index c9f3fa3..638e4dc 100644 --- a/html/testBotScripts/connectfour.html +++ b/html/testBotScripts/connectfour.html @@ -265,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});