Code of algorithm used to generate fixture list templates
These routines were written in Microsoft Quick Basic 3. As such they should be comprehensible to most programmers even if they normally use more sophisticated languages.

I wrote these some 20 years ago! I remember struggling with some sections that I can no longer follow. These sections were added to ensure a maximum of 2 consecutive Home or Away fixtures and to provide the maximum number of Buddy Teams. Neverthless they still run either interpretively or complied as .EXE files.
'=============================================================================
SUB Matches(t%,W$(1)) STATIC
    'Subroutine "Matches":
    '    Accepts t% as the number of Teams playing in League/Division
    '    Returns array W$() containing the matches for each week:
    '        Wk#|Mch#  1|Mch#  2|Mch#  3|Mch#  4|Mch#  5|
    '          1| 1 v 10| 2 v  9| 3 v  8| 4 v  7| 5 v  6|
    '          2| 9 v  1| 8 v  2| 7 v  3| 6 v  4|10 v  5|
    '          3| 1 v  8| 2 v  7| 3 v  6| 4 v  5|10 v  9|
    '          4| 7 v  1| 6 v  2| 5 v  3| 8 v  9| 4 v 10|    
    '        Etc., etc.
    ' Where '|' is CHR$(166) to give acceptable print as the non-ASCII 
    ' character used in the online HTML.
    
' NOTE: t% may be an odd number but league/division must work
    '       with an even number thus:-

    Teams% = 2 * INT((t% + 1)/2) 'Round up to next even #.

    MperW% = INT(Teams%/2)       '  Matches played per Week
    Sw% = Teams% - 1             '  Number of weeks in semi-season
    NoW% = 2 * Sw%               '  Number of weeks in season


    CALL Addheadings(MperW%,W$(1))

    f$ = STRING$(MperW%,"0") + STRING$(MperW%,"1") + STRING$(MperW%,"0")

    REDIM Rev$(2*Teams%)' Array Rev$() holds strings of "0" & "1" to flag
			' matches for reversal of Home & Away teams
			' Used empirically and to reverse second half of
			' season.

    FOR n% = 1 TO Sw%

      IF n% = INT(n%/2) * 2 THEN
	 IF n% > 2 THEN m% = n% + 2 ELSE m% = n%
	 Rev$(n%) = MID$(f$,MperW% + m%/2,MperW%)
      ELSE
	 Rev$(n%) = MID$(f$,INT( (n%+ 1)/2 ),MperW%)
      END IF

      Rev$(n% + Sw%) = Rev$(n%)
    NEXT
      
    'Prime strings for weeks' matches
    FOR i% = 1 TO NoW%: CALL AddB( i%,MperW%,W$(i% + 1)): NEXT

    FOR H% = 1 TO MperW%
       Sc% = 8*(H% - 1)

       FOR Nxt% = 2 TO Teams%
	  A% = Teams% - H%  - Nxt%  + 3

	  IF A% > H% THEN
	     C% = H%
	     D% = A%
	     Less% = 0
	  ELSE
	     Less% = Less% + 1
	     C% = MperW% + H% - Less%
	     D% = MperW% + H%
	  END IF
          
          c$ = STR$(c%):IF c% > 9 THEN c$ = MID$(c$,2,LEN(c$))
	  d$ = STR$(d%):IF d% > 9 THEN d$ = MID$(d$,2,LEN(d$))
	  MID$(W$(Nxt%), 5 + Sc%,2) = c$
	  MID$(W$(Nxt%),10 + Sc%,2) = d$
       NEXT

    NEXT

    Less% = 0
    Os% =  5 + 8*(MperW% - 1)

    FOR i% = 2 TO Teams% - 1 STEP 2
       Less% = Less% + 1
       a% =  Teams%/2 - Less% + 1
       a$ =  STR$(a%):IF a% > 9 THEN a$ = MID$(a$,2,LEN(a$))
       b% =  Teams%   - Less%
       b$ =  STR$(b%):IF b% > 9 THEN b$ = MID$(b$,2,LEN(b$))
       MID$(W$(i% + 1),Os%,2) = a$
       MID$(W$(i% + 2),Os%,2) = b$
    NEXT


    ' Set Home/Away sequence to Reverse$()
    TopLim% = 2*(Teams% - 1) + 1
    Semi% = INT(Teams%/2)

    FOR i% = 2 TO TopLim%

       FOR g% = 1 TO Semi%
	   IF MID$(Rev$(i%-1),g%,1) = "1" THEN CALL InvG(W$(i%),g%)
       NEXT

    NEXT

    '1st half of season finished.  Invert all games for 2nd half
    FOR i% = 1 TO Teams% - 1
       Lne$ = W$(i% + 1)

       FOR n% = MperW% TO 1 STEP - 1
	  CALL InvG(Lne$,n%)
       NEXT

       MID$(W$(Teams% + i%),4,LEN(Lne$)) = MID$(Lne$,4,LEN(Lne$))
    NEXT

    W$(0) = STR$(NoLs%)

END SUB
'------------------------------------------------------------------------------
SUB AddHeadings(MperW%,Lne$) STATIC
    'Accepts MperW% as Matches played per Week
    'Returns Lne$ as:
    '        Wk#|Mch#  1|Mch#  2|Mch#  3| --------|Mch#  MperW%|
 
    Lne$ = "Wk#" + CHR$(166)

    FOR k% = 1 TO MperW%
       k$ = MID$(" 1 2 3 4 5 6 7 8 91011121314151617181920",2*k% - 1,2)
       Lne$ = Lne$ + " Mch#" + k$ + CHR$(166)
    NEXT


END SUB
'----------------------------------------------------------------------------
SUB AddB(w%,MperW%,Lne$) STATIC
    'Accepts: w% as week number
    '         MperW% as Number of matches per week
    'Returns Lne$ as blank line:
    ' " 10| 1 v 10| 2 v  9| 3 v  8|---etc---| 5 v  6|"

    IF B$ = "" THEN B$  = CHR$(166) + "   v   "
    Wk$ = STR$(w%)
    IF w% < 10 THEN Sp$ = " " ELSE Sp$ = ""
    Lne$ = Sp$ + Wk$ + B$

    FOR k% = 1 TO MperW% - 1
       Lne$ = Lne$ + B$
    NEXT

    Lne$ = Lne$ + CHR$(166)

END SUB
'----------------------------------------------------------------------------
SUB InvG(Lne$,n%) STATIC
    ' Accepts Lne$ as string of matches for week:
    '     " 10¦11 v  1¦10 v  2¦ 9 v  3¦ 8 v  4¦ --- etc ------ 12 v 19¦ 6 v 20¦"
    ' Accepts n% as number of match during week
    ' Returns Lne$ with the teams playing in match n% reversed (Home/Away)

    m% =  8 * (n% - 1) + 5
    IF LEN(Lne$) < m% + 7 THEN Lne$ = Lne$ + SPACE$(m% + 7 - LEN(Lne$))
    T1$ = MID$(Lne$,m%,2)
    T2$ = MID$(Lne$,m% + 5,2)
    MID$(Lne$,m%,2)  = T2$
    MID$(Lne$,m% + 5,2)  = T1$

END SUB
' ----------------------------------------------------------------------------


Click for Home Page - - Click for History & Help?