commit
e0a6f7df63
|
|
@ -61,6 +61,12 @@ switch ($_POST['act']){
|
||||||
'player-index' => $player
|
'player-index' => $player
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* 'messageSend' => $data_string,
|
||||||
|
* 'httpStatus' => $curl_getinfo($ch)['http_code'],
|
||||||
|
* 'response' => $output,
|
||||||
|
* 'responseArr' => $arr
|
||||||
|
*/
|
||||||
get_IA_Response($_SESSION['bot1']['url'],$params[0]); //don't care about result
|
get_IA_Response($_SESSION['bot1']['url'],$params[0]); //don't care about result
|
||||||
get_IA_Response($_SESSION['bot2']['url'],$params[1]); //don't care about result
|
get_IA_Response($_SESSION['bot2']['url'],$params[1]); //don't care about result
|
||||||
|
|
||||||
|
|
@ -98,14 +104,14 @@ switch ($_POST['act']){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
game-id string identifiant la partie.
|
* game-id string identifiant la partie.
|
||||||
action string identifiant la phase, init tout de suite, sera play-turn dans le châpitre suivant.
|
* action string identifiant la phase, init tout de suite, sera play-turn dans le châpitre suivant.
|
||||||
game string identifiant le jeu. Ici, ce sera forcément tictactoe. ça peut servir si vous donnez une seule URL pour plusieurs bots.
|
* game string identifiant le jeu. Ici, ce sera forcément tictactoe. ça peut servir si vous donnez une seule URL pour plusieurs bots.
|
||||||
players Int indiquant le nombre de joueurs dans la partie, toujours 2 au morpion.
|
* players Int indiquant le nombre de joueurs dans la partie, toujours 2 au morpion.
|
||||||
board Vide à cette étape, voir chapitre suivant.
|
* board Vide à cette étape, voir chapitre suivant.
|
||||||
player-index int, L'ordre de votre bot dans les tours de jeu. Le premier joueur a la valeur 0, le deuxième 1.
|
* player-index int, L'ordre de votre bot dans les tours de jeu. Le premier joueur a la valeur 0, le deuxième 1.
|
||||||
*/
|
*/
|
||||||
//make post datas to send
|
//make post datas to send
|
||||||
$postDatas=array(
|
$postDatas=array(
|
||||||
|
|
@ -118,9 +124,14 @@ switch ($_POST['act']){
|
||||||
'board' => $_SESSION['map'],
|
'board' => $_SESSION['map'],
|
||||||
'player-index' => $_SESSION['currentPlayer'] - 1
|
'player-index' => $_SESSION['currentPlayer'] - 1
|
||||||
);
|
);
|
||||||
|
|
||||||
//send query
|
//send query
|
||||||
$tempPlayer = get_IA_Response($botUrl,$postDatas);
|
$tempPlayer = get_IA_Response($botUrl,$postDatas);
|
||||||
$anwserPlayer = $tempPlayer['play'];
|
if(isset($tempPlayer['responseArr']['play'])){
|
||||||
|
$anwserPlayer = $tempPlayer['responseArr']['play'];
|
||||||
|
}else{
|
||||||
|
$anwserPlayer = -1;
|
||||||
|
}
|
||||||
|
|
||||||
//vérifier la validité de la réponse
|
//vérifier la validité de la réponse
|
||||||
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
|
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
|
||||||
|
|
@ -296,11 +307,15 @@ switch ($_POST['act']){
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
//reponse non conforme
|
//reponse non conforme
|
||||||
|
|
||||||
$anwserToJS=array(
|
$anwserToJS=array(
|
||||||
'continue' =>0,
|
'continue' =>0,
|
||||||
'strikeX' => -1,
|
'strikeX' => -1,
|
||||||
'strikeY' => -1,
|
'strikeY' => -1,
|
||||||
'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer),
|
'log' => $you." ".$currentBotName." made a non conform anwser: <br/>
|
||||||
|
Bots Arena sent:<em>".$tempPlayer['messageSend']."</em><br/>
|
||||||
|
".$currentBotName." HTTP STATUS:<em> ".$tempPlayer['httpStatus']."</em><br/>
|
||||||
|
His response: <em>".htmlentities($tempPlayer['response'])."</em>",
|
||||||
'gameId' => $_SESSION['matchId']
|
'gameId' => $_SESSION['matchId']
|
||||||
);
|
);
|
||||||
if($_SESSION['currentPlayer']==1){
|
if($_SESSION['currentPlayer']==1){
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ function Ajx(){
|
||||||
}
|
}
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
function addLog(message){
|
||||||
|
var p=createElem('p',{});
|
||||||
|
p.innerHTML=message;
|
||||||
|
document.getElementById('logs').appendChild(p);
|
||||||
|
}
|
||||||
function createElem(type,attributes){
|
function createElem(type,attributes){
|
||||||
var elem=document.createElement(type);
|
var elem=document.createElement(type);
|
||||||
for (var i in attributes)
|
for (var i in attributes)
|
||||||
|
|
@ -21,10 +26,14 @@ function createElem(type,attributes){
|
||||||
function connectFour(bot1,bot2,xd_check, gameId, newGame){
|
function connectFour(bot1,bot2,xd_check, gameId, newGame){
|
||||||
if (newGame === undefined){
|
if (newGame === undefined){
|
||||||
newGame = true;
|
newGame = true;
|
||||||
gameId=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newGame){
|
if (newGame){
|
||||||
|
gameId=0;
|
||||||
|
//don't touch the button while game is not ended
|
||||||
|
document.getElementById('fightButton').disabled=true;
|
||||||
|
|
||||||
//empty
|
//empty
|
||||||
while (document.getElementById('fightResult').firstChild) {
|
while (document.getElementById('fightResult').firstChild) {
|
||||||
document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild);
|
document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild);
|
||||||
|
|
@ -54,17 +63,18 @@ function connectFour(bot1,bot2,xd_check, gameId, newGame){
|
||||||
try{
|
try{
|
||||||
var reponse = JSON.parse(xhr.responseText);
|
var reponse = JSON.parse(xhr.responseText);
|
||||||
}catch(e){
|
}catch(e){
|
||||||
document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText;
|
addLog('erreur' +xhr.responseText);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//log
|
//log
|
||||||
document.getElementById('logs').innerHTML += reponse['log'] + '<br/>';
|
addLog(reponse['log']);
|
||||||
|
|
||||||
//fill the grid
|
//fill the grid
|
||||||
if( reponse['strikeX'] > -1){
|
if( reponse['strikeX'] > -1){
|
||||||
document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol'];
|
document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//colorise cells that win
|
||||||
if(reponse['cellsWin'] === undefined){
|
if(reponse['cellsWin'] === undefined){
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -79,12 +89,15 @@ function connectFour(bot1,bot2,xd_check, gameId, newGame){
|
||||||
//if game isn't finished, continue
|
//if game isn't finished, continue
|
||||||
if(reponse['continue'] == 1){
|
if(reponse['continue'] == 1){
|
||||||
connectFour(bot1,bot2,xd_check,reponse['gameId'], false);
|
connectFour(bot1,bot2,xd_check,reponse['gameId'], false);
|
||||||
|
}else{
|
||||||
|
document.getElementById('fightButton').disabled=false;
|
||||||
}
|
}
|
||||||
}else if(xhr.status == 512){
|
}else if(xhr.status == 512){
|
||||||
//just forget
|
//just forget
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
alert ('error ' + xhr.status);
|
alert ('error ' + xhr.status);
|
||||||
|
document.getElementById('fightButton').disabled=false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,5 @@ $bots=get_Bots_Array('connectFou');
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<p><input type="button" value="<?php echo $lang['FIGHT']; ?>" onclick="connectFour(document.getElementById('bot1').value,document.getElementById('bot2').value,'<?php echo xd_check_input(2); ?>',0);"></p>
|
<p><input id="fightButton" type="button" value="<?php echo $lang['FIGHT']; ?>" onclick="connectFour(document.getElementById('bot1').value,document.getElementById('bot2').value,'<?php echo xd_check_input(2); ?>',0);"></p>
|
||||||
<div id="fightResult"></div>
|
<div id="fightResult"></div>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
.tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;}
|
.tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;}
|
||||||
#fightResult{display:table;}
|
#fightResult{display:table;}
|
||||||
#logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;}
|
#logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;}
|
||||||
|
#logs p em {color: grey; font-size: 70%; test-transform:italic;}
|
||||||
.battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;}
|
.battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;}
|
||||||
.battleGrid tr{}
|
.battleGrid tr{}
|
||||||
.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;}
|
.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,13 @@ switch ($_POST['act']){
|
||||||
'player-index' =>$playerIndex
|
'player-index' =>$playerIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
$playerResponse=get_IA_Response($playerURL,$paramsToSend)['play'];
|
|
||||||
|
$tempPlayer = get_IA_Response($playerURL,$paramsToSend);
|
||||||
|
if(isset($tempPlayer['responseArr']['play'])){
|
||||||
|
$playerResponse = $tempPlayer['responseArr']['play'];
|
||||||
|
}else{
|
||||||
|
$playerResponse = -1;
|
||||||
|
}
|
||||||
|
|
||||||
//tester la validité de la réponse
|
//tester la validité de la réponse
|
||||||
if((isset($map[$playerResponse])) && ($map[$playerResponse]=="")){
|
if((isset($map[$playerResponse])) && ($map[$playerResponse]=="")){
|
||||||
|
|
@ -124,7 +130,12 @@ switch ($_POST['act']){
|
||||||
$playerPlayingNow=1;
|
$playerPlayingNow=1;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
echo "<p>".$playerName." a fait une réponse non conforme. Il perd.</p>";
|
echo "<p>".$playerName." made a non conform anwser, he lost: <br/>
|
||||||
|
Bots Arena sent:<em>".$tempPlayer['messageSend']."</em><br/>
|
||||||
|
".$playerName." HTTP STATUS:<em> ".$tempPlayer['httpStatus']."</em><br/>
|
||||||
|
His response: <em>".htmlentities($tempPlayer['response'])."</em></p>";
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ td {min-width: 10px; height: 10px;}
|
||||||
.arrenaMessage::before{content: "arena message:"; color: grey; font-size: 70%; test-transform:italic;}
|
.arrenaMessage::before{content: "arena message:"; color: grey; font-size: 70%; test-transform:italic;}
|
||||||
.botResponse{color: red;}
|
.botResponse{color: red;}
|
||||||
.botResponse::before{content: "bot response:";color: grey; font-size: 70%; test-transform:italic;}
|
.botResponse::before{content: "bot response:";color: grey; font-size: 70%; test-transform:italic;}
|
||||||
|
#fightResult p em {color: grey; font-size: 70%; test-transform:italic;}
|
||||||
|
|
@ -280,15 +280,14 @@ function save_battle($game,$bot1,$bot2,$resultat){
|
||||||
|
|
||||||
}
|
}
|
||||||
function get_unique_id(){
|
function get_unique_id(){
|
||||||
|
//increment the number
|
||||||
|
|
||||||
$fp = fopen(__DIR__.'/../countBattles.txt', 'c+');
|
$fp = fopen(__DIR__.'/../countBattles.txt', 'c+');
|
||||||
flock($fp, LOCK_EX);
|
flock($fp, LOCK_EX);
|
||||||
|
|
||||||
$count = (int)fread($fp, filesize(__DIR__.'/../countBattles.txt'));
|
$count = (int)fread($fp, filesize(__DIR__.'/../countBattles.txt'));
|
||||||
ftruncate($fp, 0);
|
ftruncate($fp, 0);
|
||||||
fseek($fp, 0);
|
fseek($fp, 0);
|
||||||
fwrite($fp, $count + 1);
|
fwrite($fp, $count + 1);
|
||||||
|
|
||||||
flock($fp, LOCK_UN);
|
flock($fp, LOCK_UN);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
return $count;
|
return $count;
|
||||||
|
|
@ -335,6 +334,7 @@ function does_arena_exist($string,$arenasArr){
|
||||||
|
|
||||||
function get_IA_Response($iaUrl,$postParams){
|
function get_IA_Response($iaUrl,$postParams){
|
||||||
// send params JSON as body
|
// send params JSON as body
|
||||||
|
// return query detail on an array
|
||||||
|
|
||||||
$data_string = json_encode($postParams);
|
$data_string = json_encode($postParams);
|
||||||
|
|
||||||
|
|
@ -348,8 +348,18 @@ function get_IA_Response($iaUrl,$postParams){
|
||||||
'Content-Type: application/json',
|
'Content-Type: application/json',
|
||||||
'Content-Length: ' . strlen($data_string))
|
'Content-Length: ' . strlen($data_string))
|
||||||
);
|
);
|
||||||
|
|
||||||
$output= curl_exec($ch);
|
$output= curl_exec($ch);
|
||||||
|
$httpCode = curl_getinfo($ch)['http_code'];
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
//echo $iaUrl." ".$data_string." ".$output.'<br/>';
|
if(! $arr = json_decode($output,TRUE)){
|
||||||
return json_decode($output,TRUE);
|
$arr=array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'messageSend' => $data_string,
|
||||||
|
'httpStatus' => $httpCode,
|
||||||
|
'response' => $output,
|
||||||
|
'responseArr' => $arr
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user