Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Trying to create a schedule

VipahVipah Posts: 4Member
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.

Comments

  • ibyiby Posts: 323Member
    : 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]

  • ibyiby Posts: 323Member
    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;

    readln;
    end.
    [/code]



  • VipahVipah Posts: 4Member
    Thanks very much..this has gotten me on the right track finally. Thanks again!

Sign In or Register to comment.