Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Adjusting basic football simulation algorithm without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I need help with adjusting my very basic football matches simulation algorithm. It doesn’t need to take in account anything other than team rating (combined rating of team players). I came up with something, but the results are not very interesting: picture i.e they almost always end up (zero) – (something)

Here’s the algorithm

``` double flagIncrementer = 0.10;
while(!flag){
if(new Random().nextDouble() <= baseChance - (homeTeamRating - awayTeamRating)){
teamAwayScore++;
boolean scoredFlag = false;
while(!scoredFlag){
for(Player player : away.getPlayerList()){
if(new Random().nextDouble() <= player.getProbabilityWeight()){
scoredFlag = true;
break;
}
}
}
}
if(new Random().nextDouble() <= baseChance - (awayTeamRating - homeTeamRating)){
teamHomeScore++;
boolean scoredFlag = false;
while(!scoredFlag){
for(Player player : home.getPlayerList()){
if(new Random().nextDouble() <= player.getProbabilityWeight()){
scoredFlag = true;
break;
}
}
}
}
if (new Random().nextDouble() <= flagIncrementer) {
flag = true;
} else {
flagIncrementer += 0.10; //inkrementiraj kako bi se izbjegla beskonačna petlja
}

}
```

It’s very simple, I just generate a random number and then see if I get a number that is less than the base chance accounted for difference in team rating. I repeat that for second team. Loop can exit on the first iteration, but it doesn’t have to be. If it doesn’t, I increment my control variable so it has a higher chance to exit on the next iteration.

I’m not particularly adept at statistics nor math, but even directing me in the right way is very much appreciated.