Beautiful. And it works much faster than with the nested loops.
I edited it (see below). I put the results in the arrays TextFieldHomeScore() and TextFieldAwayScore(), this only needs to be done once: when user starts the Predictions component.
After that, it is always used to calculate the prediction of the desired ranking of a desired team, depending on matches already played.
Such a prediction in each group with 4 teams (FIFA WC Qatar 2022), only makes sense if each team has played at least 1 match.
This brings me to DonManfred's reaction: what to do in a long season of home and away matches? Again, a prediction only makes sense if there are still 6 (or 5 or 4 or 3) matches to be played in that season.
You then use the existing ranking in a group and analyze the remaining (so a maximum of 6) matches.
I realize that I still have a lot to adjust in my app.
<
Sub MakePlayList
Private TextFieldHomeScore(1000,31), TextFieldAwayScore(1000,31) As String 'i need to adjust this...
'and thus we'd be expecting 3 ^ 6 = 729 groups each containing a different permutation of 6 game results.
'Dim NumTeams As Int = Main.TotalTeamsPerGroupe(1) 'now it is 4 '2..5 or maybe 6 if you don't mind waiting
'There is a problem if some groupes have more or less teams. Then extra work to do...
Dim NumTeams As Int = 4 '2..5 or maybe 6 if you don't mind waiting
Dim NumTournamentGames As Int = NumTeams * (NumTeams - 1) / 2
Dim sb As StringBuilder
'*** TOURNAMENT GAMES HEADING LINE ***
' sb.Initialize
' For T1 = 1 To NumTeams
' For T2 = T1 + 1 To NumTeams
' sb.Append(TAB & Chr(64 + T1) & Chr(64 + T2)) 'teams are named A, B, C, etc (ASCII 65, 66, 67, etc)
' Next
' Next
' Log(TAB & sb.ToString)
Dim WinDrawLoss() As String = Array As String("1-0", "1-1", "0-1")
Dim GameResult(NumTournamentGames) As Int 'start at all zero
Dim NumTournamentOutcomes As Int = 0
Dim DoneFlag As Boolean = False
Do Until DoneFlag
NumTournamentOutcomes = NumTournamentOutcomes + 1
'*** TOURNAMENT GAME RESULTS ***
sb.Initialize
For G = 0 To NumTournamentGames - 1
'sb.Append(TAB & WinDrawLoss(GameResult(G)))
sb.Append(WinDrawLoss(GameResult(G)))
Next
Log(NumTournamentOutcomes & TAB & sb.ToString)
Dim i As Int=0
Dim GameIndex As Int=0
For i=0 To sb.ToString.Length-1
If sb.ToString.CharAt(i)="-" Then
GameIndex=GameIndex+1
TextFieldHomeScore(NumTournamentOutcomes,GameIndex)=sb.ToString.CharAt(i-1)
TextFieldAwayScore(NumTournamentOutcomes,GameIndex)=sb.ToString.CharAt(i+1)
End If
Next
'*** INCREMENT TO NEXT TOURNAMENT OUTCOME ***
DoneFlag = True 'set false if increments without wraparound back to all zero
For G = 0 To NumTournamentGames - 1
If GameResult(G) < 2 Then
GameResult(G) = GameResult(G) + 1
DoneFlag = False
Exit
Else
GameResult(G) = 0
End If
Next
Loop
Dim ExpectedNumTournamentOutcomes As Long = Power(3, NumTournamentGames)
Log("Double-check: 3 ^ " & NumTournamentGames & " = " & ExpectedNumTournamentOutcomes)
Dim i,j As Int
For i= 1 To NumTournamentOutcomes
Log("all scores "&i)
For j=1 To 6
Log(TextFieldHomeScore(i,j) & TextFieldAwayScore(i,j))
Next
Next
End Sub
>