Zaciekawił mnie temat, więc posiedziałem chwilę nad tym i efektem jest taki oto kod:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TKarty = (kierAS, kierKROL, kierDAMA, kierWALET, kier10, kier9,
karoAS, karoKROL, karoDAMA, karoWALET, karo10, karo9,
pikAS, pikKROL, pikDAMA, pikWALET, pik10, pik9,
treflAS, treflKROL, treflDAMA, treflWALET, trefl10, trefl9);
type
TZbiorKart = set of TKarty;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure CheckCards(rozdane : TZbiorKart);
end;
var
Form1: TForm1;
Rozdane : TZbiorKart;
Figury : array of TZbiorKart;
Opisy : array of string;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
rozdane := [kierAS, karoAS, karoKROL, treflDAMA, pikWALET, pik10, trefl9];
CheckCards(rozdane);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
rozdane := [kierAS, karoAS, karoKROL, treflDAMA, pikWALET, pik10, trefl9];
CheckCards(rozdane);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
rozdane := [pikAS, karoAS, karoKROL, treflWALET, pikWALET, pik10, trefl9];
CheckCards(rozdane);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
rozdane := [kierAS, karoAS, pikAS, treflDAMA, pikWALET, pik10, trefl9];
CheckCards(rozdane);
end;
procedure TForm1.CheckCards(rozdane: TZbiorKart);
var
I: Integer;
s: string;
begin
s := 'Nic';
for I := 0 to high(figury) do
begin
if rozdane * figury[i] = figury[i] then
begin
s := Opisy[i];
break;
end;
end;
form1.Caption := s;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,j,k,l,m : integer;
begin
//kombinacje pokerów
for I := 1 to 4 do
begin
for j := 1 to 4 do
begin
for k := 1 to 4 do
begin
for l := 1 to 4 do
begin
for m := 1 to 4 do
begin
SetLength(figury,high(figury)+2);
if i=1 then Include(figury[high(figury)],kierAS) else
if i=2 then Include(figury[high(figury)],karoAS) else
if i=3 then Include(figury[high(figury)],pikAS) else
if i=4 then Include(figury[high(figury)],treflAS);
if j=1 then Include(figury[high(figury)],kierKROL) else
if j=2 then Include(figury[high(figury)],karoKROL) else
if j=3 then Include(figury[high(figury)],pikKROL) else
if j=4 then Include(figury[high(figury)],treflKROL);
if k=1 then Include(figury[high(figury)],kierDAMA) else
if k=2 then Include(figury[high(figury)],karoDAMA) else
if k=3 then Include(figury[high(figury)],pikDAMA) else
if k=4 then Include(figury[high(figury)],treflDAMA);
if l=1 then Include(figury[high(figury)],kierWALET) else
if l=2 then Include(figury[high(figury)],karoWALET) else
if l=3 then Include(figury[high(figury)],pikWALET) else
if l=4 then Include(figury[high(figury)],treflWALET);
if m=1 then Include(figury[high(figury)],kier10) else
if m=2 then Include(figury[high(figury)],karo10) else
if m=3 then Include(figury[high(figury)],pik10) else
if m=4 then Include(figury[high(figury)],trefl10);
SetLength(opisy,high(Opisy)+2);
Opisy[high(Opisy)] := 'Duży Poker';
end;
end;
end;
end;
end;
//wszystkie kombinacje dla innych figur
end;
end.
Maknkamentem jest to że trzeba stworzyć tablicę wszystkich możliwości dla figur (chodzi o miksy kolorów). Na szczęście można to wykonać półautomatycznie (przykład w OnCreate).
Warunkiem poprawnego działania, jest umieszczenie w tablicy figur w kolejności ich "ważności", ponieważ gdy pętla natknie się na kombinację istniejącą, to przerywa działanie.
W tym kodzie, naciśnięcie buttona 1 lub 2 spowoduje wyświetlenie napisu "DUŻY POKER" natomiast
3 lub 4 wyświetli "NIC"