麻雀

Last-modified: 2008-07-11 (金) 22:41:15

お蔵フォルダを整理していたら,麻雀の配牌時の役を数える計算プログラムなぞがでてきました.
アップします.ちゃんと計算してんだかどうだか..

***************************************************
MahJong.sas
マージャン配牌統計
1999.1.8 翔
***************************************************;

options nocenter;

data pai;
  do a="P","M","S";
  do b=1 to 9;
    output;
  end;end;
  b="";
  do a="Z";
  do c="e","s","w","n";
    output;
  end;end;
  do a="Y";
  do c="W","G","R";
    output;
  end;end;
run;

/*
%macro local1;
%do i=1 %to 100;
*/

data allpai;set pai pai pai pai;r=ranuni(0);run;
proc sort;by r;run;
data haipai;set allpai;drop r;if _n_>31 then stop;run;

proc sort;by a b c;run;

data mentsu;set haipai;
  keep atama anko juntsu;
  a1=lag1(a);b1=lag1(b);c1=lag1(c);
  a2=lag2(a);b2=lag2(b);c2=lag2(c);
  if a1=a2 and b1=b2 and c1=c2 then atama=1;
  if a=a1 and b=b1 and c=c1 and
     a=a2 and b=b2 and c=c2 then anko=1;
  if a=a1 and b=b1+1 and
     a=a2 and b=b2+2         then juntsu=1;
run;

data haipai2;merge haipai mentsu(firstobs=3);run;

data haipai2;set haipai2;
  if lag1(atama)=1 then atama1=1;
  if lag1(anko)=1  then anko1=1;
  if lag2(anko)=1  then anko2=1;
  if lag1(juntsu)=1  then juntsu1=1;
  if lag2(juntsu)=1  then juntsu2=1;
  mentsu=sum(atama,atama1,anko,anko1,anko2,juntsu,juntsu1,juntsu2);
run;

proc print;
where mentsu ne .;
var  a b c;sum mentsu atama atama1  anko anko1 anko2 juntsu juntsu1 juntsu2;
run;


/*
proc summary data=haipai;var atama mentsu anko juntsu;output out=sum sum=;run;
proc append data=sum out=stat;run;

%end;
%mend;

proc datasets lib=work;delete stat;run;
%local1;

proc print data=stat;where not(atama>=1 and mentsu>=4);run;
 */