# Trying to create a schedule

I am currently working on a sports game sim and I am having a heck of a time coding the schedule creation portion of the program. My problem is that I have 20 teams whom I want to play each other once each over a span of 19 weeks. I have wracked and possibly damaged my brain trying to come up with somthing that will not cause doubled games and 2 games in the same day to no avail...anyone have anything that would work that maybe I am just missing?

I am using Visual Pascal 2.1

Thanks.

• : I am currently working on a sports game sim and I am having a heck of a time coding the schedule creation portion of the program. My problem is that I have 20 teams whom I want to play each other once each over a span of 19 weeks. I have wracked and possibly damaged my brain trying to come up with somthing that will not cause doubled games and 2 games in the same day to no avail...anyone have anything that would work that maybe I am just missing?
:
: I am using Visual Pascal 2.1
:
: Thanks.
:

I hope following works (didn't try it...)

[code]
type schedule_type:array[1..20] of byte;

var schedule:array[1..20] of schedule_type;

procedure season;
var i,j,k:byte;
temp:schedule_type;
begin
for i:=1 to 20 do
for j:=i to 20 do if i<>j then
begin
repeat
n:=round(random(20)+1);
until not(n in schedule[i]);
schedule[i].[j]:=n;
schedule[j].[i]:=n;
end;
end;

[/code]

• here is whole thing:

[code]
type schedule_type=array[1..20] of byte;

var schedule:array[1..20] of schedule_type;
var i,j,k,p,q:byte;

procedure season;
var tr:boolean;
begin
for i:=1 to 20 do
for j:=i to 20 do if i<>j then
begin
repeat
k:=round(random(20));
tr:=false;
q:=i;
if j>i then q:=j;
for p:=1 to j do
if k=schedule[i][p] then
tr:=true;
until tr=false;
schedule[i][j]:=k;
schedule[j][i]:=k;
end;
end;

begin
writeln;
randomize;
season;

{ Display the schedule... }

write(' ');
for i:=1 to 20 do
begin
write(i,' ');
if i<10 then write(' ');
end;
writeln;
writeln(' -------------------------------------------------------------');

for i:=1 to 20 do
begin

write('Team',i,': ');
if i<10 then write(' ');
for j:=1 to 20 do
if schedule[i][j]=0 then write('- ') else
if schedule[i][j]<10 then write(schedule[i][j],' ')
else write(schedule[i][j],' ');
writeln;
end;

end.
[/code]

• Thanks very much..this has gotten me on the right track finally. Thanks again!