Soccer simulation for a game

后端 未结 4 1122
青春惊慌失措
青春惊慌失措 2020-12-22 17:39

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

4条回答
  •  滥情空心
    2020-12-22 18:03

    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.

提交回复
热议问题