Salut tous,
Je cherche une solution. Le problème est qu'il y a N joueurs sur ma liste. Je doit préparer des paires (de joueurs) pour le
round 1, puis ensuite pour un nouveau round, et ainsi de suite. Comment contrôler ça ? Je précise que le joueur A ne peut pas jouer avec le joueur B plus d'1 fois au cours du tournoi. Il ne peut pas jouer plus de deux fois sous la même couleur (si le joueur A a joué le 2e et 3e round en noir, il ne peut jouer le 4e de nouveau en noir ! Il (elle) doit se voir attribuer la couleur blan che (règles du codex d'échec). Comment contrôler tout ça ?
Quelqu'un aurait-il une idée ?
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprocedure ListeMatches(Njoueurs:integer); var liste:TstringList; X,N,I,J:integer; begin liste := TstringList.create; x := 1; for J:=1 to Njoueurs-1 do for i:=J+1 to Njoueurs do Liste.add('Joueur ' + inttostr(J) + ' contre joueur ' + inttostr(i)); Liste.savetofile('ListeMatchesPour' + inttostr(Njoueurs)+ 'joueurs.txt'); Liste.free; end;
procedure ListeMatches(Njoueurs:integer); var liste:TstringList; I,J:integer; begin liste := TstringList.create; for J:=1 to Njoueurs-1 do for i:=J+1 to Njoueurs do Liste.add('Joueur ' + inttostr(J) + ' contre joueur ' + inttostr(i)); Liste.savetofile('ListeMatchesPour' + inttostr(Njoueurs)+ 'joueurs.txt'); Liste.free; end;
@korgis:
pas de soucis pour la traduction..
C'était pour dubois77
ah bon !
qu'est ce que j'ai encore fait ?
J'ai jamais assisté à un cours d'anglais et ça va être dur de m'y mettre maintenant !
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, StrUtils; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } end; var Form1: TForm1; TChoix: array of string; TPlayers: array of string; SL: TStringList; const TNamePlayers: array[0..3] of string = ('Patrick', 'Henri', 'Pascal', 'Daniel'); implementation {$R *.dfm} function GetStrPart(const Str, Delimiter: string; const WordIndex: cardinal = 1): string; var I, P1, P2, LD: integer; begin Result := ''; if (posex(Delimiter, Str[1]) = 1) and (WordIndex <= 1) then exit; P1 := 1; LD := Length(Delimiter); for I := 1 to WordIndex - 1 do begin P1 := posex(Delimiter, Str, P1); if P1 = 0 then exit else P1 := P1 + LD; end; P2 := posex(Delimiter, Str, P1); if P2 = 0 then P2 := length(Str) + 1; Result := copy(Str, P1, P2 - P1); end; procedure DisplayCombin(tab: array of string); var a, b: integer; begin SL.Clear; for a := 0 to (length(tab) - 2) do for b := a + 1 to (length(tab) - 1) do SL.Add(tab[a] + ';' + tab[b]); end; procedure DisplayTruePlayers; var i, j, cj: integer; begin Setlength(TChoix, 2); Setlength(TPLAYERS, 2 * Length(TNamePlayers)); TChoix[0] := 'N'; TChoix[1] := 'B'; cj := 0; for i := 0 to Length(TNamePlayers) - 1 do for j := 0 to Length(TChoix) - 1 do begin TPLAYERS[cj] := TNamePlayers[i] + TChoix[j]; Inc(cj); end; DisplayCombin(TPLAYERS); form1.Memo1.Lines.Clear; for i := 0 to SL.Count - 1 do begin if (copy(GetstrPart(SL.Strings[i], ';', 1), 1, length(GetstrPart(SL.Strings[i], ';', 1)) - 1) = copy(GetstrPart(SL.Strings[i], ';', 2), 1, length(GetstrPart(SL.Strings[i], ';', 2)) - 1)) or (RightStr(GetstrPart(SL.Strings[i], ';', 1), 1) = RightStr(GetstrPart(SL.Strings[i], ';', 2), 1)) then continue; form1.Memo1.Lines.Add(SL.Strings[i]); end; end; procedure TForm1.FormCreate(Sender: TObject); begin SL := TStringList.Create; end; procedure TForm1.Button1Click(Sender: TObject); begin DisplayTruePlayers; end; end.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, StrUtils; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } end; var Form1: TForm1; TChoix: array of string; TPlayers: array of string; SL: TStringList; const TNamePlayers: array[0..3] of string = ('Patrick', 'Henri', 'Pascal', 'Daniel'); implementation {$R *.dfm} function GetStrPart(const Str, Delimiter: string; const WordIndex: cardinal = 1): string; var I, P1, P2, LD: integer; begin Result := ''; if (posex(Delimiter, Str[1]) = 1) and (WordIndex <= 1) then exit; P1 := 1; LD := Length(Delimiter); for I := 1 to WordIndex - 1 do begin P1 := posex(Delimiter, Str, P1); if P1 = 0 then exit else P1 := P1 + LD; end; P2 := posex(Delimiter, Str, P1); if P2 = 0 then P2 := length(Str) + 1; Result := copy(Str, P1, P2 - P1); end; procedure DisplayCombin(tab: array of string); var a, b: integer; begin SL.Clear; for a := 0 to (length(tab) - 2) do for b := a + 1 to (length(tab) - 1) do SL.Add(tab[a] + ';' + tab[b]); end; procedure DisplayNewPlayers; var i, j, cj: integer; begin Setlength(TChoix, 2); Setlength(TPLAYERS, 2 * Length(TNamePlayers)); TChoix[0] := 'N'; TChoix[1] := 'B'; cj := 0; for i := 0 to Length(TNamePlayers) - 1 do for j := 0 to Length(TChoix) - 1 do begin TPLAYERS[cj] := TNamePlayers[i] + TChoix[j]; Inc(cj); end; DisplayCombin(TPLAYERS); form1.Memo1.Lines.Clear; for i := 0 to SL.Count - 1 do begin if (copy(GetstrPart(SL.Strings[i], ';', 1), 1, length(GetstrPart(SL.Strings[i], ';', 1)) - 1) = copy(GetstrPart(SL.Strings[i], ';', 2), 1, length(GetstrPart(SL.Strings[i], ';', 2)) - 1)) or (RightStr(GetstrPart(SL.Strings[i], ';', 1), 1) = RightStr(GetstrPart(SL.Strings[i], ';', 2), 1)) then continue; form1.Memo1.Lines.Add(SL.Strings[i]); end; end; procedure TForm1.FormCreate(Sender: TObject); begin SL := TStringList.Create; end; procedure TForm1.Button1Click(Sender: TObject); begin DisplayNewPlayers; end; procedure TForm1.FormDestroy(Sender: TObject); begin SL.Free; end; end.