声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3245|回复: 9

[共享资源] 用matlab写的梭哈游戏

 关闭 [复制链接]
发表于 2006-11-13 10:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本程序作者:zjliu

suoha.m

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

  13. [an,K]=sort(an);
  14. anc=anc(K);
  15. aSC=zeros(3,5);
  16. ppl=find(anc<2);
  17. aSC(1,ppl)=1;

  18. [bn,K]=sort(bn);
  19. bnc=bnc(K);
  20. bSC=zeros(3,5);
  21. ppl=find(bnc<2);
  22. bSC(1,ppl)=1;

  23. figure('Position',[83 79 888 586],'MenuBar','none',...
  24.     'NumberTitle','off','name','扑克梭哈');
  25. axes('position',[0.3,0.94,0.2,0.2]);
  26. text(0,0,'\diamondsuit','fontsize',48,'color','r')
  27. axis off

  28. axes('position',[0.37,0.925,0.2,0.2]);
  29. text(0,0,'<','fontsize',56,'color','b')
  30. axis off

  31. axes('position',[0.44,0.94,0.2,0.2]);
  32. text(0,0,'\heartsuit','fontsize',48,'color','r')
  33. axis off

  34. axes('position',[0.51,0.925,0.2,0.2]);
  35. text(0,0,'<','fontsize',56,'color','b')
  36. axis off

  37. axes('position',[0.58,0.94,0.2,0.2]);
  38. text(0,0,'\clubsuit','fontsize',48,'color','black')
  39. axis off

  40. axes('position',[0.65,0.925,0.2,0.2]);
  41. text(0,0,'<','fontsize',56,'color','b')
  42. axis off

  43. axes('position',[0.72,0.94,0.2,0.2]);
  44. text(0,0,'\spadesuit','fontsize',48,'color','black')
  45. axis off

  46. a1=axes('position',[0.1,0.15,0.088 0.3]);
  47. rectangle('position',[0 0 1 1],'Curvature',...
  48.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  49. aTS1=text(0.2,0.4,char(CC(anc(1))),'fontsize',58,...
  50. 'color',aSC(:,1));
  51. aTN1=text(0.1,0.7,S(an(1)),'fontsize',48);
  52. axis off

  53. a2=axes('position',[0.2,0.15,0.088 0.3]);
  54. rectangle('position',[0 0 1 1],'Curvature',...
  55.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  56. aTS2=text(0.2,0.4,char(CC(anc(2))),'fontsize',58,...
  57. 'color',aSC(:,2));
  58. aTN2=text(0.1,0.7,S(an(2)),'fontsize',48);
  59. axis off

  60. a3=axes('position',[0.3,0.15,0.088 0.3]);
  61. rectangle('position',[0 0 1 1],'Curvature',...
  62.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  63. aTS3=text(0.2,0.4,char(CC(anc(3))),'fontsize',58,...
  64. 'color',aSC(:,3));
  65. aTN3=text(0.1,0.7,S(an(3)),'fontsize',48);
  66. axis off

  67. a4=axes('position',[0.4,0.15,0.088 0.3]);
  68. rectangle('position',[0 0 1 1],'Curvature',...
  69.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  70. aTS4=text(0.2,0.4,char(CC(anc(4))),'fontsize',58,...
  71. 'color',aSC(:,4));
  72. aTN4=text(0.1,0.7,S(an(4)),'fontsize',48);
  73. axis off

  74. a5=axes('position',[0.5,0.15,0.088 0.3]);
  75. rectangle('position',[0 0 1 1],'Curvature',...
  76.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  77. aTS5=text(0.2,0.4,char(CC(anc(5))),'fontsize',58,...
  78. 'color',aSC(:,5));
  79. aTN5=text(0.1,0.7,S(an(5)),'fontsize',48);
  80. axis off

  81. b1=axes('position',[0.1,0.55,0.088 0.3]);
  82. rectangle('position',[0 0 1 1],'Curvature',...
  83.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  84. bTS1=text(0.2,0.4,char(CC(bnc(1))),'fontsize',58,...
  85. 'color',bSC(:,1));
  86. bTN1=text(0.1,0.7,S(bn(1)),'fontsize',48);
  87. axis off

  88. b2=axes('position',[0.2,0.55,0.088 0.3]);
  89. rectangle('position',[0 0 1 1],'Curvature',...
  90.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  91. bTS2=text(0.2,0.4,char(CC(bnc(2))),'fontsize',58,...
  92. 'color',bSC(:,2));
  93. bTN2=text(0.1,0.7,S(bn(2)),'fontsize',48);
  94. axis off

  95. b3=axes('position',[0.3,0.55,0.088 0.3]);
  96. rectangle('position',[0 0 1 1],'Curvature',...
  97.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  98. bTS3=text(0.2,0.4,char(CC(bnc(3))),'fontsize',58,...
  99. 'color',bSC(:,3));
  100. bTN3=text(0.1,0.7,S(bn(3)),'fontsize',48);
  101. axis off

  102. b4=axes('position',[0.4,0.55,0.088 0.3]);
  103. rectangle('position',[0 0 1 1],'Curvature',...
  104.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  105. bTS4=text(0.2,0.4,char(CC(bnc(4))),'fontsize',58,...
  106. 'color',bSC(:,4));
  107. bTN4=text(0.1,0.7,S(bn(4)),'fontsize',48);
  108. axis off

  109. b5=axes('position',[0.5,0.55,0.088 0.3]);
  110. rectangle('position',[0 0 1 1],'Curvature',...
  111.     [0.3 0.3],'EdgeColor','b','linewidth',3);
  112. bTS5=text(0.2,0.4,char(CC(bnc(5))),'fontsize',58,...
  113. 'color',bSC(:,5));
  114. bTN5=text(0.1,0.7,S(bn(5)),'fontsize',48);
  115. axis off


  116. [aR,aT,aSkk]=suosuo(anc,an);
  117. [bR,bT,bSkk]=suosuo(bnc,bn);

  118. aui=uicontrol(gcf,'style','text',...
  119. 'unit','normalized','position',[0.6,0.29,0.12,0.06],...
  120. 'BackgroundColor','w','ForegroundColor','r',...
  121. 'string',aSkk,'fontsize',24);

  122. Mm=uicontrol(gcf,'style','text',...
  123. 'unit','normalized','position',[0.79,0.76,0.14,0.07],...
  124. 'BackgroundColor','w','ForegroundColor','b',...
  125. 'string','Money','fontsize',24);

  126. Mone=uicontrol(gcf,'style','text',...
  127. 'unit','normalized','position',[0.79,0.69,0.16,0.06],...
  128. 'BackgroundColor','w','ForegroundColor','g',...
  129. 'string',num2str(M),'fontsize',24);

  130. zhu=uicontrol(gcf,'style','edit',...
  131. 'unit','normalized','position',[0.73,0.29,0.1,0.06],...
  132. 'BackgroundColor','w','ForegroundColor','g',...
  133. 'string',num2str(Kp),'fontsize',14,'callback',...
  134. ['Kp=str2num(get(zhu,''string''));']);

  135. uicontrol(gcf,'style','push',...
  136. 'unit','normalized','position',[0.84,0.29,0.1,0.04],...
  137. 'BackgroundColor','w','ForegroundColor','g',...
  138. 'string','double','fontsize',14,'callback',...
  139. ['M=str2num(get(Mone,''string''));','Kp=2*Kp;',...
  140.     'set(zhu,''string'',num2str(Kp));',...
  141. 'set(Mone,''string'',num2str(M-Kp/2));']);

  142. bui=uicontrol(gcf,'style','text',...
  143. 'unit','normalized','position',[0.6,0.69,0.12,0.06],...
  144. 'BackgroundColor','w','ForegroundColor','r',...
  145. 'string',bSkk,'fontsize',24);

  146. uicontrol(gcf,'style','push',...
  147. 'unit','normalized','position',[0.6,0.19,0.1,0.04],...
  148. 'BackgroundColor','w','ForegroundColor','g',...
  149. 'string','Restar','fontsize',14,'callback','suoha;');

  150. uicontrol(gcf,'style','push',...
  151. 'unit','normalized','position',[0.71,0.19,0.1,0.04],...
  152. 'BackgroundColor','w','ForegroundColor','g',...
  153. 'string','发牌','fontsize',14,'callback','suoha_count;');
  154. uicontrol(gcf,'style','push',...
  155. 'unit','normalized','position',[0.82,0.19,0.1,0.04],...
  156. 'BackgroundColor','w','ForegroundColor','g',...
  157. 'string','换牌','fontsize',14,'callback',...
  158. ['suoha_count2;']);


  159. abN=zeros(1,5);
  160. uicontrol(gcf,'style','text',...
  161. 'unit','normalized','position',[0,0.49,0.1,0.04],...
  162. 'BackgroundColor','w','ForegroundColor','r',...
  163. 'string','player','fontsize',14);

  164. uicontrol(gcf,'style','text',...
  165. 'unit','normalized','position',[0.01,0.89,0.1,0.04],...
  166. 'BackgroundColor','w','ForegroundColor','r',...
  167. 'string','computer','fontsize',14);

  168. Bu={'hold off','hold on'};
  169. % button
  170. abutton1=uicontrol(gcf,'style','push',...
  171. 'unit','normalized','position',[0.11,0.09,0.06,0.04],...
  172. 'BackgroundColor','w','ForegroundColor','r',...
  173. 'string','hold off','callback',['abN(1)=not(abN(1));',...
  174.     'set(gcbo,''string'',Bu(abN(1)+1));']);

  175. abutton2=uicontrol(gcf,'style','push',...
  176. 'unit','normalized','position',[0.21,0.09,0.06,0.04],...
  177. 'BackgroundColor','w','ForegroundColor','r',...
  178. 'string','hold off','callback',['abN(2)=not(abN(2));',...
  179.     'set(gcbo,''string'',Bu(abN(2)+1));']);

  180. abutton3=uicontrol(gcf,'style','push',...
  181. 'unit','normalized','position',[0.31,0.09,0.06,0.04],...
  182. 'BackgroundColor','w','ForegroundColor','r',...
  183. 'string','hold off','callback',['abN(3)=not(abN(3));',...
  184.     'set(gcbo,''string'',Bu(abN(3)+1));']);

  185. abutton4=uicontrol(gcf,'style','push',...
  186. 'unit','normalized','position',[0.41,0.09,0.06,0.04],...
  187. 'BackgroundColor','w','ForegroundColor','r',...
  188. 'string','hold off','callback',['abN(4)=not(abN(4));',...
  189.     'set(gcbo,''string'',Bu(abN(4)+1));']);

  190. abutton5=uicontrol(gcf,'style','push',...
  191. 'unit','normalized','position',[0.51,0.09,0.06,0.04],...
  192. 'BackgroundColor','w','ForegroundColor','r',...
  193. 'string','hold off','callback',['abN(5)=not(abN(5));',...
  194.     'set(gcbo,''string'',Bu(abN(5)+1));']);
复制代码

评分

1

查看全部评分

回复
分享到:

使用道具 举报

 楼主| 发表于 2006-11-13 10:43 | 显示全部楼层
Suoha_count.m

  1. PPd=randperm(52);
  2. aa=PPd(1:5);
  3. bb=PPd(6:10);
  4. [anc,an]=ind2sub([4,13],aa);
  5. [bnc,bn]=ind2sub([4,13],bb);

  6. [an,K]=sort(an);
  7. anc=anc(K);
  8. aSC=zeros(3,5);
  9. ppl=find(anc<3);
  10. aSC(1,ppl)=1;

  11. [bn,K]=sort(bn);
  12. bnc=bnc(K);
  13. bSC=zeros(3,5);
  14. ppl=find(bnc<3);
  15. bSC(1,ppl)=1;
  16. abN=zeros(1,5);
  17. set(abutton1,'string','hold off');
  18. set(abutton2,'string','hold off');
  19. set(abutton3,'string','hold off');
  20. set(abutton4,'string','hold off');
  21. set(abutton5,'string','hold off');
  22. Kp=100;
  23. set(zhu,'string',num2str(Kp));

  24. set(aTS1,'string',CC(anc(1)),'color',aSC(:,1));
  25. set(aTS2,'string',CC(anc(2)),'color',aSC(:,2));
  26. set(aTS3,'string',CC(anc(3)),'color',aSC(:,3));
  27. set(aTS4,'string',CC(anc(4)),'color',aSC(:,4));
  28. set(aTS5,'string',CC(anc(5)),'color',aSC(:,5));

  29. set(bTS1,'string',CC(bnc(1)),'color',bSC(:,1));
  30. set(bTS2,'string',CC(bnc(2)),'color',bSC(:,2));
  31. set(bTS3,'string',CC(bnc(3)),'color',bSC(:,3));
  32. set(bTS4,'string',CC(bnc(4)),'color',bSC(:,4));
  33. set(bTS5,'string',CC(bnc(5)),'color',bSC(:,5));

  34. %%%%%%%%%%%
  35. set(aTN1,'string',S(an(1)));
  36. set(aTN2,'string',S(an(2)));
  37. set(aTN3,'string',S(an(3)));
  38. set(aTN4,'string',S(an(4)));
  39. set(aTN5,'string',S(an(5)));

  40. set(bTN1,'string',S(bn(1)));
  41. set(bTN2,'string',S(bn(2)));
  42. set(bTN3,'string',S(bn(3)));
  43. set(bTN4,'string',S(bn(4)));
  44. set(bTN5,'string',S(bn(5)));

  45. [aR,aT,aSkk]=suosuo(anc,an);
  46. [bR,bT,bSkk]=suosuo(bnc,bn);
  47. set(aui,'string',aSkk);
  48. set(bui,'string',bSkk);
  49. Kz=1;
复制代码
 楼主| 发表于 2006-11-13 10:43 | 显示全部楼层
suoha_count2.m

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


  6. an(abN==0)=[];
  7. anc(abN==0)=[];
  8. cc=[];
  9. if length(an)>0;
  10.     cc=sub2ind([4,13],anc,an);   
  11. end
  12. cc(length(cc)+1:5)=PPd(11:10+5-length(cc));
  13. bb=PPd(16:20);
  14. aa=cc;

  15. [anc,an]=ind2sub([4,13],aa);
  16. [bnc,bn]=ind2sub([4,13],bb);

  17. [an,K]=sort(an);
  18. anc=anc(K);
  19. aSC=zeros(3,5);
  20. ppl=find(anc<3);
  21. aSC(1,ppl)=1;

  22. [bn,K]=sort(bn);
  23. bnc=bnc(K);
  24. bSC=zeros(3,5);
  25. ppl=find(bnc<3);
  26. bSC(1,ppl)=1;
  27. M=M-Kp;
  28. set(aTS1,'string',CC(anc(1)),'color',aSC(:,1));
  29. set(aTS2,'string',CC(anc(2)),'color',aSC(:,2));
  30. set(aTS3,'string',CC(anc(3)),'color',aSC(:,3));
  31. set(aTS4,'string',CC(anc(4)),'color',aSC(:,4));
  32. set(aTS5,'string',CC(anc(5)),'color',aSC(:,5));

  33. set(bTS1,'string',CC(bnc(1)),'color',bSC(:,1));
  34. set(bTS2,'string',CC(bnc(2)),'color',bSC(:,2));
  35. set(bTS3,'string',CC(bnc(3)),'color',bSC(:,3));
  36. set(bTS4,'string',CC(bnc(4)),'color',bSC(:,4));
  37. set(bTS5,'string',CC(bnc(5)),'color',bSC(:,5));

  38. %%%%%%%%%%%
  39. set(aTN1,'string',S(an(1)));
  40. set(aTN2,'string',S(an(2)));
  41. set(aTN3,'string',S(an(3)));
  42. set(aTN4,'string',S(an(4)));
  43. set(aTN5,'string',S(an(5)));

  44. set(bTN1,'string',S(bn(1)));
  45. set(bTN2,'string',S(bn(2)));
  46. set(bTN3,'string',S(bn(3)));
  47. set(bTN4,'string',S(bn(4)));
  48. set(bTN5,'string',S(bn(5)));
  49. [aR,aT,aSkk]=suosuo(anc,an);
  50. [bR,bT,bSkk]=suosuo(bnc,bn);
  51. set(aui,'string',aSkk);
  52. set(bui,'string',bSkk);
  53. M=sign(aR-bR)*Kp*aT+M+Kp;
  54. set(Mone,'string',num2str(M));
  55. Kz=0;
复制代码
 楼主| 发表于 2006-11-13 10:43 | 显示全部楼层
  1. function [R,T,Skk]=suosuo(xnc,xn);
  2. %比较大小
  3. dxn=diff(xn);
  4. if length(unique(xn))==5 & length(unique(dxn))==1 & length(unique(xnc))==1;
  5.     R=8*13^2+max(xn)*13+unique(xnc);
  6.     T=15;
  7.     Skk='同花顺';
  8. elseif length(unique(xn))==2 & dxn(1)+dxn(4)>0;
  9.     R=7*13^2;
  10.     T=10;
  11.     Skk='铁枝(四张)';
  12. elseif length(unique(xn))==2 & dxn(2)+dxn(3)>0;
  13.     R=6*13^2+xn(3)*13;
  14.     T=5;
  15.     Skk='葫芦';
  16. elseif length(unique(xnc))==1;
  17.     R=5*13^2+max(xn)*13+unique(xnc);
  18.     T=1;
  19.     Skk='同花';
  20. elseif length(unique(xn))==5 & length(find(dxn==1))==4;
  21.     R=4*13^2+max(xn)*13+xnc(xn==max(xn));
  22.     T=1;
  23.     Skk='顺子';
  24. elseif length(find(xn==xn(3)))==3;
  25.     R=3*13^2+xn(3)*13;
  26.     T=1;
  27.     Skk='三条';
  28. elseif length(unique(xn))==3;
  29.     R=2*13^2+max(xn(dxn==0))*13+max(xnc(xn==max(xn(dxn==0))));
  30.     T=1;
  31.     Skk='兔胚';
  32. elseif length(unique(xn))==4;
  33.     R=13^2+max(xn(dxn==0))*13+max(xnc(xn==max(xn(dxn==0))));
  34.     T=1;
  35.     Skk='单胚';
  36. else
  37.     R=max(xn)*13+xnc(xn==max(xn));
  38.     T=1;
  39.     Skk='单张';
  40. end
复制代码
发表于 2006-11-19 11:23 | 显示全部楼层
一共几个M文件,放到一块试了一下缺个脚本
 楼主| 发表于 2006-11-20 08:15 | 显示全部楼层
原帖由 nymail 于 2006-11-19 11:23 发表
一共几个M文件,放到一块试了一下缺个脚本



一共2个文件,分别见1楼和2楼,没有问题
注意文件名,帖子中已经给出了
发表于 2007-2-3 19:54 | 显示全部楼层
萝卜就是强啊
发表于 2007-4-28 18:55 | 显示全部楼层
........

小弟大开眼界!要继续努力学习啊!
发表于 2007-5-9 00:04 | 显示全部楼层
牛就一个字,我只说一次!就是不知道怎么玩!如果再给出一个help 就好了!
发表于 2007-5-9 12:39 | 显示全部楼层
到底是怎么用的,麻烦教下,小弟新手,弄了以后它把5张牌都一下给我了
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-14 05:49 , Processed in 0.070073 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表