<?php
	session_start();
	
	include('correlation.php');
	
						
			if(isset($_POST["J1"]) && isset($_POST["J2"]) )
			{
				$J1_nom =  $_POST["J1"]; 
				$J2_nom =  $_POST["J2"];	
			}
				
			//$sql = "SELECT * FROM classement WHERE joueur = '".$J1_nom."' ";
			$sql = "SELECT * FROM " .$_SESSION['classement'] ." WHERE joueur = '".$J1_nom."' ";
			
			$results = mysql_query($sql);
			$val = mysql_fetch_array($results);
			$elo1 =  $val['elo'];
			
			//$sql = "SELECT * FROM classement WHERE joueur = '".$J2_nom."' ";
			$sql = "SELECT * FROM " .$_SESSION['classement'] ." WHERE joueur = '".$J2_nom."' ";
						
			$results = mysql_query($sql);
			$val = mysql_fetch_array($results);
			$elo2 =  $val['elo'];
			
			$_SESSION['$J1_nom'] = $J1_nom;
			$_SESSION['$J2_nom'] = $J2_nom;  
			
			// echo '<h3>Côte initiale</h3>
					// Blanc : '.$elo1.'<br>
					// Noir : '.$elo2.'<br>
				 // ';

			//pourcentage
			$chance_of_winning = abs((1 / ( 1 + pow(10, ( ($elo2 - $elo1) / 400) ) )) * 100); 
			$chance_of_losing = abs(100 - $chance_of_winning);

			//echo "<br/>";
			//echo "----------------------------------------------------------";
			//echo "<br/>";
			
			//echo ' Blanc (J1) : Probabilité de gagner : '  .round($chance_of_winning , 2).' %';
			//echo '<br/>';
			//echo ' Noir (J2) : Probabilité de gagner : '  .round($chance_of_losing , 2).' %';
			//echo '<br/>';

			//echo "----------------------------------------------------------";
			//echo "<br/>";
			
			$donnees[0] = 0;
			$donnees[1] = $J1_nom;
			$donnees[2] = $J2_nom;
			$donnees[3] = 1;
			$donnees[4] = 0;
			$retour = estimation_elo($donnees); 
			
			//echo $retour;
			//echo '<br/>';
			$pieces = explode("+", $retour);
			$diff = $pieces[0] - $pieces[1];
			$res1 = $pieces[0] .' ('.$diff .')';
			//echo "Blanc (J1) :  gagne ,  passe de " .$pieces[1]  ." à " .$pieces[0]   .' ('.$diff .')';
			//echo '<br/>';
			$diff = $pieces[2] - $pieces[3];
			$res2 = $pieces[2] .' ('.$diff .')';
			//echo ' Noir (J2) : perd , passe de '  .$pieces[3] ." à " .$pieces[2]  .' ('.$diff .')';
			//echo '<br/>';
			
			//echo "----------------------------------------------------------";
			//echo "<br/>";
		
			$donnees[0] = 0;
			$donnees[1] = $J1_nom;
			$donnees[2] = $J2_nom;
			$donnees[3] = 0;
			$donnees[4] = 1;
			$retour = estimation_elo($donnees); 
			
			//echo $retour;
			//echo '<br/>';
			$pieces = explode("+", $retour);
			$diff = $pieces[0] - $pieces[1];
			$res3 = $pieces[0] .' ('.$diff .')';
			//echo "Blanc (J1) :  perd ,  passe de " .$pieces[1]  ." à " .$pieces[0]   .' ('.$diff .')';
			//echo '<br/>';
			$diff = $pieces[2] - $pieces[3];
			$res4 = $pieces[2] .' ('.$diff .')';
			//echo ' Noir (J2) : gagne , passe de '  .$pieces[3] ." à " .$pieces[2]  .' ('.$diff .')';
			//echo '<br/>';
		
			//echo "----------------------------------------------------------";
			//echo "<br/>";
			
			$donnees[0] = 0;
			$donnees[1] = $J1_nom;
			$donnees[2] = $J2_nom;
			$donnees[3] = 0.5;
			$donnees[4] = 0.5;
			$retour = estimation_elo($donnees); 
						
			//echo $retour;
			//echo '<br/>';
			$pieces = explode("+", $retour);
			$diff = $pieces[0] - $pieces[1];
			$res5 = $pieces[0] .' ('.$diff .')';
			//echo "Blanc (J1) :  nul ,  passe de " .$pieces[1]  ." à " .$pieces[0]   .' ('.$diff .')';
			//echo '<br/>';
			$diff = $pieces[2] - $pieces[3];
			$res6 = $pieces[2] .' ('.$diff .')';
			//echo ' Noir (J2) : nul , passe de '  .$pieces[3] ." à " .$pieces[2]  .' ('.$diff .')';
			//echo '<br/>';
		
			//echo "----------------------------------------------------------";
			//echo "<br/>";
			//echo "<br/>";
			
			
?>			
			<br>
			<table border="1" style="width:100%">
			<tr align="center">
			<td>ELO</td>
			<td>Probabilité</td>
			<td>Banc gagne</td>		
			<td>Blanc perd</td>
			<td>Match nul</td>
			</tr>

			<tr align="center">
			<td><?php echo "Blanc: " .$elo1; ?></td>
			<td><?php echo round($chance_of_winning , 2).' %'; ?> </td>		
			<td><?php echo $res1; ?></td>
			<td><?php echo $res3; ?></td>
			<td><?php echo $res5; ?></td>
			</tr>
  
			<tr align="center">
			<td><?php echo "Noir: " .$elo2; ?></td>
			<td><?php echo round($chance_of_losing , 2).' %'; ?></td>		
			<td><?php echo $res2; ?></td>		
			<td><?php echo $res4; ?></td>
			<td><?php echo $res6; ?></td>
			</tr>
			</table>
