This commit is contained in:
Gnieark 2016-05-12 17:05:44 +02:00
parent 828f1a4492
commit b85498c1c9

View File

@ -59,6 +59,7 @@ switch ($_POST['act']){
if(!isset($_SESSION['currentPlayer'])){ if(!isset($_SESSION['currentPlayer'])){
$_SESSION['currentPlayer']=1; $_SESSION['currentPlayer']=1;
$you="X"; $you="X";
$currentBotName=$_SESSION['bot1']['name'];
$opponentName=$_SESSION['bot2']['name']; $opponentName=$_SESSION['bot2']['name'];
$botUrl=$_SESSION['bot1']['url']; $botUrl=$_SESSION['bot1']['url'];
}else{ }else{
@ -66,10 +67,12 @@ switch ($_POST['act']){
$_SESSION['currentPlayer']=2; $_SESSION['currentPlayer']=2;
$you="O"; $you="O";
$opponentName=$_SESSION['bot1']['name']; $opponentName=$_SESSION['bot1']['name'];
$currentBotName=$_SESSION['bot2']['name'];
$botUrl=$_SESSION['bot2']['url']; $botUrl=$_SESSION['bot2']['url'];
}else{ }else{
$_SESSION['currentPlayer']=1; $_SESSION['currentPlayer']=1;
$opponentName=$_SESSION['bot2']['name']; $opponentName=$_SESSION['bot2']['name'];
$currentBotName=$_SESSION['bot1']['name'];
$botUrl=$_SESSION['bot1']['url']; $botUrl=$_SESSION['bot1']['url'];
$you="X"; $you="X";
} }
@ -86,10 +89,85 @@ switch ($_POST['act']){
); );
//send query //send query
$anwserPlayer=get_IA_Response($botUrl,$postDatas); $anwserPlayer=get_IA_Response($botUrl,$postDatas);
$anwserToJS=array(
) //vérifier la validité de la réponse
echo "player ".$_SESSION['currentPlayer']." répond ".$anwserPlayer;
if(isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == ""){
//reponse conforme
for($y = 0; $_SESSION['map'][$y][$anwserPlayer] <> ""; $y++){
}
$_SESSION['map'][$y][$anwserPlayer]=$you;
//does he win?
for($i=0;$i < 7;$i++){
for($j=0;$j < 6;$j++){
if($_SESSION['map'][$j][$i]== $you){
$wins=false;
//tester si 4 pions allignés vers la droite
if($i<4){
$wins=true;
for($x = $i+1; $x < $i+4; $x++){
if($_SESSION['map'][$j][$x] <> $you){
$wins=false;
break;
}
}
}
//tester si 4 pions allignés diagonale vers la droite
if((!$wins) && ($i < 4) && ($j < 3)){
$wins=true;
for($x = $i+1; $y = $j+1; $x < $i+4 ; $x++; $y++){
if($_SESSION['map'][$j][$x] <> $you){
$wins=false;
break;
}
}
}
//tester si 4 pions allignés diagonale vers la gauche
if((!$wins) && ($i > 3) && ($j < 3)){
$wins=true;
for($x = $i-1; $y = $j+1; $x > $i - 4 ; $x++; $y++){
if($_SESSION['map'][$j][$x] <> $you){
$wins=false;
break;
}
}
}
}
}
}
if($wins){
$anwserToJS=array(
'continue' => 0,
'grid' => $_SESSION['map'],
'log' => $you." ".$currentBotName." a gagné"
);
}else{
$anwserToJS=array(
'continue' => 1,
'grid' => $_SESSION['map'],
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer
);
}
}else{
//reponse non conforme
$anwserToJS=array(
'continue' =>0,
'grid' => $_SESSION['map'],
'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd"
);
}
echo json_encode($anwserToJS);