Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In general, it looks like this is a fairly complicated problem, and I'm not sure how efficient you'll get it.</p> <p>That said, I have seen some things which would decidedly help you.</p> <p>First I would type the variables in the parameters. This may not necessarily make your code faster, but it would make it easier to read and debug. Next, I would remove the $teamname_att, $teamname_def parameters and simply have those as values in the associative $strength_att, $strength_def arrays. Since this data is always paired up anyway, this will reduce the risk of accidentally using one team's name as a reference to the other team.</p> <p>This will make it so you will not have to continually look up values in arrays:</p> <pre><code>// replace all $tactics[$teamname_att] with $attackers $attackers = $tactics[$teamname_att]; $defenders = $tactics[$teamname_def]; // Now do the same with arrays like $_POST[ "team1" ]; </code></pre> <p>You have three helper functions which all have the pattern:</p> <pre><code>function foo( $arg ){ $bar = $arg * $value; return $bar; } </code></pre> <p>Since this means that you have to create an extra variable (something which can be costly) each time you run the function, use these instead:</p> <pre><code>function tactics_weight($wert) { return $wert*0.1+0.8; } function strengths_weight($wert) { return log10($wert+1)+0.35; } /* Perhaps I missed it, but I never saw Chance_Percent( $num1, $num2 ) consider using this function instead: (one line instead of four, it also functions more intuitively, Chance_Percent is your chance out of 100 (or per cent) function Chance_Percent( $chance ) { return (mt_rand(1, 100) &lt;= $chance); } */ function Chance_Percent($chance, $universe = 100) { $chance = abs(intval($chance)); // Will you always have a number as $chance? // consider using only abs( $chance ) here. $universe = abs(intval($universe)); return (mt_rand(1, $universe) &lt;= $chance); } </code></pre> <p>I couldn't help but notice this pattern coming up consistently:</p> <pre><code>$matchReport .= ' ' . comment_action($teamname_att, 'attack'); </code></pre> <p>My general experience is that if you move the concatenation of $matchReport into comment_action, then it will be just <em>slightly</em> faster (Generally less than a dozen milliseconds, but since you're calling that function a half-dozen times inside of a recursive function, this could shave a couple tenths of a second per running).</p> <p>I think that this would flow much better (both from a reader's perspective, and from </p> <p>Finally, there are several times where you will use the same call to the same function with the same parameter. Make that call up front:</p> <pre><code>$goalieStrength = strengths_weight($strength_def['goalkeeper']); </code></pre> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload