home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 126
/
af126a.adf
/
Football.lzx
/
football
/
exec
/
CupScheduleNextRound.rexx
next >
Wrap
OS/2 REXX Batch file
|
1999-05-22
|
42KB
|
1,260 lines
/* ***********************************************************************
CUP NEXT ROUND SCHEDULER PROGRAM FOR FOOTBALL REXX SUITE
----------------------------------------------------------
Copyright Mark Naughton 1997
Version Date History
--------------------------------------------------------------------------
1.0 091297 Started. Has been planned for 3 weeks.
131297 After a two day break, have completed the code. Now
for the testing... Searching out those problems...
141297 Code works alright up to the Final where it failed due
to 'datafile2' being used instead of 'datafile'.
Amended Final code to handle replays. One Cup has been
run through and now works. Three more to go.
151297 Improved round names when matches are displayed.
Added code to change current round, after the final
is played to FINISHED so you will still be able to
view results and run scripts on the Cup.
161297 Amended bettername so it handled replays in early
rounds. Undummied code to swap teams around when a
replay is needed - Home:=Away and Away:=Home.
Third place doesn't get setup - oh dear.
171297 Noticed that the teams for third place aren't stored
- amended. Third also didn't store losing teams in
working file. Winning teams are now stored with "#"
and the losing ones are deleted when Third has been
played.
181297 Fixed bug where teams for Final Replay where picked
up from the teams in Third Place Play-Off. Added
cosmetic changes to reports. Its working so all
debug information will be taken out.
070698 Added code for manually scheduling.
290898 With the addition of two-legged matches and away goals
this program was going to be the beast to amend.
Started planning the amendments.
030998 Nearly five days later, the amendments have been made.
Now for the testing...
050998 What a nightmare. Testing is complete and many little
bugs were found but not documented. Take it from me,
it works..(kind of).
100998 Made several improvements during the course of finding
the bug (found in CupUpdateMatches.rexx) which missed
data lines during recreation of '.scf' file.
120998 Amended winner check to handle away goals when there
is a different score after extra time to that at full
time.
**************************************************************************
Procedure (Where Third is mentioned, it only gets the data
--------- if the option has been set)
1. Check files exist.
2. Read '.cf' file and get settings.
3. Read '.cfrw' file. Store and get current round settings.
4. Read matches from '.scf' file.
5. Check if any of these matches haven't been played - if they haven't then
give error and exit.
6. If current round is Third, set round to Final, adjust teams, write back
to '.cfrw' file, give message and exit.
7. If at the end of the number of rounds, read Final and Third matches.
8. If Third is set, get the winner/loser of the Third Place Play-Off.
9. Search for the Final, find winner. If replay, store after checking its
not already been stored.
10.If not a replay, write IGNORE in replay array.
11.If replays exist, adjust roundname.
12.Go through the replays, setting them to not played.
13.Write '.cfrw' file back to itself.
14.Append replays back to '.scf' file and give message and exit.
15.If no replays exist (linked to No.11), if history (if set) file doesn't
exist, then create it.
16.Append winner/loser and if set, third and fourth place.
17.Change round to 'Finished'. Write '.cfrw' file. Give end message and
exit.
18.If not at the end of the number of rounds (linked to No.7), search
matches, finding winners/losers and replays (if applicable).
19.If replays exist, search '.cfrw' file, putting '#' in front of teams
not in replays.
20.Adjust roundname.
21.Write not played and swap teams, checking replays aren't ignored and
if they are, decrement the count.
22.If no replays, get teams minus the '#'. Write '.cfrw' file.
23.If replays append to '.scf' file, give message and exit.
24.If no replays (linked to No.19) exist, read '.cfrw' file again, getting
the settings.
25.Read matches for current round.
26.Search matches, storing winners/losers. Update '.cfrw' settings then
rewrite '.cfrw' file.
27.If Third, dummy out finalists.
28.If Semi-Finals, write Third (if set) and Final matches, give message
and exit.
29.Random match generator - get number and store.
30.Append matches to '.scf' file, writing home and away teams according to
the randomly generated array.
31.Give message for next round and exit.
32.Routine 'whosthewinr' - depending on the settings for each round
(Extra Time and Penalties), decide who the winner and loser are, and
return the winner on the left side of '*****'. Return '#####' if its
the 1st leg of Two.
33.Routine 'bettername' - using the current round name, create a more
useful name, ie. "Quart" becomes "Quarter Finals" and "1st Replays"
becomes "1st Round Replays", etc.
************************************************************************** */
PARSE ARG league_stuff
version = 1
input_file = '.cf'
input2_file = '.scf'
input3_file = '.cfrw'
input4_file = '.cfh'
output3_file = '.temp'
indicator = 'RAM:MatchesToBeDone'
title = '*CUP_TITLE='
thirdpl = '*CUP_THIRD='
rounddef = '*CUP_RNDDEF='
currond = '*CUP_ROND='
currrondn = '*CUP_CRDN='
roundddef = '*CUP_RDEF='
cuphistory = '*CUP_HISTORY='
thirdpl = '*CUP_THIRD='
teams_cnt = '*CUP_TCNT='
awaygs = '*CUP_AWAYG='
schedtype = '*CUP_SCHEDULE='
pkversion = '* Version='
matches. = '???'
separator = '*'
teams. = '???'
rnds. = '???'
lines. = '???'
replays. = '???'
working. = '???'
losing. = '???'
repct = 0
repno. = '???'
tcount = 0
ttc = 0
rndcnt = 0
linesct = 0
league_file = "Data/"league_stuff
curnd = ''
curndn = 0
not_played = "__ __"
if exists(league_file||input_file) = 0 then exit
if exists(league_file||input2_file) = 0 then exit
if exists(league_file||input3_file) = 0 then exit
if open(datafile,league_file || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(title,line) > 0 then cupname = delstr(line,1,11)
if pos(cuphistory,line) > 0 then cuph = delstr(line,1,13)
if pos(thirdpl,line) > 0 then third = delstr(line,1,11)
if pos(awaygs,line) > 0 then awaygls = delstr(line,1,11)
if pos(schedtype,line) > 0 then scht = delstr(line,1,14)
if pos(rounddef,line) > 0 then do
rndcnt = rndcnt + 1
rnds.rndcnt = delstr(line,1,12)
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input_file"' file."
exit
end
if open(datafile,league_file || input3_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
linesct = linesct + 1
lines.linesct = line
if pos(currond,line) > 0 then crond = strip(substr(line,11,2))
if pos(roundddef,line) > 0 then tcrondn= strip(substr(line,11,5))
if pos(currrondn,line) > 0 then do
crondn = strip(substr(line,11,30))
tleg_no = 0
if pos("1 Leg",line) > 0 then tleg_no = 1
if pos("2 Legs",line) > 0 then tleg_no = 2
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' file."
exit
end
leg_number = 0
if pos("Leg",crondn) > 0 then do
if pos("2 Legs",crondn) > 0 then
leg_number = 2
else
leg_number = 1
end
/* this can be here or later....decide! */
mkr = 0
ttc = 0
if open(datafile,league_file || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos("*Round="strip(tcrondn),line) > 0 & mkr = 0 then do
if pos("Leg",line) > 0 then do
if tleg_no = 1 & pos("1 Leg",line) > 0 then mkr = 1
if tleg_no = 2 & pos("2 Legs",line) > 0 then mkr = 1
end
else
mkr = 1
end
if mkr = 1 then do
ttc = ttc + 1
matches.ttc = line
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' file."
exit
end
do i=1 to ttc
if pos(not_played,matches.i) > 0 & pos("#",matches.i) = 0 & pos("Third",crondn) = 0 then do
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "INFORMATION :"
say
say "Not all matches have been played. This program will schedule the next round's"
say "matches when all of the matches have been played."
say
say "-------------------------------------------------------------------------------"
exit
end
end
if pos("Third",crondn) > 0 then do
do i=1 to linesct
if pos(currond,lines.i) > 0 then lines.i=currond||rndcnt
if pos(currrondn,lines.i) > 0 then do
if pos("Leg",rnds.rndcnt) > 0 then do
if pos("2 Legs",crondn) > 0 then
lines.i=currrondn||"Final 2 Legs"
else
lines.i=currrondn||"Final 1 Leg"
end
else
lines.i=currrondn||"Final"
end
if pos(roundddef,lines.i) > 0 then lines.i=roundddef||rnds.rndcnt
if pos(separator,lines.i) = 0 then do
if pos("#",lines.i) = 0 then
lines.i = "-DELETED-"
else do
parse var lines.i "#"teamname
lines.i = teamname
end
end
end
if open(datafile,league_file || input3_file,'w') then do
do p=1 to i
if p = i then
writech(datafile,lines.p)
else
writeln(datafile,lines.p)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
leg_do = "Blank"
if pos("2 Legs",rnds.rndcnt) > 0 then
leg_do = "1 Leg"
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "bettername("Final",leg_do)
say
do i=1 to ttc
if pos("*Round=Final",matches.i) > 0 then do
g = i + 2
say matches.g
leave
end
end
say
say "-------------------------------------------------------------------------------"
exit
end
if crond = rndcnt then do
if pos("YES",third) > 0 then
temprond = "Third"
else
temprond = "Final"
mkr = 0
ttc = 0
matchcnt = 0
if open(datafile,league_file || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos("*Round="strip(temprond),line) then
mkr = 1
if mkr = 1 then do
ttc = ttc + 1
matches.ttc = line
end
if pos(separator,line) = 0 & pos("#",line) = 0 & line~='' then
matchcnt = matchcnt + 1
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' file."
exit
end
if pos("YES",third) > 0 then do
where = crond - 1
ermm = substr(rnds.where,1,5)
posit = 0
do i=1 to ttc
if pos("Third",matches.i) > 0 then do
posit = i + 2
leave
end
end
thirdstrng = whosthewinr(posit,rnds.where,ermm,0,"NO")
end
mkr = 0
if pos("Leg",crondn) > 0 then do
if pos("2 Legs",crondn) > 0 then
leg_number = 2
else
leg_number = 1
end
else
leg_number = 0
do i=1 to ttc
if pos("Final",matches.i) > 0 then
mkr = 1
if pos('*',matches.i) = 0 & pos('#',matches.i) = 0 & matches.i~='' & mkr = 1 then do
match_1f = i
strng = whosthewinr(i,rnds.crond,crondn,leg_number,awaygls)
if pos("REPLAY",strng) > 0 then do
repno.repct = i
teama = strip(substr(matches.i,1,30))
teamb = strip(substr(matches.i,41,30))
do k=1 to repct
if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 & repno.k~=i then do
replays.k = "IGNORE"
end
end
end
if pos("NOP",strng) = 0 & pos("REPLAY",strng) = 0 then do
teama = strip(substr(matches.i,1,30))
teamb = strip(substr(matches.i,41,30))
do k=1 to repct
if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 then do
replays.k = "IGNORE"
end
end
end
end
end
if repct > 0 then do
do j=1 to linesct
if pos(currrondn,lines.j) > 0 & pos("Replay",lines.j) = 0 then
lines.j=lines.j||" Replay"
end
trepct = repct
do i=1 to repct
if pos("IGNORE",replays.i) = 0 then
replays.i = overlay(not_played,replays.i,32)
else
trepct = trepct - 1
end
if trepct = 0 then repct = 0
if open(datafile,league_file || input3_file,'w') then do
do p=1 to linesct
if p = linesct then
writech(datafile,lines.p)
else
writeln(datafile,lines.p)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
if repct > 0 then do
if open(datafile,league_file || input2_file,'a') then do
writeln(datafile,"*Round="tcrondn" Replay")
writeln(datafile,"*")
do p=1 to repct
if pos("IGNORE",replays.p) = 0 then
writeln(datafile,replays.p)
end
writeln(datafile,"*")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' for amendment."
exit
end
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "bettername(word(crondn,1)" Replay ","Blank")
say
do i=1 to repct
if pos("IGNORE",replays.i) = 0 then
say replays.i
end
say
say "-------------------------------------------------------------------------------"
exit
end
end
if repct = 0 then do
winning = strng
if pos("#####",winning) > 0 then do
parse var winning l1teamh "#####" l1teama
do j=1 to linesct
if pos(currrondn,lines.j) > 0 then
lines.j=currrondn||word(tcrondn,1)" 2 Legs"
end
if open(datafile,league_file || input3_file,'w') then do
do p=1 to linesct
if p = linesct then
writech(datafile,lines.p)
else
writeln(datafile,lines.p)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
if open(datafile,league_file || input2_file,'a') then do
writeln(datafile,"*Round="word(tcrondn,1)" 2 Legs")
writeln(datafile,"*")
writeln(datafile,left(l1teama,30," ")" __ __ " l1teamh)
writeln(datafile,left("#1st Leg",30," ")" "right(strip(substr(matches.match_1f,37,2)),2)" "right(strip(substr(matches.match_1f,32,2)),2))
writeln(datafile,"*")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' for amendment."
exit
end
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "bettername(word(crondn,1),"2 Legs")
say
s1 = strip(substr(matches.match_1f,37,2))
s2 = strip(substr(matches.match_1f,32,2))
say left(l1teama,30," ")" ("s1") __ __ ("s2") "l1teamh
say
say "-------------------------------------------------------------------------------"
exit
end
parse var winning winner"*****"loser
parse var thirdstrng thirdplace"*****"fourthplace
if pos("YES",cuph) > 0 then do
if exists(league_file||input4_file) = 0 then do
if open(datafile,league_file||input4_file,'w') then do
writeln(datafile,"*")
writeln(datafile,"** History for '"cupname"'")
writeln(datafile,"*")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Cannot write to '"league_file||input4_file"'."
exit
end
end
if open(datafile,league_file||input4_file,'a') then do
writeln(datafile,"*WINNER="winner)
writeln(datafile,"*RUNNERUP="loser)
if pos("YES",third) > 0 then do
writeln(datafile,"*THIRD="thirdplace)
writeln(datafile,"*FOURTH="fourthplace)
end
writeln(datafile,"*")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Cannot append to '"league_file||input4_file"'."
exit
end
end
/* write FINISHED to Working file so it can be read by Football */
/* but no scores will be able to be updated. */
do i=1 to linesct
if pos(currrondn,lines.i) > 0 then lines.i=currrondn||"Finished"
end
if open(datafile,league_file || input3_file,'w') then do
do p=1 to i
if p = i then
writech(datafile,lines.p)
else
writeln(datafile,lines.p)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "All matches have been played, totalling "matchcnt", (including replays or legs "
say "if applicable)."
say
say
say " WINNER : "upper(winner)
say
say " RunnerUp : "loser
if pos("YES",third) > 0 then do
say " Third : "thirdplace
say " Fourth : "fourthplace
end
say
say "-------------------------------------------------------------------------------"
exit
end
end
if crond ~= rndcnt then do
do i=1 to ttc
if pos('*',matches.i) = 0 & pos('#',matches.i) = 0 & matches.i~='' then do
strng = whosthewinr(i,rnds.crond,crondn,leg_number,awaygls)
if pos("REPLAY",strng) > 0 then do
repno.repct = i
teama = strip(substr(matches.i,1,30))
teamb = strip(substr(matches.i,41,30))
do k=1 to repct
if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 & repno.k~=i then do
replays.k = "IGNORE"
end
end
end
if pos("NOP",strng) = 0 & pos("REPLAY",strng) = 0 then do
teama = strip(substr(matches.i,1,30))
teamb = strip(substr(matches.i,41,30))
do k=1 to repct
if pos(teama,replays.k) > 0 & pos(teamb,replays.k) > 0 then do
replays.k = "IGNORE"
end
end
end
end
end
if repct > 0 then do
do j=1 to linesct
if pos(separator,lines.j) = 0 & pos("#",lines.j) = 0 then do
willhe = 0
do p=1 to repct
if pos(strip(lines.j),replays.p) > 0 then
willhe = 1
end
if willhe = 0 then
lines.j = insert("#",lines.j,0)
end
end
do j=1 to linesct
if pos(currrondn,lines.j) > 0 & pos("Replay",lines.j) = 0 then
lines.j=lines.j||" Replays"
end
trepct = repct
do i=1 to repct
if pos("IGNORE",replays.i) = 0 then do
replays.i = overlay(not_played,replays.i,32)
teama = strip(substr(replays.i,1,30)) /* this code swaps the teams round for replays */
teamb = strip(substr(replays.i,41,30))
replays.i = overlay(teama,replays.i,41,30)
replays.i = overlay(teamb,replays.i,1,30)
end
else
trepct = trepct - 1
end
if trepct = 0 then repct = 0
if repct = 0 then do
do p=1 to linesct
if pos("#",lines.p) > 0 then
lines.p = delstr(lines.p,1,1)
end
end
if open(datafile,league_file || input3_file,'w') then do
do p=1 to linesct
if p = linesct then
writech(datafile,lines.p)
else
writeln(datafile,lines.p)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
if repct > 0 then do
if open(datafile,league_file || input2_file,'a') then do
writeln(datafile,"*Round="tcrondn" Replays")
writeln(datafile,"*")
do p=1 to repct
if pos("IGNORE",replays.p) = 0 then
writeln(datafile,replays.p)
end
writeln(datafile,"*")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' for recreation."
exit
end
roundname = bettername(crondn,"Blank")
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "roundname
say
say "The following replays will need to be played :"
say
do i=1 to repct
if pos("IGNORE",replays.i) = 0 then
say replays.i
end
say
say "-------------------------------------------------------------------------------"
exit
end
end
if repct = 0 then do
linesct = 0
if open(datafile,league_file || input3_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
linesct = linesct + 1
lines.linesct = line
if pos(currond,line) > 0 then crond = strip(substr(line,11,2))
if pos(roundddef,line) > 0 then tcrondn= strip(substr(line,11,5))
if pos(currrondn,line) > 0 then do
crondn = strip(substr(line,11,30))
tleg_no = 0
if pos("1 Leg",line) > 0 then tleg_no = 1
if pos("2 Legs",line) > 0 then tleg_no = 2
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' file."
exit
end
ttc = 0
mkr = 0
if open(datafile,league_file || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos("*Round="strip(tcrondn),line) > 0 & mkr = 0 then do
if pos("Leg",line) > 0 then do
if tleg_no = 1 & pos("1 Leg",line) > 0 then mkr = 1
if tleg_no = 2 & pos("2 Legs",line) > 0 then mkr = 1
end
else
mkr = 1
end
if mkr = 1 then do
ttc = ttc + 1
matches.ttc = line
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' file."
exit
end
winct = 0
losct = 0
do i=1 to ttc
if pos("*Round",matches.i) > 0 then
parse var matches.i "*Round="crondn
if pos(separator,matches.i) = 0 & pos("#",matches.i) = 0 & matches.i~='' then do
strng = whosthewinr(i,rnds.crond,crondn,tleg_no,awaygls)
if pos("REPLAY",strng) = 0 & pos("NOP",strng) = 0 then do
if pos("#####",strng) = 0 then do
parse var strng tempa "*****" tempb
mn = 0
do k=1 to winct
if pos(strip(tempa),working.k) > 0 then mn=1
end
if mn = 0 then do
winct = winct + 1
working.winct = strip(tempa)
end
mn = 0
do k=1 to losct
if pos(strip(tempb),losing.k) > 0 then mn=1
end
if mn = 0 then do
losct = losct + 1
losing.losct = strip(tempb)
end
end
if pos("#####",strng) > 0 then do
parse var strng tempa "#####" tempb
winct = winct + 1
working.winct = strip(tempb)
winct = winct + 1
working.winct = strip(tempa)
losct = losct + 1
losing.losct = matches.i
end
end
strng = ""
end
end
if tleg_no = 1 then do
do j=1 to linesct
if pos(currrondn,lines.j) > 0 then
lines.j=currrondn||word(tcrondn,1)" 2 Legs"
end
if open(datafile,league_file || input3_file,'w') then do
do p=1 to linesct
if p = linesct then
writech(datafile,lines.p)
else
writeln(datafile,lines.p)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
if open(datafile,league_file || input2_file,'a') then do
writeln(datafile,"*Round="word(tcrondn,1)" 2 Legs")
writeln(datafile,"*")
lg1ct = 0
do i=1 to winct by 2
l = i + 1
writeln(datafile,left(working.i,30," ")" __ __ " working.l)
lg1ct = lg1ct + 1
leg1match = losing.lg1ct
leg1match = overlay(" ",leg1match,1,30)
leg1match = overlay(" ",leg1match,41,30)
leg1match = overlay("#1st Leg",leg1match,1)
score1 = substr(leg1match,32,2)
score2 = substr(leg1match,37,2)
leg1match = overlay(score2,leg1match,32,2)
leg1match = overlay(score1,leg1match,37,2)
writeln(datafile,leg1match)
end
writeln(datafile,"*")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input2_file"' for amendment."
exit
end
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "bettername(word(crondn,1),"2 Legs")
say
lg1ct = 0
do i=1 to winct by 2
l = i + 1
lg1ct = lg1ct + 1
leg1match = losing.lg1ct
s1 = strip(substr(losing.lg1ct,37,2))
s2 = strip(substr(losing.lg1ct,32,2))
say left(working.i,30," ")" ("s1") __ __ ("s2") "working.l
end
say
say "-------------------------------------------------------------------------------"
exit
end
crond = crond + 1
if pos("Third",crond) > 0 then
winct = winct + losct
do j=1 to linesct
if pos(roundddef,lines.j) > 0 then lines.j=roundddef||rnds.crond
if pos(currond,lines.j) > 0 then lines.j=currond||crond
if pos(currrondn,lines.j) > 0 then do
if pos("2 Legs",rnds.crond) > 0 then
lines.j=currrondn||substr(rnds.crond,1,5)" 1 Leg"
else
lines.j=currrondn||substr(rnds.crond,1,5)
end
if pos(teams_cnt,lines.j) > 0 then lines.j=teams_cnt||winct
end
if open(datafile,league_file || input3_file,'w') then do
do j=1 to linesct
if pos(separator,lines.j) > 0 then
writeln(datafile,lines.j)
end
if pos("Third",crond) > 0 then do
writeln(datafile,"#"working.1)
writeln(datafile,"#"working.2)
writeln(datafile,losing.1)
writech(datafile,losing.2)
end
else do
do j=1 to winct
if j = winct then
writech(datafile,working.j)
else
writeln(datafile,working.j)
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to open '"league_file || input3_file"' for recreation."
exit
end
if pos("Semi",tcrondn) > 0 then do
if open(outfile,league_file || input2_file,"a") then do
if pos("YES",third) > 0 then do
writeln(outfile,"*Round=Third")
writeln(outfile,"*")
writeln(outfile,left(losing.1,30)" __ __ " losing.2)
writeln(outfile,"*")
end
leg_do = ""
if pos("2 Legs",rnds.rndcnt) > 0 then
leg_do = "1 Leg"
writeln(outfile,"*Round=Final "leg_do)
writeln(outfile,"*")
writeln(outfile,left(working.1,30)" __ __ " working.2)
writech(outfile,"*")
close(outfile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to append to '"league_file || input2_file"'."
exit
end
leg_do = "Blank"
if pos("2 Legs",rnds.rndcnt) > 0 then
leg_do = "1 Leg"
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "bettername("Final",leg_do)
say
say left(working.1,30)" v "working.2
say
say
if pos("YES",third) > 0 then do
say "Round : Third Place Play-Off"
say
say left(losing.1,30)" v "losing.2
say
end
say
say "-------------------------------------------------------------------------------"
exit
end
if pos("AUTOMATIC",scht) > 0 then do
nums = ''
numct= 0
closed = winct
rndseed= winct * rndcnt
do while closed ~= 0
t = random(1,closed,time('s'))
if find(nums,t) = 0 then do
if numct = 0 then do
numct = 1
nums = t
end
else do
numct = numct + 1
nums = nums||" "||t
end
end
if numct = winct-1 then do
do f=1 to winct
if pos(f,nums) = 0 then
nums = nums||" "f
end
numct = numct + 1
closed = 0
end
end
end
if open(outfile,league_file || input2_file,"a") then do
leg_do = ""
if pos("2 Legs",rnds.crond) > 0 then
leg_do = "1 Leg"
writeln(outfile,"*Round="word(rnds.crond,1)" "leg_do)
writeln(outfile,"*")
if pos("AUTOMATIC",scht) > 0 then do
home = 0
away = 0
do i=1 to winct by 2
home = word(nums,i)
away = word(nums,i+1)
writeln(outfile,left(working.home,30)" __ __ " working.away)
end
writeln(outfile,"*")
end
close(outfile)
if pos("AUTOMATIC",scht) = 0 then do
if open(datafile,indicator,'w') then do
writeln(datafile,"Matches To Be Scheduled")
close(datafile)
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Matches need to be manually scheduled but the indicator"
say "file cannot be created."
exit
end
end
end
else do
say
say "ERROR : (CupScheduleNextRound)"
say
say "Unable to append to '"league_file || input2_file"'."
exit
end
leg_do = "Blank"
if pos("2 Legs",rnds.crond) > 0 then
leg_do = "1 Leg"
roundname = bettername(substr(rnds.crond,1,5),leg_do)
say
say center("'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say
say "Round : "roundname
say
say "The following matches have been scheduled : "
say
if pos("AUTOMATIC",scht) > 0 then do
do i=1 to winct by 2
home = word(nums,i)
away = word(nums,i+1)
say left(working.home,30)" __ __ " working.away
end
say
say "-------------------------------------------------------------------------------"
end
exit
end
end
exit
/* Routine ----------------------------------------------------------- */
whosthewinr:
parse arg start,rdef,wroundname,num_leg,gls_away
et = 0
pe = 0
etr = 0
per = 0
spos = start
fchk = 0
if pos("Replay",wroundname) = 0 then do
if pos("Extra Time",rdef) > 0 then et = 2
if pos("Penalties",rdef) > 0 then pe = 2
if pos("2 Legs",rdef) > 0 & num_leg = 1 then do
teama = strip(substr(matches.spos,1,30))
teamb = strip(substr(matches.spos,41,30))
return teama"#####"teamb
end
teama = strip(substr(matches.spos,1,30))
teamb = strip(substr(matches.spos,41,30))
form = strip(substr(matches.spos,32,2))
agam = strip(substr(matches.spos,37,2))
if pos("2 Legs",rdef) > 0 & num_leg = 2 then do
spos = spos + 1
for1l = strip(substr(matches.spos,32,2))
aga1l = strip(substr(matches.spos,37,2))
if for1l = '' | aga1l = '' then return "NOP"
for = form + for1l
aga = agam + aga1l
end
else do
for = form
aga = agam
end
if for > aga then do
return teama"*****"teamb
end
if for < aga then do
return teamb"*****"teama
end
if num_leg = 2 & pos("YES",gls_away) > 0 then do
if for = aga then do
if for1l > agam then return teama"*****"teamb
if for1l < agam then return teamb"*****"teama
end
end
if for = aga & et = 2 then do
spos = spos + 1
for1 = strip(substr(matches.spos,32,2))
aga1 = strip(substr(matches.spos,37,2))
if pos("2 Legs",rdef) > 0 & num_leg = 2 then do
f1 = for1 + for1l
a1 = aga1 + aga1l
if f1 > a1 then return teama"*****"teamb
if f1 < a1 then return teamb"*****"teama
if f1 = a1 then do
if pos("YES",gls_away) > 0 then do
if for1l > aga1 then return teama"*****"teamb
if for1l < aga1 then return teamb"*****"teama
if for1l = aga1 then do
if for1 = for1l & aga1 = aga1l then
for1 = aga1
else do
if aga1 > for1l then return teamb"*****"teama
if aga1 < for1l then return teama"*****"teamb
if aga1 = for1l then for1 = aga1
end
end
end
else
for1 = aga1 /* to force penalties when ET after 2 legs */
end
end
if for1 > aga1 then return teama"*****"teamb
if for1 < aga1 then return teamb"*****"teama
if for1 = aga1 & pe = 2 then do
spos = spos + 1
for2 = strip(substr(matches.spos,32,2))
aga2 = strip(substr(matches.spos,37,2))
if for2 > aga2 then return teama"*****"teamb
if for2 < aga2 then return teamb"*****"teama
if for2 = aga2 then do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
else do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
if for = aga & pe = 2 & et = 0 then do
spos = spos + 1
for1 = strip(substr(matches.spos,32,2))
aga1 = strip(substr(matches.spos,37,2))
if for1 > aga1 then return teama"*****"teamb
if for1 < aga1 then return teamb"*****"teama
if for1 = aga1 then do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
if for = aga & pe = 0 & et = 0 then do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
spos = start
if pos("Replay",wroundname) > 0 then do
if pos("Extra Time",rdef) > 0 then et = 2
if pos("E.T If Rep.",rdef) > 0 then etr = 2
if pos("Penalties",rdef) > 0 then pe = 2
if pos("Pen If Rep.",rdef) > 0 then per = 2
teama = strip(substr(matches.spos,1,30))
teamb = strip(substr(matches.spos,41,30))
for = strip(substr(matches.spos,32,2))
aga = strip(substr(matches.spos,37,2))
if for > aga then return teama"*****"teamb
if for < aga then return teamb"*****"teama
if for = aga & (etr = 2 | et = 2) then do
spos = spos + 1
for1 = 0
aga1 = 0
for1 = strip(substr(matches.spos,32,2))
aga1 = strip(substr(matches.spos,37,2))
if for1 > aga1 then return teama"*****"teamb
if for1 < aga1 then return teamb"*****"teama
if for1 = aga1 & (per = 2 | pe = 2) then do
spos = spos + 1
for2 = strip(substr(matches.spos,32,2))
aga2 = strip(substr(matches.spos,37,2))
if for2 > aga2 then return teama"*****"teamb
if for2 < aga2 then return teamb"*****"teama
if for2 = aga2 then do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
else do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
if for = aga & per = 2 & et = 0 & etr = 0 then do
spos = spos + 1
for1 = strip(substr(matches.spos,32,2))
aga1 = strip(substr(matches.spos,37,2))
if for1 > aga1 then return teama"*****"teamb
if for1 < aga1 then return teamb"*****"teama
if for1 = aga1 then do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
if for = aga & pe = 0 & et = 0 & etr = 0 & per = 0 then do
repct = repct + 1
replays.repct = matches.start
return "REPLAY"
end
end
return "NOP"
/* Routine ----------------------------------------------------------- */
bettername:
parse arg crn,legless
trdn = substr(crn,1,1)
if datatype(trdn,'n') = 1 then do
if pos("Replay",crn) > 0 then
trn = strip(word(crn,1))" Round "strip(word(crn,2))
else do
parse var crn roundno" "extra
trn = strip(crn)" Round "extra
end
end
else do
if pos("Final",crn) > 0 then do
parse var crn . " "extra
if pos("Replay",crn) > 0 then
trn = "Final "extra
else
trn = "Final"
end
if pos("Semi",crn) > 0 then do
parse var crn . " "extra
if pos("Replay",crn) > 0 then
trn = "Semi-Final "extra
else
trn = "Semi-Finals"
end
if pos("Quart",crn) > 0 then do
parse var crn . " "extra
if pos("Replay",crn) > 0 then
trn = "Quarter-Final "extra
else
trn = "Quarter-Finals"
end
if pos("Third",crn) > 0 then do
trn = "Third Place Play-Off"
end
end
if pos("1 Leg",legless) > 0 then
trn = trn||" (1st Leg)"
if pos("2 Legs",legless) > 0 then
trn = trn||" (2nd Leg)"
return trn
/* ------------------------------------------------------------------- */