erlang-麻将胡牌

 最近休息在家还没时间工作,闲来晚上写写服务端开发,还是使用之前比较有熟悉的erlang,最近棋牌挺火爆!使用erlang实现下麻将胡牌,测试已经可以!

 下面是部分代码(写不好不要吐槽!哈哈):全部代码到git https://github.com/StartHua/erlang-- 记住后面加--(不改了程序本是坑)

checkHu(UserPai) ->
T = getMyPaisForRecord(UserPai,#r_userMyPai{}),
%第一步检查AAA(减少检查,代码难看)
{A1,B1} = validHu_AAA(T#r_userMyPai.wan,0),
M = case (A1 and (B1 =< 1)) of
true  ->
{A2,B2} = validHu_AAA(T#r_userMyPai.tiao,0),
case (A2 and (B2 =< 1)) of
true  ->
{A3,B3} = validHu_AAA(T#r_userMyPai.bing,0),
case (A3 and (B3 =< 1)) of
true  ->
{A4,B4} = validHu_AAA(T#r_userMyPai.feng,0),
case (A4 and (B4 =< 1)) of
true  ->
{A5,B5} = validHu_AAA(T#r_userMyPai.zfb,0),
Count = B1+B2+B3+B4+B5,
(A5 and (Count == 1));
false ->
false
end;
false ->
false
end;
false ->
false
end;
false ->
false
end,


% 第二部检查AA
MAA = case M of
true  ->
true;
false ->
{A11,B11} = validHu_AA(T#r_userMyPai.wan,0),
case (A11 and (B11 =< 1)) of
true  ->
{A22,B22} = validHu_AA(T#r_userMyPai.tiao,0),
case (A22 and (B22 =< 1)) of
true  ->
{A33,B33} = validHu_AA(T#r_userMyPai.bing,0),
case (A33 and (B33 =< 1)) of
true  ->
{A44,B44} = validHu_AA(T#r_userMyPai.feng,0),
case (A44 and (B44 =< 1)) of
true  ->
{A55,B55} = validHu_AA(T#r_userMyPai.zfb,0),
Count2 = B11+B22+B33+B44+B55,
(A55 and (Count2 == 1));
false ->
false
end;
false ->
false
end;
false ->
false
end;
false ->
false
end
end,


% 检查ABC
MABC = case MAA of
true ->
true;
false ->
{A111,B111} = validHu_AA(T#r_userMyPai.wan,0),
M111 = case (A111 and (B111 =< 1)) of
true  ->
{A222,B222} = validHu_AA(T#r_userMyPai.tiao,0),
case (A222 and (B222 =< 1)) of
true  ->
{A333,B333} = validHu_AA(T#r_userMyPai.bing,0),
case (A333 and (B333 =< 1)) of
true  ->
{A444,B444} = validHu_AA(T#r_userMyPai.feng,0),
case (A444 and (B444 =< 1)) of
true  ->
{A555,B555} = validHu_AA(T#r_userMyPai.zfb,0),
Count3 = B111+B222+B333+B444+B555,
(A555 and (Count3 == 1));
false ->
false
end;
false ->
false
end;
false ->
false
end;
false ->
false
end
end.

猜你喜欢

转载自blog.csdn.net/u010665359/article/details/73182364