三张牌型概率模拟

三张牌型概率模拟

模拟三张牌的牌形可能,不计(KA2)的顺子。

模拟1000万次的结果如下

单牌概率74.39%。豹子和顺金概率极低。

运行过程

clc;clear;
cnt = 0;
maxIter = 1e7;
Tdata = zeros(maxIter,1);
for i=1:maxIter
    cnt=cnt+1;
    Tdata(i)=zhajinhua();
    if mod(cnt,1e6)==0
        disp(cnt);
    end
end
TT = tabulate(Tdata);
bar(TT(:,1),TT(:,3));
set(gca, 'xticklabels', {'单', '对', '顺', '金', '顺金', '豹'}, 'Fontname', '黑体', 'Fontsize', 14);
ylabel('概率,%');
xlabel('牌型');
str = sprintf('%e次模拟牌型概率分布',maxIter);
title(str);

计算三张牌的函数

function [ttype] = zhajinhua()
%ZHAJINHUA 牌形的蒙特卡洛模拟
%   此处显示详细说明
t = randperm(52,3);
% disp(t);
A = mod(t,4); % 花色
% disp(A);
B = mod(t,13); % 牌型
% disp(B);
%ttype 0 散牌 1 对 2 顺 3 金 4 顺金 5 豹
isjin = 0;
isshun = 0;
ttype = 0;
if A(1)==A(2) && A(2)==A(3)
    isjin = 1; %金
    ttype = 3;
end
if B(1)==B(2) && B(2)==B(3)
    ttype = 5;
elseif B(1)==B(2) || B(1)==B(3) || B(2)==B(3)
    ttype = 1;
end
C = sort(B);
if (C(2)-C(1))==1&&(C(3)-C(2))==1
    isshun = 1;
    ttype = 2;
end
if C(1)==0 && C(2)==11 && C(3) == 12
    isshun = 1;
    ttype = 2;
end
if isshun&&isjin
    ttype = 4;
end
% disp(ttype);
end

posted on 2021-10-10 15:13  MultiSimOpt  阅读(787)  评论(0)    收藏  举报

导航