//============================================================================
//牌の配列:JSON形式
//============================================================================
var paiType = [
{"No":0,"paiName":"赤五萬","cssSprite":"man0"},
{"No":1,"paiName":"一萬","cssSprite":"man1"},
{"No":2,"paiName":"二萬","cssSprite":"man2"},
{"No":3,"paiName":"三萬","cssSprite":"man3"},
{"No":4,"paiName":"四萬","cssSprite":"man4"},
{"No":5,"paiName":"五萬","cssSprite":"man5"},
{"No":6,"paiName":"六萬","cssSprite":"man6"},
{"No":7,"paiName":"七萬","cssSprite":"man7"},
{"No":8,"paiName":"八萬","cssSprite":"man8"},
{"No":9,"paiName":"九萬","cssSprite":"man9"},
{"No":10,"paiName":"赤五筒","cssSprite":"pin0"},
{"No":11,"paiName":"一筒","cssSprite":"pin1"},
{"No":12,"paiName":"二筒","cssSprite":"pin2"},
{"No":13,"paiName":"三筒","cssSprite":"pin3"},
{"No":14,"paiName":"四筒","cssSprite":"pin4"},
{"No":15,"paiName":"五筒","cssSprite":"pin5"},
{"No":16,"paiName":"六筒","cssSprite":"pin6"},
{"No":17,"paiName":"七筒","cssSprite":"pin7"},
{"No":18,"paiName":"八筒","cssSprite":"pin8"},
{"No":19,"paiName":"九筒","cssSprite":"pin9"},
{"No":20,"paiName":"赤五索","cssSprite":"sou0"},
{"No":21,"paiName":"一索","cssSprite":"sou1"},
{"No":22,"paiName":"二索","cssSprite":"sou2"},
{"No":23,"paiName":"三索","cssSprite":"sou3"},
{"No":24,"paiName":"四索","cssSprite":"sou4"},
{"No":25,"paiName":"五索","cssSprite":"sou5"},
{"No":26,"paiName":"六索","cssSprite":"sou6"},
{"No":27,"paiName":"七索","cssSprite":"sou7"},
{"No":28,"paiName":"八索","cssSprite":"sou8"},
{"No":29,"paiName":"九索","cssSprite":"sou9"},
{"No":30,"paiName":"裏","cssSprite":"ji0"},
{"No":31,"paiName":"東","cssSprite":"ji1"},
{"No":32,"paiName":"南","cssSprite":"ji2"},
{"No":33,"paiName":"西","cssSprite":"ji3"},
{"No":34,"paiName":"北","cssSprite":"ji4"},
{"No":35,"paiName":"白","cssSprite":"ji5"},
{"No":36,"paiName":"發","cssSprite":"ji6"},
{"No":37,"paiName":"中","cssSprite":"ji7"}
];
//グローバル変数==============================================================
var tehai = new Array(37);//手牌の配列:37種
tehai = [0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0];
//var tempTehai = new Array(37);//tehai配列のクローン用
//============================================================================
//国士無双のアガリ判定とシャンテン数を返す関数
//============================================================================
function syanten_kokusi(){
var syantenKokusi=13;
var toitsu_suu=0;//雀頭
var i;
//19牌をチェックする処理
for(i=1;i<30;i++){
if(i%10==1||i%10==9){//10で割った余りが1または9の場合に実行する
if(tehai[i]){
syantenKokusi--;
}
////余った19牌を雀頭としてカウント。1個でOK
if(tehai[i]>=2&&!toitsu_suu){
toitsu_suu=1;
}
}
}
//字牌をチェックする処理
for(i=31;i<38;i++){
if(tehai[i]){
syantenKokusi--;
}
////余った字牌を雀頭としてカウント。1個でOK
if(tehai[i]>=2&&!toitsu_suu){
toitsu_suu=1;
}
}
//雀頭がある場合の処理
syantenKokusi-=toitsu_suu;
return syantenKokusi;
}
//============================================================================
//チートイツのアガリ判定とシャンテン数を返す関数:修正版
//============================================================================
function syanten_7toitsu(){
var toitsu_suu = 0;//対子数
var syurui_suu = 0;//牌の種類
var seven7toitsu = 6;//七対子のシャンテン数
var i;
var kantsu_count=0;
for(i=1;i<38;i++){
if(!tehai[i]){continue;}//牌が無い時は以降の処理を中断して、ループの最初に戻る
if(tehai[i]===4){kantsu_count++;}
syurui_suu++;//4枚チートイツを回避するために牌種をカウントしておく
if(tehai[i]>=2){
toitsu_suu++;
}
}
if(syurui_suu===7&&toitsu_suu===7){
return -1;//アガリ判定
}
if(syurui_suu>=7&&toitsu_suu===6&&kantsu_count===0){
return 0;//テンパイ判定
}
if(syurui_suu===6&&toitsu_suu===6){
return 1;//1シャンテン判定
}
syanten7toitsu=6-toitsu_suu;//チートイツのシャンテン数を求める計算式
return syanten7toitsu;
}
//============================================================================
//動作チェック用
$("#SyantenCheckBtn").click(function() {
var paiTehaiSyantenCheck = $("#paiTehaiSyantenCheck");//要素を変数に格納してキャッシュ
paiTehaiSyantenCheck.empty();
var syantenkokusi = syanten_kokusi();//syantenCheck()の動作テスト用関数
paiTehaiSyantenCheck.append("国士無双のシャンテン数は" + syantenkokusi);
var syanten7toitsu = syanten_7toitsu();//syantenCheck()の動作テスト用関数
paiTehaiSyantenCheck.append("<br>チートイツのシャンテン数は" + syanten7toitsu);
});
//============================================================================