Pascal/Turbo Pascal - Programa en Pascal complicado

   
Vista:

Programa en Pascal complicado

Publicado por CAESAR (12 intervenciones) el 01/05/2013 19:09:47
Deseo hacer un programita que muestre torneo round robin, tengo este codigo en delphi...como puede adaptarse para pascal? o como puede hacerse uno en pascal basado en esta idea?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
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

Programa en Pascal complicado

Publicado por ramon (2072 intervenciones) el 01/05/2013 21:49:43
{A qui tienes para pascal 7 }

uses
crt;

const
MaxTeams = 100;
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;

var
tro : TRoundRobinAry;
i1,i2,i3 : integer;

procedure 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;
For i := 1 to Teams do
GameAry[i] := i;
if Teams < 0 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)
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
RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
RoundRobinAry[i][Half+1][Away] := Bye;
end;

TempGameValue := GameAry[SwitchBottom];
for ii := SwitchBottom downto 2 do
GameAry[ii] := GameAry[ii-1];
GameAry[1] := TempGameValue;
end;
end;

begin
clrscr;
CreateRoundRobin(TRo,4);
for i1 := 1 to 3 do
begin
for i2 := 1 to 3 do
begin
for i3 := 1 to 3 do
write(' ',tro[i1,i2,i3]);
writeln;
end;
writeln;
end;
readkey;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Programa en Pascal complicado

Publicado por CAESAR (12 intervenciones) el 02/05/2013 18:33:03
Gracias, lo he probado...pero solo me muestra unos valores al ejecutar...¿como puedo implementar la idea para generar el round robin de 20 jugadores? lo que necesito es algo como lo que se hace en este vinculo:

http://www.devenezia.com/downloads/round-robin/index.html pero en pascal...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar