connect four full js
This commit is contained in:
parent
22ecf1f4c8
commit
5bb515d7cf
|
@ -48,6 +48,23 @@ switch ($_POST['act']){
|
||||||
$_SESSION['matchId']=get_unique_id();
|
$_SESSION['matchId']=get_unique_id();
|
||||||
$_SESSION['game']="connectFou";
|
$_SESSION['game']="connectFou";
|
||||||
|
|
||||||
|
//send init message
|
||||||
|
|
||||||
|
for($player = 0; $player < 2; $player++){
|
||||||
|
$params[$player]=array(
|
||||||
|
'game-id' => $_SESSION['matchId',
|
||||||
|
'action' => 'init',
|
||||||
|
'game' => 'connectFou',
|
||||||
|
'players' => 2,
|
||||||
|
'board' => '',
|
||||||
|
'player-index' => $player
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//echo "plop".json_encode($_SESSION['map']);
|
//echo "plop".json_encode($_SESSION['map']);
|
||||||
case "fight":
|
case "fight":
|
||||||
|
|
||||||
|
@ -77,26 +94,38 @@ switch ($_POST['act']){
|
||||||
$you="X";
|
$you="X";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
game-id string identifiant la partie.
|
||||||
|
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.
|
||||||
|
players Int indiquant le nombre de joueurs dans la partie, toujours 2 au morpion.
|
||||||
|
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.
|
||||||
|
*/
|
||||||
//make post datas to send
|
//make post datas to send
|
||||||
$postDatas=array(
|
$postDatas=array(
|
||||||
|
'game-id' => $_SESSION['matchId'],
|
||||||
|
'action' => 'play-turn',
|
||||||
'game' => 'connectFour',
|
'game' => 'connectFour',
|
||||||
'match_id' => $_SESSION['matchId']."-".$_SESSION['currentPlayer'],
|
'players' => 2,
|
||||||
'opponent' => $opponentName,
|
'opponent' => $opponentName,
|
||||||
'you' => $you,
|
'you' => $you,
|
||||||
'grid' => $_SESSION['map']
|
'board' => $_SESSION['map'],
|
||||||
|
'player-index' => $_SESSION['currentPlayer'] - 1
|
||||||
);
|
);
|
||||||
//send query
|
//send query
|
||||||
$anwserPlayer=get_IA_Response($botUrl,$postDatas);
|
$tempPlayer = get_IA_Response($botUrl,$postDatas);
|
||||||
//for test ***************************
|
$anwserPlayer = $tempPlayer['play'];
|
||||||
//echo $anwserPlayer; die;
|
|
||||||
//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] == "")){
|
||||||
//reponse conforme
|
//reponse conforme
|
||||||
|
|
||||||
for($y = 0; $_SESSION['map'][$y][$anwserPlayer] <> ""; $y++){
|
for($y = 0; $_SESSION['map'][$y][$anwserPlayer] <> ""; $y++){
|
||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION['map'][$y][$anwserPlayer]=$you;
|
$_SESSION['map'][$y][$anwserPlayer]=$you;
|
||||||
$strikeX=$anwserPlayer;
|
$strikeX=$anwserPlayer;
|
||||||
$strikeY=$y;
|
$strikeY=$y;
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
function get_IA_Response($iaUrl,$postParams){
|
function get_IA_Response($iaUrl,$postParams){
|
||||||
//send params JSON as body
|
//send params JSON as body
|
||||||
|
|
||||||
$data_string = json_encode($postParams);
|
$data_string = json_encode($postParams);
|
||||||
/*
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $iaUrl);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
$output = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
$ch = curl_init($iaUrl);
|
$ch = curl_init($iaUrl);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||||
|
@ -24,8 +15,7 @@ function get_IA_Response($iaUrl,$postParams){
|
||||||
);
|
);
|
||||||
$output= curl_exec($ch);
|
$output= curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
return json_decode($output,TRUE);
|
||||||
return htmlentities($output);
|
|
||||||
}
|
}
|
||||||
function get_Post_Params($botsCount){
|
function get_Post_Params($botsCount){
|
||||||
$keysBots=array('bot1','bot2');
|
$keysBots=array('bot1','bot2');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user