suffer 发表于 2006-11-13 10:42

用matlab写的梭哈游戏

本程序作者:zjliu

suoha.m

% clear
M=1000;
Kp=100;
Kz=1;
close all
S={'2','3','4','5','6','7','8','9','10','J','Q','K','A'};
CC={'\diamondsuit','\heartsuit','\clubsuit','\spadesuit'};
PPd=randperm(52);
aa=PPd(1:5);
bb=PPd(6:10);
=ind2sub(,aa);
=ind2sub(,bb);

=sort(an);
anc=anc(K);
aSC=zeros(3,5);
ppl=find(anc<2);
aSC(1,ppl)=1;

=sort(bn);
bnc=bnc(K);
bSC=zeros(3,5);
ppl=find(bnc<2);
bSC(1,ppl)=1;

figure('Position',,'MenuBar','none',...
    'NumberTitle','off','name','扑克梭哈');
axes('position',);
text(0,0,'\diamondsuit','fontsize',48,'color','r')
axis off

axes('position',);
text(0,0,'<','fontsize',56,'color','b')
axis off

axes('position',);
text(0,0,'\heartsuit','fontsize',48,'color','r')
axis off

axes('position',);
text(0,0,'<','fontsize',56,'color','b')
axis off

axes('position',);
text(0,0,'\clubsuit','fontsize',48,'color','black')
axis off

axes('position',);
text(0,0,'<','fontsize',56,'color','b')
axis off

axes('position',);
text(0,0,'\spadesuit','fontsize',48,'color','black')
axis off

a1=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
aTS1=text(0.2,0.4,char(CC(anc(1))),'fontsize',58,...
'color',aSC(:,1));
aTN1=text(0.1,0.7,S(an(1)),'fontsize',48);
axis off

a2=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
aTS2=text(0.2,0.4,char(CC(anc(2))),'fontsize',58,...
'color',aSC(:,2));
aTN2=text(0.1,0.7,S(an(2)),'fontsize',48);
axis off

a3=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
aTS3=text(0.2,0.4,char(CC(anc(3))),'fontsize',58,...
'color',aSC(:,3));
aTN3=text(0.1,0.7,S(an(3)),'fontsize',48);
axis off

a4=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
aTS4=text(0.2,0.4,char(CC(anc(4))),'fontsize',58,...
'color',aSC(:,4));
aTN4=text(0.1,0.7,S(an(4)),'fontsize',48);
axis off

a5=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
aTS5=text(0.2,0.4,char(CC(anc(5))),'fontsize',58,...
'color',aSC(:,5));
aTN5=text(0.1,0.7,S(an(5)),'fontsize',48);
axis off

b1=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
bTS1=text(0.2,0.4,char(CC(bnc(1))),'fontsize',58,...
'color',bSC(:,1));
bTN1=text(0.1,0.7,S(bn(1)),'fontsize',48);
axis off

b2=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
bTS2=text(0.2,0.4,char(CC(bnc(2))),'fontsize',58,...
'color',bSC(:,2));
bTN2=text(0.1,0.7,S(bn(2)),'fontsize',48);
axis off

b3=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
bTS3=text(0.2,0.4,char(CC(bnc(3))),'fontsize',58,...
'color',bSC(:,3));
bTN3=text(0.1,0.7,S(bn(3)),'fontsize',48);
axis off

b4=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
bTS4=text(0.2,0.4,char(CC(bnc(4))),'fontsize',58,...
'color',bSC(:,4));
bTN4=text(0.1,0.7,S(bn(4)),'fontsize',48);
axis off

b5=axes('position',);
rectangle('position',,'Curvature',...
    ,'EdgeColor','b','linewidth',3);
bTS5=text(0.2,0.4,char(CC(bnc(5))),'fontsize',58,...
'color',bSC(:,5));
bTN5=text(0.1,0.7,S(bn(5)),'fontsize',48);
axis off


=suosuo(anc,an);
=suosuo(bnc,bn);

aui=uicontrol(gcf,'style','text',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string',aSkk,'fontsize',24);

Mm=uicontrol(gcf,'style','text',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','b',...
'string','Money','fontsize',24);

Mone=uicontrol(gcf,'style','text',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','g',...
'string',num2str(M),'fontsize',24);

zhu=uicontrol(gcf,'style','edit',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','g',...
'string',num2str(Kp),'fontsize',14,'callback',...
['Kp=str2num(get(zhu,''string''));']);

uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','g',...
'string','double','fontsize',14,'callback',...
['M=str2num(get(Mone,''string''));','Kp=2*Kp;',...
    'set(zhu,''string'',num2str(Kp));',...
'set(Mone,''string'',num2str(M-Kp/2));']);

bui=uicontrol(gcf,'style','text',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string',bSkk,'fontsize',24);

uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','g',...
'string','Restar','fontsize',14,'callback','suoha;');

uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','g',...
'string','发牌','fontsize',14,'callback','suoha_count;');
uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','g',...
'string','换牌','fontsize',14,'callback',...
['suoha_count2;']);


abN=zeros(1,5);
uicontrol(gcf,'style','text',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','player','fontsize',14);

uicontrol(gcf,'style','text',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','computer','fontsize',14);

Bu={'hold off','hold on'};
% button
abutton1=uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','hold off','callback',['abN(1)=not(abN(1));',...
    'set(gcbo,''string'',Bu(abN(1)+1));']);

abutton2=uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','hold off','callback',['abN(2)=not(abN(2));',...
    'set(gcbo,''string'',Bu(abN(2)+1));']);

abutton3=uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','hold off','callback',['abN(3)=not(abN(3));',...
    'set(gcbo,''string'',Bu(abN(3)+1));']);

abutton4=uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','hold off','callback',['abN(4)=not(abN(4));',...
    'set(gcbo,''string'',Bu(abN(4)+1));']);

abutton5=uicontrol(gcf,'style','push',...
'unit','normalized','position',,...
'BackgroundColor','w','ForegroundColor','r',...
'string','hold off','callback',['abN(5)=not(abN(5));',...
    'set(gcbo,''string'',Bu(abN(5)+1));']);

suffer 发表于 2006-11-13 10:43

Suoha_count.m

PPd=randperm(52);
aa=PPd(1:5);
bb=PPd(6:10);
=ind2sub(,aa);
=ind2sub(,bb);

=sort(an);
anc=anc(K);
aSC=zeros(3,5);
ppl=find(anc<3);
aSC(1,ppl)=1;

=sort(bn);
bnc=bnc(K);
bSC=zeros(3,5);
ppl=find(bnc<3);
bSC(1,ppl)=1;
abN=zeros(1,5);
set(abutton1,'string','hold off');
set(abutton2,'string','hold off');
set(abutton3,'string','hold off');
set(abutton4,'string','hold off');
set(abutton5,'string','hold off');
Kp=100;
set(zhu,'string',num2str(Kp));

set(aTS1,'string',CC(anc(1)),'color',aSC(:,1));
set(aTS2,'string',CC(anc(2)),'color',aSC(:,2));
set(aTS3,'string',CC(anc(3)),'color',aSC(:,3));
set(aTS4,'string',CC(anc(4)),'color',aSC(:,4));
set(aTS5,'string',CC(anc(5)),'color',aSC(:,5));

set(bTS1,'string',CC(bnc(1)),'color',bSC(:,1));
set(bTS2,'string',CC(bnc(2)),'color',bSC(:,2));
set(bTS3,'string',CC(bnc(3)),'color',bSC(:,3));
set(bTS4,'string',CC(bnc(4)),'color',bSC(:,4));
set(bTS5,'string',CC(bnc(5)),'color',bSC(:,5));

%%%%%%%%%%%
set(aTN1,'string',S(an(1)));
set(aTN2,'string',S(an(2)));
set(aTN3,'string',S(an(3)));
set(aTN4,'string',S(an(4)));
set(aTN5,'string',S(an(5)));

set(bTN1,'string',S(bn(1)));
set(bTN2,'string',S(bn(2)));
set(bTN3,'string',S(bn(3)));
set(bTN4,'string',S(bn(4)));
set(bTN5,'string',S(bn(5)));

=suosuo(anc,an);
=suosuo(bnc,bn);
set(aui,'string',aSkk);
set(bui,'string',bSkk);
Kz=1;

suffer 发表于 2006-11-13 10:43

suoha_count2.m

if Kz==0;
    errordlg('请先按 [ 发牌 ] 按钮 !');
    Kk=1;
    return
end


an(abN==0)=[];
anc(abN==0)=[];
cc=[];
if length(an)>0;
    cc=sub2ind(,anc,an);   
end
cc(length(cc)+1:5)=PPd(11:10+5-length(cc));
bb=PPd(16:20);
aa=cc;

=ind2sub(,aa);
=ind2sub(,bb);

=sort(an);
anc=anc(K);
aSC=zeros(3,5);
ppl=find(anc<3);
aSC(1,ppl)=1;

=sort(bn);
bnc=bnc(K);
bSC=zeros(3,5);
ppl=find(bnc<3);
bSC(1,ppl)=1;
M=M-Kp;
set(aTS1,'string',CC(anc(1)),'color',aSC(:,1));
set(aTS2,'string',CC(anc(2)),'color',aSC(:,2));
set(aTS3,'string',CC(anc(3)),'color',aSC(:,3));
set(aTS4,'string',CC(anc(4)),'color',aSC(:,4));
set(aTS5,'string',CC(anc(5)),'color',aSC(:,5));

set(bTS1,'string',CC(bnc(1)),'color',bSC(:,1));
set(bTS2,'string',CC(bnc(2)),'color',bSC(:,2));
set(bTS3,'string',CC(bnc(3)),'color',bSC(:,3));
set(bTS4,'string',CC(bnc(4)),'color',bSC(:,4));
set(bTS5,'string',CC(bnc(5)),'color',bSC(:,5));

%%%%%%%%%%%
set(aTN1,'string',S(an(1)));
set(aTN2,'string',S(an(2)));
set(aTN3,'string',S(an(3)));
set(aTN4,'string',S(an(4)));
set(aTN5,'string',S(an(5)));

set(bTN1,'string',S(bn(1)));
set(bTN2,'string',S(bn(2)));
set(bTN3,'string',S(bn(3)));
set(bTN4,'string',S(bn(4)));
set(bTN5,'string',S(bn(5)));
=suosuo(anc,an);
=suosuo(bnc,bn);
set(aui,'string',aSkk);
set(bui,'string',bSkk);
M=sign(aR-bR)*Kp*aT+M+Kp;
set(Mone,'string',num2str(M));
Kz=0;

suffer 发表于 2006-11-13 10:43

function =suosuo(xnc,xn);
%比较大小
dxn=diff(xn);
if length(unique(xn))==5 & length(unique(dxn))==1 & length(unique(xnc))==1;
    R=8*13^2+max(xn)*13+unique(xnc);
    T=15;
    Skk='同花顺';
elseif length(unique(xn))==2 & dxn(1)+dxn(4)>0;
    R=7*13^2;
    T=10;
    Skk='铁枝(四张)';
elseif length(unique(xn))==2 & dxn(2)+dxn(3)>0;
    R=6*13^2+xn(3)*13;
    T=5;
    Skk='葫芦';
elseif length(unique(xnc))==1;
    R=5*13^2+max(xn)*13+unique(xnc);
    T=1;
    Skk='同花';
elseif length(unique(xn))==5 & length(find(dxn==1))==4;
    R=4*13^2+max(xn)*13+xnc(xn==max(xn));
    T=1;
    Skk='顺子';
elseif length(find(xn==xn(3)))==3;
    R=3*13^2+xn(3)*13;
    T=1;
    Skk='三条';
elseif length(unique(xn))==3;
    R=2*13^2+max(xn(dxn==0))*13+max(xnc(xn==max(xn(dxn==0))));
    T=1;
    Skk='兔胚';
elseif length(unique(xn))==4;
    R=13^2+max(xn(dxn==0))*13+max(xnc(xn==max(xn(dxn==0))));
    T=1;
    Skk='单胚';
else
    R=max(xn)*13+xnc(xn==max(xn));
    T=1;
    Skk='单张';
end

nymail 发表于 2006-11-19 11:23

一共几个M文件,放到一块试了一下缺个脚本

suffer 发表于 2006-11-20 08:15

原帖由 nymail 于 2006-11-19 11:23 发表
一共几个M文件,放到一块试了一下缺个脚本


一共2个文件,分别见1楼和2楼,没有问题
注意文件名,帖子中已经给出了

fxyz 发表于 2007-2-3 19:54

萝卜就是强啊

2上弦月2 发表于 2007-4-28 18:55

........

小弟大开眼界!要继续努力学习啊!

smtmobly 发表于 2007-5-9 00:04

牛就一个字,我只说一次!就是不知道怎么玩!如果再给出一个help 就好了!

f1111aaaa 发表于 2007-5-9 12:39

到底是怎么用的,麻烦教下,小弟新手,弄了以后它把5张牌都一下给我了
页: [1]
查看完整版本: 用matlab写的梭哈游戏