This commit is contained in:
Gnieark 2016-06-21 16:10:08 +02:00
parent ff63db17c6
commit 2a227eb201

View File

@ -25,6 +25,50 @@ header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST'); header('Access-Control-Allow-Methods: GET, POST');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
//connexion mysql
require_once("config.php");
if (!$lnMySQL=mysqli_connect($config['mysql_host'], $config['mysql_user'], $config['87%!IuQs'])) {
error(500,'database connexion failed');
die;
}
mysqli_select_db($lnMySQL,$config['mysql_database']);
mysqli_set_charset($lnMySQL, 'utf8');
function hash_map($map,$me,$opponent){
$hashMap = "";
foreach($map as $line){
foreach ($line as $cell){
switch($cell){
case $me:
$hashMap.="1";
break;
case $opponnent:
$hashMap.="2";
break;
default:
$hashMap.="0";
break;
}
}
}
return base_convert($hashMap, 3, 10);
}
function play($map,$colToPlay,$me,$opponnent,$gameid){
//save the lap on the database and then send the play response
//transform map as string
}
function can_win($line,$myChar,$depth=0){ function can_win($line,$myChar,$depth=0){
//retourne la position du caractere a remplacer dans la ligne pour gagner //retourne la position du caractere a remplacer dans la ligne pour gagner
$arr=array(); $arr=array();
@ -263,8 +307,6 @@ switch($params['action']){
//transformer la grille en lignes horizontales, verticales et diagonales //transformer la grille en lignes horizontales, verticales et diagonales
//verticales //verticales
for($x = 0; $x <7; $x ++){ for($x = 0; $x <7; $x ++){
$colStr=""; $colStr="";
@ -319,7 +361,6 @@ switch($params['action']){
} }
$choice = analize($diagStr,$params['you'],$opponent,false,0); $choice = analize($diagStr,$params['you'],$opponent,false,0);
} }
//print_r($choice);
//si j'arrive là, je ne gagne pas à ce tour //si j'arrive là, je ne gagne pas à ce tour
@ -342,9 +383,6 @@ switch($params['action']){
} }
} }
if(count($choice['colForNoLose']) > 0){ if(count($choice['colForNoLose']) > 0){
//intersection entre $choice['colForNoLose'] et $colAvailable //intersection entre $choice['colForNoLose'] et $colAvailable
@ -398,6 +436,3 @@ switch($params['action']){
default: default:
break; break;
} }