Files
resatennis_tyroltenn/www/site_inscription/baseFaitsTableau_bis.php

243 lines
10 KiB
PHP
Executable File

<?PHP
$categorie=$_POST['categorie'];
$double=$_POST['double'];
$nb_qualif=$_POST['nb_qualif'];
$fin_tranche=$_POST['fin_tranche'];
copy("faits_fixes_tableau.fai","./cer/tab/tab.fai");
$faits=fopen("./cer/tab/tab.fai","a");
include("conf.php");
include("mysql_compat.php");
include ("conf.php");
$db_connection=mysql_connect($db_host,$db_user,$password);
mysql_select_db($db_name,$db_connection);
//////////////////////////////////////////////////RECHERCHE DES JOUEURS DANS CETTE CATEGORIE/////////////////////////////////////
$tab_classement=array("0/6","1/6","2/6","3/6","4/6","5/6","15/0","15/1","15/2","15/3","15/4","15/5","30/0","30/1","30/2","30/3","30/4","30/5","NC");
/////////////// RECHERCHE DES JOUEURS QUI VONT ENTRER DANS LE TOURNOI ////////////////////////////////
for ($i=$avencement-1;$i>=$fin_tranche;$i--){
$requete="SELECT classement, id_inscription FROM `inscription`, `joueur`
WHERE inscription.categorie = '$categorie'
AND joueur.classement = '$i'
AND inscription.joueur=joueur.id_joueur AND inscription.valider='1';";
$reponse=mysql_query($requete,$db_connection) or die ("Erreur no".mysql_errno()." : ".mysql_error()."<br>");
while ($reptab=mysql_fetch_array($reponse)){
$nb_joueur++;
$ligne="JOUEUR_".$['']." ' JOUEUR\n";fwrite($faits,$ligne);
$ligne="JOUEUR_".$['']." JOUE PAS_D_ADVERSAIRE\n";fwrite($faits,$ligne);
$ligne="JOUEUR_".$['']." ENTRE TOUR_1\n";fwrite($faits,$ligne);
$ligne="JOUEUR_".$['']." EST_CLASSE ".$tab_classement[$['']]."\n";fwrite($faits,$ligne);
$tour[$['']]=1;
}
}
global $infoTour;
if ($nb_joueur > 2*$nb_qualif){
$nb_inscrit[]=0;
for ($i=19;$i>=0;$i=$i-1){
$nb_inscrit[$i]=0;
}
$requete2="SELECT joueur FROM inscription WHERE categorie='$categorie' AND valider='1'";
$reponse2=mysql_query($requete2,$db_connection) or die ("Erreur no".mysql_errno()." : ".mysql_error()."<br>");
while ($inscription=mysql_fetch_object($reponse2)){
$requete3="SELECT classement,nom,prenom FROM joueur WHERE id_joueur='$inscription->joueur'";
$reponse3=mysql_query($requete3,$db_connection) or die ("Erreur no".mysql_errno()." : ".mysql_error()."<br>");
$joueur1=mysql_fetch_object($reponse3);
$classement=$joueur1->classement;
$nb_inscrit[$classement]=$nb_inscrit[$classement]+1;
}
$max=0;
for( $i=0;$i<19;$i++){
if ($nb_inscrit[$i]>$max){
$max=$nb_inscrit[$i];
}
}
//echo "max : ",$max,"<br>";
$nb_tour=$nb_joueur/$max;
$nb_tour=floor($nb_tour);
/*********************************************RECHERCHE DE LA CATEGORIE DU DEBUT DU TABLEAU************************/
//echo "nb tour : ",$nb_tour,"<br>";
$j=19;
for ($j;$j>=0;$j=$j-1){
if ($nb_inscrit[$j]!=0) {
$debut=$j;
break;
}
}
//echo "Début : ",$tab_classement[$debut]," Nombre : ",$nb_inscrit[$debut],"<br>";
/*****************************************************************************************************/
/*********************************************RECHERCHE NB COMPRESSION ************************/
$Nb_comp=abs($nb_inscrit[$debut]-$nb_qualif);
//echo "Nb compression : ",$Nb_comp,"<br>";
/*****************************************************************************************************/
/*********************************************RECHERCHE NB MATCH A PLACER ************************/
$nb_match_a_placer=$nb_joueur-$nb_qualif;
//echo "Nb match à placer : ",$nb_match_a_placer,"<br>";
/*****************************************************************************************************/
/*********************************************PLACEMENT MATCH TOUR MAX ************************/
$infoTour[$nb_tour-1][nb_match]=$nb_qualif+$Nb_comp;
$infoTour[$nb_tour-1][nb_joueur_entrant]=$nb_qualif*2+$Nb_comp*2;
$nb_match_a_placer=$nb_match_a_placer-$nb_qualif*2-$Nb_comp;
$nb_joueur_restant=$nb_joueur-($nb_qualif*2+$Nb_comp*2);
//echo "Nb match à placer : ",$nb_match_a_placer,"<br>";
//echo "Nb joueur à placer : ",$nb_joueur_restant,"<br>";
/*****************************************************************************************************/
/*********************************************CAS POSSIBLE POUR LE NOMBRE DE MATCHS RESTANTS ************************/
$indice2=0;
for ($i=$nb_qualif;$i<=($nb_qualif+$Nb_comp);$i++){
for ($indice=0;$indice<$nb_tour-2;$indice++){
$nb[$indice][$indice2]=$i;
}
$indice2++;
}
if ($nb_tour=="4"){
$i=0;
$k=1;
for ($j=0;$j<=$Nb_comp;$j++){
if ($k<$nb_tour-2){
for ($l=0;$l<=$Nb_comp;$l++){
if ($nb[$i][$j]>=$nb[$k][$l]){
/*echo $i,"-",$j;
echo " | ",$nb[$i][$j]," | ";
echo $k,"-",$l;
echo " | ",$nb[$k][$l]," | ";*/
$total=$nb[$i][$j]+$nb[$k][$l];
if ($total==$nb_match_a_placer){
$infoTour[$nb_tour-2][nb_match]=$nb[$i][$j];
$infoTour[$nb_tour-2-$k][nb_match]=$nb[$k][$l];
//echo "total : ",$total,"<br>";
break;
}
else{
//echo "<br>";
}
$total=0;
}
}
}
}
/*****************************************************************************************************/
/*********************************************CALCUL DU NOMBRE DE MATCH PAR TOUR ************************/
for( $ind=$nb_tour-1;$ind>=1;$ind--){
if ($infoTour[$ind][nb_match]>=$infoTour[$ind-1][nb_match] and $infoTour[$ind-1][nb_match]!=""){
$p=$infoTour[$ind][nb_match]-$infoTour[$ind-1][nb_match];
//echo "tour ",$ind," diff ",$p;
if ($ind==$nb_tour-1){
$infoTour[$ind-1][nb_joueur_entrant]=$infoTour[$ind-1][nb_match]-$p;
$nb_joueur_restant=$nb_joueur_restant-$infoTour[$ind-1][nb_joueur_entrant];
//echo $nb_joueur_restant;
}
else {
//echo $infoTour[$ind][nb_joueur_entrant];
$infoTour[$ind-1][nb_joueur_entrant]=$infoTour[$ind-1][nb_match]-$p;
$nb_joueur_restant=$nb_joueur_restant-$infoTour[$ind-1][nb_joueur_entrant];
//echo $nb_joueur_restant;
}
}
}
}
else if ($nb_tour=="3"){
$infoTour[1][nb_match]=$nb_match_a_placer;
if ($infoTour[1][nb_match]<=$infoTour[2][nb_match]){
$e=$infoTour[2][nb_match]-$infoTour[1][nb_match];
$infoTour[1][nb_joueur_entrant]=$infoTour[1][nb_match]-$e;
$nb_joueur_restant=$nb_joueur_restant-$infoTour[1][nb_joueur_entrant];
}
}
/*****************************************************************************************************/
/*********************************************PLACEMENT MATCH TOUR 0 ************************/
$infoTour[0][nb_match]=$nb_qualif;
$infoTour[0][nb_joueur_entrant]=$nb_joueur_restant;
/*****************************************************************************************************/
$ligne="\n\n";fwrite($faits,$ligne);
$ligne="NB_TOUR ' ".$nb_tour."\n";fwrite($faits,$ligne);
$ligne="TOUR_COURANT ' ".$nb_tour."\n";fwrite($faits,$ligne);
for( $i=$nb_tour-1;$i>=0;$i--){
$no_tour=$nb_tour-$i;
//echo "<br> ".$no_tour."++joueurs entrants++".$infoTour[$i][nb_joueur_entrant]."++nb match++".$infoTour[$i][nb_match];
//echo "<br> infoTour[".$i."][nb_joueur_entrant]".$infoTour[$i][nb_joueur_entrant]."<br>";
//echo "<br> infoTour[".$i."][nb_match]".$infoTour[$i][nb_match]."<br>";
$ligne="\nTOUR_".$no_tour." ' TOUR\n";fwrite($faits,$ligne);
$ligne="TOUR_".$no_tour." NUMERO ".$no_tour."\n";fwrite($faits,$ligne);
$ligne="TOUR_".$no_tour." NB_MATCH ".$infoTour[$i][nb_match]."\n";fwrite($faits,$ligne);
$ligne="TOUR_".$no_tour." NB_JOUEUR_ENTRANT ".$infoTour[$i][nb_joueur_entrant]."\n";fwrite($faits,$ligne);
for($j=0;$j<$infoTour[$i][nb_match];$j++){
//if ($no_tour<$nb_tour) {
$ligne="VAINQUEUR_".$no_tour."-".$j." ' JOUEUR\n";fwrite($faits,$ligne);
$ligne="VAINQUEUR_".$no_tour."-".$j." JOUE PAS_D_ADVERSAIRE\n";fwrite($faits,$ligne);
$ligne="VAINQUEUR_".$no_tour."-".$j." ENTRE TOUR_".($no_tour + 1)."\n";fwrite($faits,$ligne);
$ligne="VAINQUEUR_".$no_tour."-".$j." EST_CLASSE PIRE\n";fwrite($faits,$ligne);
// }
}
}
fclose($faits);
//echo "base faits ecrite.<br>";
//echo "lancement des moteurs "systeme expert";
$file="tab";
$dir="cer/tab/";
//echo "compil -rf 1 bcc=".$dir.$file.".bcc reg=".$dir.$file.".reg fts=".$dir.$file.".fai err=".$dir.$file.".err1 m=n"."<br>";
exec("./cer/compil -rf 1 bcc=".$dir.$file.".bcc reg=".$dir.$file.".reg fts=".$dir.$file.".fai err=".$dir.$file.".err1 m=n");
//echo "moteur bcc=".$dir.$file.".bcc fts=".$dir.$file.".fai res=".$dir.$file.".res err=".$dir.$file.".err2 t=4 s=c m=n"."<br>";
exec("./cer/moteur bcc=".$dir.$file.".bcc fts=".$dir.$file.".fai res=".$dir.$file.".res err=".$dir.$file.".err2 t=4 s=c m=n");
//echo "<br><br><br>";
$env=fopen("./cer/tab/tab.env","r");
$i=0;
while(!feof($env)){
$ligne=fgets($env);
//echo $ligne."<br>";
list($objet,$attribut,$valeur)=explode(" ",$ligne);
switch ($attribut){
case "ENTRE" :
list($type_joueur,$id_insc)=explode("_",$objet);
if ($id_insc[0]=='Q'){
list($rien,$no_match)=explode("Q",$id_insc);
$tour_q[$no_match]=$valeur[5];
}
else
$tour[$id_insc]=$valeur[5];
//echo $id_insc." entre tour".$tour[$id_insc]."<br>";
break;
case "JOUE" :
list($type_joueur1,$id_insc1)=explode("_",$objet);
list($type_joueur2,$id_insc2)=explode("_",$valeur);
if ($type_joueur1=="JOUEUR") {
$info_match[$i][insc1]=$id_insc1;
if ($id_insc1[0]=='Q'){
list($rien,$no_match)=explode("Q",$id_insc1);
$info_match[$i][tour]=$tour_q[$no_match];
}
else
$info_match[$i][tour]=$tour[$id_insc1];
}
else {
$info_match[$i][insc1]="V";
list($tour,$rien)=explode("-",$id_insc1);
$info_match[$i][tour]=$tour+1;
}
if ($type_joueur2=="JOUEUR") {
$info_match[$i][insc2]=$id_insc2;
}
else {
$info_match[$i][insc2]="V";
list($tour,$rien)=explode("-",$id_insc2);
$info_match[$i][tour]=$tour+1;
}
$i++;
break;
default :
break;
}
}
for($i=0;$i<count($info_match);$i++){
//echo "tour ".$info_match[$i][tour]." : ".$info_match[$i][insc1]."-".$info_match[$i][insc2]."<br>";
$match[$info_match[$i][tour]][]=$info_match[$i][insc1]."-".$info_match[$i][insc2];
}
include ("enregistrementMatch.php");
}
else {
$erreur= "<center><font color=00ff00><h3>Il n'y a pas assez de joueurs pour faire ".$nb_qualif." matchs aux dernier tour.</h3></font></center>";
include ("quelTranche.php");
}
?>