home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 126
/
af126a.adf
/
Football.lzx
/
football
/
exec
/
CupScheduler.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-22
|
11KB
|
402 lines
/* ***********************************************************************
CUP SCHEDULER PROGRAM FOR FOOTBALL REXX SUITE
-----------------------------------------------
Copyright Mark Naughton 1997
Version Date History
--------------------------------------------------------------------------
1.0 121097 Wrote the random match generator.
201097 Wrote the main routine that creates all the files,
such as sorting the 'cf' file, creating the
working/history files and randomly generating a
schedule. This program will ONLY create the files and
not maintain them. That is left to
"CupScheduleNextRound.rexx".
221097 Tidied report and added number of matches to be
played. If a history file is found but it is switched
off then it will not be deleted.
311097 Changed format of 'working' file - added CRDN.
091297 Cup history file creation has been dummied out for
the time being.
151297 Tidied display and removed CupHistory code.
060698 Added code for manual scheduling.
260898 Added code for handling 2 legs.
050998 Didn't read setting for away goals.
**************************************************************************
Procedure
---------
1. Check files exist.
2. Read '.cf' and write teams to output file.
3. Using external program, sort the teams.
4. Re-read the teams and recreate '.cf'.
5. Open '.cf' for reading.
6. Extract data and store.
7. If no separator in it, then take it as a
team. Strip blanks and store.
8. Close input file.
9. Create '.cfrw' working file with round/teams.
10.Randomly generate who is going to play who and store in array but only
if the matches are to be automatically scheduled.
11.Create '.scf' file and using the order in which the numbers were
generated earlier, write the particular teams.
12.Write report and exit.
************************************************************************** */
PARSE ARG league_stuff
version = 1
input_file = '.cf'
input2_file = '.scf'
input3_file = '.cfrw'
input4_file = '.cfh'
output3_file = '.temp'
title = '*CUP_TITLE='
thirdpl = '*CUP_THIRD='
rounddef = '*CUP_RNDDEF='
cuphistory = '*CUP_HISTORY='
schedtype = '*CUP_SCHEDULE='
awaygs = '*CUP_AWAYG='
pkversion = '* Version='
matches. = '???'
separator = '*'
teams. = '???'
rnds. = '???'
tcount = 0
ttc = 0
rndcnt = 0
league_file = "Data/"league_stuff
if exists(league_file || input_file) = 0 then exit
ttc = 0
tcount = 0
if open(datafile,league_file || input_file,'r') then do
if open(datafile2,league_file || output3_file,'w') then do
do while ~eof(datafile)
line = readln(datafile)
line = strip(line)
if pos(separator,line) > 0 then do
tcount = tcount + 1
teams.tcount = line
end
else do
ttc = ttc + 1
writeln(datafile2,line)
end
end
close(datafile2)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot write to '"league_file||output3_file"'."
close(datafile)
exit
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot open '"league_file || input_file"' for reading/sorting."
exit
end
address command 'sort 'league_file || output3_file league_file || output3_file
if open(datafile2,league_file || output3_file,'r') then do
if open(datafile,league_file || input_file,'w') then do
do i=1 to tcount
writeln(datafile,teams.i)
end
do j=1 to ttc /* while ~eof(datafile2) */
line = readln(datafile2)
line = strip(line)
if j = ttc then
writech(datafile,line)
else
writeln(datafile,line)
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot write to '"league_file||input_file"'."
close(datafile2)
exit
end
close(datafile2)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot read '"league_file||output3_file"'."
close(datafile)
exit
end
address command 'delete >NIL: 'league_file || output3_file
tcount = 0
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(thirdpl,line) > 0 then third = delstr(line,1,11)
if pos(awaygs,line) > 0 then awaygoals= delstr(line,1,11)
if pos(pkversion,line) > 0 then fversion = delstr(line,1,12)
if pos(cuphistory,line) > 0 then cuph = delstr(line,1,13)
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
if pos(separator,line) = 0 then do
line = strip(line)
tcount = tcount + 1
teams.tcount = line
end
end
close(datafile)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Unable to open '"league_file || input_file"' file."
exit
end
if open(datafile2,league_file || input3_file,'w') then do
writeln(datafile2,"*")
writeln(datafile2,"* WORKING CUP FILE")
writeln(datafile2,"*")
writeln(datafile2,"*CUP_TITLE="cupname)
writeln(datafile2,"*CUP_ROND=1")
if pos("2 Legs",rnds.1) > 0 then
writeln(datafile2,"*CUP_CRDN="left(rnds.1,6)" 1 Leg")
else
writeln(datafile2,"*CUP_CRDN="left(rnds.1,6))
writeln(datafile2,"*CUP_RDEF="rnds.1)
writeln(datafile2,"*CUP_TCNT="tcount)
writeln(datafile2,"*")
do i=1 to tcount
if i = tcount then
writech(datafile2,teams.i)
else
writeln(datafile2,teams.i)
end
close(datafile2)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Unable to write to '"league_file || input3_file"' file."
exit
end
/* Schedule matches */
if pos("AUTOMATIC",scht) > 0 then do
nums = ''
numct= 0
closed = tcount
rndseed= tcount * 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 = tcount-1 then do
do f=1 to tcount
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,"w") then do
writeln(outfile,"*")
writeln(outfile,"**" cupname)
writeln(outfile,"*")
writeln(outfile,"*")
if pos("2 Legs",rnds.1) > 0 then
writeln(outfile,"*Round="word(rnds.1,1)" 1 Leg")
else
writeln(outfile,"*Round="word(rnds.1,1))
writeln(outfile,"*")
if pos("AUTOMATIC",scht) > 0 then do
home = 0
away = 0
do i=1 to tcount by 2
home = word(nums,i)
away = word(nums,i+1)
writech(outfile,left(teams.home,30))
writeln(outfile," __ __ " teams.away)
end
writech(outfile,"*")
end
close(outfile)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Unable to write to '"league_file || input2_file"'."
exit
end
matches = 0
left = tcount
do while left ~= 1
matches = matches + (left/2)
left = left / 2
end
if pos("YES",third) > 0 then
matches = matches + 1
do i=1 to rndcnt /* amend count if two legs */
if pos("2 Legs",rnds.i) > 0 then
matches = matches + 1
end
say
say center("Report for '"cupname"'",78)
say "-------------------------------------------------------------------------------"
say " Created "date('e')" at "time()
say
say "Version: "fversion
say "_______________________________________________________________________________"
say
say "Number of teams : "left(tcount,3)" Number of Matches : "matches
say " (excluding replays)"
say
if pos("MANUAL",scht) > 0 then
say "Matches will be manually scheduled."
else
say "Matches will be automatically scheduled."
if pos("YES",third) > 0 then
say "Third place play-offs will take place."
if pos("YES",cuph) > 0 then
say "Cup history will be stored."
if pos("YES",awaygoals) > 0 then do
say "Away Goals will be used for all 2-leg matches. If there aren't"
say "any, then it will be ignored."
end
say
say "'"cupname"' is scheduled for "rndcnt" rounds, with the following settings"
say "regarding Extra Time and Penalties and Legs for each round as listed below..."
say
say "Round ExtraTime Penalties Legs"
say "--------------------------------------------------"
say
do i=1 to rndcnt
if pos("1 Leg",rnds.i) > 0 then do
k = pos("1 Leg",rnds.i)
rnds.i = overlay(" ",rnds.i,k)
say rnds.i
end
else
say rnds.i
end
say
say "_______________________________________________________________________________"
say
say "Team Listing: "
say "-------------"
say
do i=1 to tcount
say teams.i
end
say
say "_______________________________________________________________________________"
say
if pos("2 Legs",rnds.1) > 0 then
say "Round: "bettername(word(rnds.1,1),"1 Leg")
else
say "Round: "bettername(word(rnds.1,1),"Blank")
say "------------------------------------"
say
if pos("AUTOMATIC",scht) > 0 then do
home = 0
away = 0
do i=1 to tcount by 2
home = word(nums,i)
away = word(nums,i+1)
say left(teams.home,30)" __ __ "teams.away
end
say
say "-------------------------------------------------------------------------------"
say
end
exit
/* Routine ----------------------------------------------------------- */
bettername:
parse arg crn,legless
trdn = strip(substr(crn,1,1))
if datatype(trdn,'n') = 1 then do
parse var crn roundno" "extra
trn = strip(crn)" Round "extra
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
/* ------------------------------------------------------------------- */