Einzelnen Beitrag anzeigen

Benutzerbild von d3g
d3g

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

Re: Kartenspiel Algorithmus

  Alt 3. Feb 2004, 19:33
Zitat von MikeS:
dafür hast du keine auswertung!

53/13 = 4,...
52/13 = 4,0;
Dass da Joker im Spiel sind hab ich auch überhaupt nicht geplant -- bei mir ist 13 * 4 == 54 . Schön langsam glaube ich an die Drogen-Sache, vor allem weil ich noch einen weiteren dummen Fehler gefunden habe.

Delphi-Quellcode:
type
  TStrArray = array[1..10] of String;

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

  Result := '';
  count := 1;

  for i := 1 to 54 do begin
    if (i in Cards) then begin
      if (i - 1 >= 13 * 4) then
        Result[count] := 'Joker'
      else
        case ((i - 1) div 13) of
          0: Result[count] := 'Kreuz ';
          1: Result[count] := 'Pik ';
          2: Result[count] := 'Herz ';
          3: Result[count] := 'Karo ';
        end;
        case ((i - 1) mod 13) of
          0..8: Result[count] := Result[count] + IntToStr((i + 1) mod 13);
          9: Result[count] := Result[count] + 'Bube';
          10: Result[count] := Result[count] + 'Dame';
          11: Result[count] := Result[count] + 'König';
          12: Result[count] := Result[count] + 'As';
        end;
    count := count + 1;
  end;
end;
Immerhin braucht jetzt nicht mehr hinterher sortiert zu werden.

[edit]Das war der Fehler, den ich meinte, the_master.[/quote]
[edit]Und schon wieder so ein dummer In-Pascal-fängt-man-mit-1-an-zu-zählen-nicht-konsequent-durchgeführt-Fehler[/edit]
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat