[ create a new paste ] login | about

Link: http://codepad.org/Q62l2wfv    [ raw code | fork ]

Giorgio - PHP, pasted on Dec 20:
<?php

// Players' stack
$stack = array(5000,3000,2000,1000,2500,2511,522,500);


function equity ($stack) {
	
	$tot_stack = 0;
	$remanent_stack = 0;
	
	// Create the 'result' array as follow
	// NUM CHIPS | Equity 1° | Equity 2°  | Equity 3°
	// X modificare $result[0][3]= xxx;
	$result = array();
	foreach ($stack as $s) {
	array_push($result,array($s,0,0,0));						 
	}
	
	
	//Total chips value
	foreach ($stack as $s) {
		$tot_stack = $s + $tot_stack;
	}
	
	
	//Equity on 1st place
	$c = 0;
	foreach($stack as $s) {
	$eq = $s/$tot_stack;
	$result[$c][1] = round($eq,5);
	$c++;
	}
	
	//Equity on 2nd place
	$c = 0;
	foreach($stack as $s) {
	        $eq = 0;
		$control =0;
		for($a=0;$a<count($stack);$a++) {
			if($result[$a][0]==$s AND $control==0) {$control=1;}
			else {
			$sub = $tot_stack - $result[$a][0]; 
			$eq = $eq + $result[$a][1]*($s/$sub);
			}//chiudo else
		}
		$eq = round($eq,5);
		$result[$c][2] = $eq;
		
		$c++;
	}//End foreach
	
	
	//Equity on 3rd place
	$c = 0;
	foreach($stack as $s) {
		$eq = 0;
		$control =0;
		$control2 =0;
		for($a=0;$a<count($stack);$a++) {
			
			$stack_gf=$result[$a][0];
			
			for($t=0;$t<count($stack);$t++){
			        
                                //some controls
				if($result[$t][0]==$stack_gf) {}
				else if($result[$a][0]==$result[$t][0] ) {}
				else if($s==$result[$t][0] ) {}
				else if($stack_gf==$result[$c][0] ) {}
				else if($result[$t][0]==$s) {}
			else{
		
				$remanent_stack = $tot_stack - $result[$t][0] - $result[$a][0];
				
                                //calculate the equity on 2nd place of G2
				$eqq = ($result[$a][0]/($tot_stack-$result[$t][0]));
				$result[$c][3] = $result[$c][3] + $result[$t][1]*$eqq*($s/$remanent_stack); 
		
			
			}


			}//close else
		}//close for
		$c++;
	}//chiudo secondo foreach
	
	
	
//////////////	
//CHECK if everything is fine and return
//////////////

	print_r($result);
	return($result);
}
?>


Create a new paste based on this one


Comments: