<?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."' ";
			$results = mysql_query($sql);
			$val = mysql_fetch_array($results);
			$elo1 =  $val['elo'];
			
			$sql = "SELECT * FROM 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>cote 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];
			echo "Blanc (J1) :  gagne ,  passe de " .$pieces[1]  ." à " .$pieces[0]   .' ('.$diff .')';
			echo '<br/>';
			$diff = $pieces[2] - $pieces[3];
			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];
			echo "Blanc (J1) :  perd ,  passe de " .$pieces[1]  ." à " .$pieces[0]   .' ('.$diff .')';
			echo '<br/>';
			$diff = $pieces[2] - $pieces[3];
			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];
			echo "Blanc (J1) :  nul ,  passe de " .$pieces[1]  ." à " .$pieces[0]   .' ('.$diff .')';
			echo '<br/>';
			$diff = $pieces[2] - $pieces[3];
			echo ' Noir (J2) : nul , passe de '  .$pieces[3] ." à " .$pieces[2]  .' ('.$diff .')';
			echo '<br/>';
		
			echo "----------------------------------------------------------";
			echo "<br/>";
			echo "<br/>";
			

?>	