I would like to build a simulation engine which can simulate a soccer (association football) match. It would be cool great if you could help me. What is important to me is t
I would suggest you convert all your probabilities to percentages:
function Chance($chance, $universe = 100)
{
$chance = abs(intval($chance));
$universe = abs(intval($universe));
if (mt_rand(1, $universe) <= $chance)
{
return true;
}
return false;
}
Chance(25); // 25%
Chance(5, 1000); // 0.5%
Also I would only instantiate some probabilities with the conditions of others, example:
if ($attack === true)
{
if (Chance(15 * $aggressivity) === true)
{
if (Chance(10 * $aggressivity) === true)
{
// red card
}
else
{
// yellow card
}
}
}
EDIT: I just home and I really need to go to sleep but after a quick glance at your edit I just had an idea that might interest you. What if, instead of using a adjustment value of 1, 2 or 3 don't you use the tactical position of the team? For instance, a team with a 4-4-2 would have less chances of scoring a goal against a 5-3-2 team than with a 3-3-4 team. Assuming that the placements are always triplets (X-Y-Z) it would be pretty easy to compare which team performs the best at defending, passing and scoring.
A simple formula could be something like this:
A: 4-4-2 (Defending Team)
B: 3-2-5 (Attacking Team)
The chance of B scoring a goal would be (4 / 5) ^ -1 = 0.2 = 20%, and the inverse (team A scoring) would be (3 / 2) ^ -1 = 0.5 = 50%. PS: This doesn't seem to make much sense now, but I'll try to give another look at it in the morning.
And another thing: after a red card why does the faulting team stays the same? It should get weaker (one player less) IMO.