Einzelnen Beitrag anzeigen

Benutzerbild von d3g
d3g

Registriert seit: 21. Jun 2002
602 Beiträge
 
#7

Re: Kartenspiel Algorithmus

  Alt 3. Feb 2004, 18:24
Zitat von Jelly:
Bedenke aber noch bei dem Code keine Karten doppelt zu ziehen, sonst hast du plötzlich 5 Asse
Und dazu nimmst du am besten Sets, das beste an Pascal überhaupt.

Delphi-Quellcode:
function PickCards(): String;
var
  Picked, i: Integer;
  Cards: set of 1..54;
  s: String;
begin
  Cards := [];
  for i := 1 to 10 do begin
    Picked := Randomize(54) + 1;
    if (not (Picked in Cards)) then
      Cards := Cards + [Picked];
  end;

  Result := '';
  for i := 1 to 54
    if (i in Cards) then begin
      case (i div 13) of
        0: Result := 'Kreuz ';
        1: Result := 'Pik ';
        2: Result := 'Herz ';
        3: Result := 'Karo ';
      end;
      case (i mod 13) of
        1: Result := Result + 'As';
        2..10: Result := Result + IntToStr(i mod 13);
        11: Result := Result + 'Bube';
        12: Result := Result + 'Dame';
        0: Result := Result + 'König';
      end;
    end;
end;
[edit]Zum Sortieren kannst du das Sortier-Tutorial hier aus dem Forum zu Rate ziehen.[/edit]
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat