First of im new to this site and I've never been the sharpest at math, im a web developer by trade.
My question is math related but ill just give you a quick background about my website so that you can get a better understanding about my question.
My website predicts the chance of teamX winning against teamY everything is working perfectly except I sometimes get a result like this which is wrong.
TeamX chance 60% TeamY chance 75%
My Question
How can I change this so that the combined chances of both teams does not go over 100%
Some of the formula I am using follows:
//teamstrength1
$teamstrength = ($teamstrength / 30 * 20);
//teamstrength2
$team2strength = ($team2strength /30 * 20);
//add international experience for team1
$teamstrength = $teamstrength + $internationalPlayersT1;
//add international experience for team2
$team2strength = $team2strength + $internationalPlayersT2;
//add players which is better for team 1
$teamstrength = $teamstrength + $bettert1;
//add players who is better for team2
$team2strength = $team2strength + $bettert2;
//add homefield advantage
$teamstrength = $teamstrength + 5;
//echo team chances
echo'<h2>Match Prediction</h2>';
echo '<h3>'.$Team[0].' chance '.floor($teamstrength).'%</h3>';
echo '<h3>'.$Team2[0].' chance '.floor($team2strength).'%</h3>';
if($teamstrength > $team2strength){
echo'<h4>Recommended Pick '.$Team[0];
}
else if($team2strength > $teamstrength){
echo'<h4>Recommended Pick '.$Team2[0];
}
In your code, you are taking two "base" variables, teamstrength and team2strength and multiplying each of them by 20/30 or 2/3 $\approx 0.667$. Then you are adding on a bunch of numbers to account for player skill and home team advantage.
Without knowing the ranges of your various "factors" and for the base variables, I don't know what effect each line is having. However, nowhere do you normalize the scores to get a relative advantage - so I am surprised you are actually getting resonable numbers (again depending on how you've specified the ranges of each score adjustment and the base score).
Tyler's comment gave you one such way to do this to ensure that not only do the combined chances stay below 100%, but that they actually add to 100% exactly (since one team MUST win, correct, or are ties allowed?) If ties are allowed, then you will need to adjust your code.
The bottom line is that somewhere in your code, you need to divide each team's strength the the sum of both team's strengths so that your are able to apportion likelihood using the relative strength - then you should be ok.