Delphi - Como crear un programa round robin en delphi?

 
Vista:
sin imagen de perfil

Como crear un programa round robin en delphi?

Publicado por elias (1 intervención) el 30/04/2013 19:35:55
Tengo este codigo pero no se que mas falta o como implementarlo...iniciandome en delphi...ayuda...me gustaria correrlo, que me falta? gracias

const
MaxTeams = 500;
MaxRounds = MaxTeams;
MaxGames = (MaxTeams+1) Div 2;
Home = 1;
Away = 2;
Bye : Integer = -1;
type
TGameAry = Array[1..MaxTeams] of Integer;
TRoundRobinAry = Array[1..MaxRounds,1..MaxGames,Home..Away] of Integer;

....

procedure TForm1.CreateRoundRobin(var RoundRobinAry: TRoundRobinAry;
const Teams: Integer);
var
GameAry : TGameAry;
Half,
Rounds,
Bottom,
SwitchBottom,
TempGameValue,
i,
ii,
iii : Integer;
begin
For i := 1 to MaxRounds do
For ii := 1 to MaxGames do
For iii := 1 to 2 do
RoundRobinAry[i][ii][iii] := 0;
IF ((Teams MaxTeams)) Then exit;
//Initilize Team Array with Team Numbers
For i := 1 to Teams do
GameAry[i] := i;
if (Teams then For i := (Teams+1) to MaxTeams do
GameAry[i] := 0;
Half := (Teams-1) Div 2;
IF ((Teams Mod 2)=0)
Then Begin
Rounds := Teams - 1;
Bottom := Teams - 2;
SwitchBottom := Bottom + 1;
End
else Begin
Rounds := Teams;
Bottom := Teams - 1;
SwitchBottom := Teams;
end;
for i := 1 to Rounds do
begin
for ii := 1 to Half do
begin
RoundRobinAry[i][ii][Home] := GameAry[ii];
RoundRobinAry[i][ii][Away] := GameAry[Bottom-ii+1];
end;
If ((Teams - Bottom) = 2) // if even number of teams
then begin
if i mod 2 = 0
then begin
RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
RoundRobinAry[i][Half+1][Away] := GameAry[Bottom+2];
end
else begin
RoundRobinAry[i][Half+1][Away] := GameAry[SwitchBottom];
RoundRobinAry[i][Half+1][Home] := GameAry[Bottom+2];
end
end
else begin // if odd number of teams then idle team gets a bye
RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
RoundRobinAry[i][Half+1][Away] := Bye;
end;
//rotate value of gameary
TempGameValue := GameAry[SwitchBottom];
for ii := SwitchBottom downto 2 do
GameAry[ii] := GameAry[ii-1];
GameAry[1] := TempGameValue;
end;
end;

You can easily print the result to a richedit with a push of a button.

procedure TForm1.Button1Click(Sender: TObject);
const NoOfTeams : integer = 7;
var roundrobinary : TRoundRobinAry;

begin
RichEdit1.Clear;
CreateRoundRobin(RoundRobinAry,NoOfTeams);
PrintFullChart(RoundRobinAry); //see below
end;


Procedure Tform1.PrintFullChart(const RoundRobinAry: TRoundRobinAry;);
var i,ii : integer;
begin
richedit1.Lines.BeginUpdate;
i := 1;
ii := 1;
repeat;
Richedit1.Lines.Add(Format('Round : %d', [i]));
while (RoundRobinAry[i][ii][Home] 0) do
begin
if RoundRobinAry[i][ii][away] - 1 then
Richedit1.Lines.Add(Format('Home : %3.0d Away: %3.0d', [RoundRobinAry[i][ii][Home],RoundRobinAry[i][ii][Away]]))
else
Richedit1.Lines.Add(Format('BYE FOR TEAM : %3.0d', [RoundRobinAry[i][ii][Home]]));
inc(ii);
end;
inc(i);
ii := 1;
until (RoundRobinAry[i][ii][Home] = 0);
Richedit1.Lines.endupdate;
end;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder