プログラムの解説と実行
アガリとシャンテン数を算出するでひと通り完成したシャンテン数算出プログラムを使って、簡単なシャンテン数当てゲームを作ってみました。配牌を取ってシャンテン数を数えて答え合わせをするだけです。いわゆるたたき台ですね。メンツやターツの構成を素早く把握する練習にご利用ください。
簡易シャンテン数当てゲームで遊んでみよう
操作は簡単です。[配牌を取る]ボタンを押すとパネル内に配牌が表示されます。続いて[シャンテン数を確認する]ボタンを押すとシャンテン数が表示されます。
配牌:0牌
シャンテン数
本プログラムを応用したツール
麻雀トレーニングツールとして好評稼働中。PC&スマホ対応。
シャンテン数当てゲーム
シャンテン数当てゲーム
JavaScriptソースコード
本記事で紹介したサンプルプログラムをダウンロードできます。
ダウンロードをする前にお読みください
- サイトで紹介している記事の内容や公開しているプログラムの動作は100%保障するものではありません。
- 当プログラム使用による如何なる不具合やトラブル、損害の責任も負いかねます。
- 当プログラムは断り無く内容が変わることがあります。
- 当プログラムを別サイトで配布することは禁止します。
- サポートはいたしません。
- 自己責任にてご利用くださいませ。
以上をご確認の上、プログラムのダウンロードをお願いいたします。
- 本プログラムはjQueryを組み込んだ状態じゃないと動作しません。ご注意ください。
- 乱数処理は「Mersenne Twister in JavaScript」を使用しています。
- アガリ判定とシャンテン数を算出する処理は「麻雀C言語プログラム集」のシャンテン数を参考にしています。
「program_012.js」内のシャンテン数算出プログラムは、「通常手のアガリとシャンテン数を算出する~再帰呼び出し版)」のシャンテン数プログラムに差し替えました(2016年7月14日)。
サンプルプログラムのソースコード
ソースコードは折りたたんであります。[+]を押すと、折りたたまれたソースコードが開きます。[-]を押すと、コードは折りたたまれます。
+ program_012.jsを開く
//============================================================================ //牌の配列:JSON形式 //============================================================================ var paiYama = [ {"No":0,"paiName":"一萬","paiCode":"1m","paiNo":1}, {"No":1,"paiName":"一萬","paiCode":"1m","paiNo":1}, {"No":2,"paiName":"一萬","paiCode":"1m","paiNo":1}, {"No":3,"paiName":"一萬","paiCode":"1m","paiNo":1}, {"No":4,"paiName":"二萬","paiCode":"2m","paiNo":2}, {"No":5,"paiName":"二萬","paiCode":"2m","paiNo":2}, {"No":6,"paiName":"二萬","paiCode":"2m","paiNo":2}, {"No":7,"paiName":"二萬","paiCode":"2m","paiNo":2}, {"No":8,"paiName":"三萬","paiCode":"3m","paiNo":3}, {"No":9,"paiName":"三萬","paiCode":"3m","paiNo":3}, {"No":10,"paiName":"三萬","paiCode":"3m","paiNo":3}, {"No":11,"paiName":"三萬","paiCode":"3m","paiNo":3}, {"No":12,"paiName":"四萬","paiCode":"4m","paiNo":4}, {"No":13,"paiName":"四萬","paiCode":"4m","paiNo":4}, {"No":14,"paiName":"四萬","paiCode":"4m","paiNo":4}, {"No":15,"paiName":"四萬","paiCode":"4m","paiNo":4}, {"No":16,"paiName":"赤五萬","paiCode":"0m","paiNo":0}, {"No":17,"paiName":"五萬","paiCode":"5m","paiNo":5}, {"No":18,"paiName":"五萬","paiCode":"5m","paiNo":5}, {"No":19,"paiName":"五萬","paiCode":"5m","paiNo":5}, {"No":20,"paiName":"六萬","paiCode":"6m","paiNo":6}, {"No":21,"paiName":"六萬","paiCode":"6m","paiNo":6}, {"No":22,"paiName":"六萬","paiCode":"6m","paiNo":6}, {"No":23,"paiName":"六萬","paiCode":"6m","paiNo":6}, {"No":24,"paiName":"七萬","paiCode":"7m","paiNo":7}, {"No":25,"paiName":"七萬","paiCode":"7m","paiNo":7}, {"No":26,"paiName":"七萬","paiCode":"7m","paiNo":7}, {"No":27,"paiName":"七萬","paiCode":"7m","paiNo":7}, {"No":28,"paiName":"八萬","paiCode":"8m","paiNo":8}, {"No":29,"paiName":"八萬","paiCode":"8m","paiNo":8}, {"No":30,"paiName":"八萬","paiCode":"8m","paiNo":8}, {"No":31,"paiName":"八萬","paiCode":"8m","paiNo":8}, {"No":32,"paiName":"九萬","paiCode":"9m","paiNo":9}, {"No":33,"paiName":"九萬","paiCode":"9m","paiNo":9}, {"No":34,"paiName":"九萬","paiCode":"9m","paiNo":9}, {"No":35,"paiName":"九萬","paiCode":"9m","paiNo":9}, {"No":36,"paiName":"一筒","paiCode":"1p","paiNo":11}, {"No":37,"paiName":"一筒","paiCode":"1p","paiNo":11}, {"No":38,"paiName":"一筒","paiCode":"1p","paiNo":11}, {"No":39,"paiName":"一筒","paiCode":"1p","paiNo":11}, {"No":40,"paiName":"二筒","paiCode":"2p","paiNo":12}, {"No":41,"paiName":"二筒","paiCode":"2p","paiNo":12}, {"No":42,"paiName":"二筒","paiCode":"2p","paiNo":12}, {"No":43,"paiName":"二筒","paiCode":"2p","paiNo":12}, {"No":44,"paiName":"三筒","paiCode":"3p","paiNo":13}, {"No":45,"paiName":"三筒","paiCode":"3p","paiNo":13}, {"No":46,"paiName":"三筒","paiCode":"3p","paiNo":13}, {"No":47,"paiName":"三筒","paiCode":"3p","paiNo":13}, {"No":48,"paiName":"四筒","paiCode":"4p","paiNo":14}, {"No":49,"paiName":"四筒","paiCode":"4p","paiNo":14}, {"No":50,"paiName":"四筒","paiCode":"4p","paiNo":14}, {"No":51,"paiName":"四筒","paiCode":"4p","paiNo":14}, {"No":52,"paiName":"赤五筒","paiCode":"0p","paiNo":10}, {"No":53,"paiName":"五筒","paiCode":"5p","paiNo":15}, {"No":54,"paiName":"五筒","paiCode":"5p","paiNo":15}, {"No":55,"paiName":"五筒","paiCode":"5p","paiNo":15}, {"No":56,"paiName":"六筒","paiCode":"6p","paiNo":16}, {"No":57,"paiName":"六筒","paiCode":"6p","paiNo":16}, {"No":58,"paiName":"六筒","paiCode":"6p","paiNo":16}, {"No":59,"paiName":"六筒","paiCode":"6p","paiNo":16}, {"No":60,"paiName":"七筒","paiCode":"7p","paiNo":17}, {"No":61,"paiName":"七筒","paiCode":"7p","paiNo":17}, {"No":62,"paiName":"七筒","paiCode":"7p","paiNo":17}, {"No":63,"paiName":"七筒","paiCode":"7p","paiNo":17}, {"No":64,"paiName":"八筒","paiCode":"8p","paiNo":18}, {"No":65,"paiName":"八筒","paiCode":"8p","paiNo":18}, {"No":66,"paiName":"八筒","paiCode":"8p","paiNo":18}, {"No":67,"paiName":"八筒","paiCode":"8p","paiNo":18}, {"No":68,"paiName":"九筒","paiCode":"9p","paiNo":19}, {"No":69,"paiName":"九筒","paiCode":"9p","paiNo":19}, {"No":70,"paiName":"九筒","paiCode":"9p","paiNo":19}, {"No":71,"paiName":"九筒","paiCode":"9p","paiNo":19}, {"No":72,"paiName":"一索","paiCode":"1s","paiNo":21}, {"No":73,"paiName":"一索","paiCode":"1s","paiNo":21}, {"No":74,"paiName":"一索","paiCode":"1s","paiNo":21}, {"No":75,"paiName":"一索","paiCode":"1s","paiNo":21}, {"No":76,"paiName":"二索","paiCode":"2s","paiNo":22}, {"No":77,"paiName":"二索","paiCode":"2s","paiNo":22}, {"No":78,"paiName":"二索","paiCode":"2s","paiNo":22}, {"No":79,"paiName":"二索","paiCode":"2s","paiNo":22}, {"No":80,"paiName":"三索","paiCode":"3s","paiNo":23}, {"No":81,"paiName":"三索","paiCode":"3s","paiNo":23}, {"No":82,"paiName":"三索","paiCode":"3s","paiNo":23}, {"No":83,"paiName":"三索","paiCode":"3s","paiNo":23}, {"No":84,"paiName":"四索","paiCode":"4s","paiNo":24}, {"No":85,"paiName":"四索","paiCode":"4s","paiNo":24}, {"No":86,"paiName":"四索","paiCode":"4s","paiNo":24}, {"No":87,"paiName":"四索","paiCode":"4s","paiNo":24}, {"No":88,"paiName":"赤五索","paiCode":"0s","paiNo":20}, {"No":89,"paiName":"五索","paiCode":"5s","paiNo":25}, {"No":90,"paiName":"五索","paiCode":"5s","paiNo":25}, {"No":91,"paiName":"五索","paiCode":"5s","paiNo":25}, {"No":92,"paiName":"六索","paiCode":"6s","paiNo":26}, {"No":93,"paiName":"六索","paiCode":"6s","paiNo":26}, {"No":94,"paiName":"六索","paiCode":"6s","paiNo":26}, {"No":95,"paiName":"六索","paiCode":"6s","paiNo":26}, {"No":96,"paiName":"七索","paiCode":"7s","paiNo":27}, {"No":97,"paiName":"七索","paiCode":"7s","paiNo":27}, {"No":98,"paiName":"七索","paiCode":"7s","paiNo":27}, {"No":99,"paiName":"七索","paiCode":"7s","paiNo":27}, {"No":100,"paiName":"八索","paiCode":"8s","paiNo":28}, {"No":101,"paiName":"八索","paiCode":"8s","paiNo":28}, {"No":102,"paiName":"八索","paiCode":"8s","paiNo":28}, {"No":103,"paiName":"八索","paiCode":"8s","paiNo":28}, {"No":104,"paiName":"九索","paiCode":"9s","paiNo":29}, {"No":105,"paiName":"九索","paiCode":"9s","paiNo":29}, {"No":106,"paiName":"九索","paiCode":"9s","paiNo":29}, {"No":107,"paiName":"九索","paiCode":"9s","paiNo":29}, {"No":108,"paiName":"東","paiCode":"1z","paiNo":31}, {"No":109,"paiName":"東","paiCode":"1z","paiNo":31}, {"No":110,"paiName":"東","paiCode":"1z","paiNo":31}, {"No":111,"paiName":"東","paiCode":"1z","paiNo":31}, {"No":112,"paiName":"南","paiCode":"2z","paiNo":32}, {"No":113,"paiName":"南","paiCode":"2z","paiNo":32}, {"No":114,"paiName":"南","paiCode":"2z","paiNo":32}, {"No":115,"paiName":"南","paiCode":"2z","paiNo":32}, {"No":116,"paiName":"西","paiCode":"3z","paiNo":33}, {"No":117,"paiName":"西","paiCode":"3z","paiNo":33}, {"No":118,"paiName":"西","paiCode":"3z","paiNo":33}, {"No":119,"paiName":"西","paiCode":"3z","paiNo":33}, {"No":120,"paiName":"北","paiCode":"4z","paiNo":34}, {"No":121,"paiName":"北","paiCode":"4z","paiNo":34}, {"No":122,"paiName":"北","paiCode":"4z","paiNo":34}, {"No":123,"paiName":"北","paiCode":"4z","paiNo":34}, {"No":124,"paiName":"白","paiCode":"5z","paiNo":35}, {"No":125,"paiName":"白","paiCode":"5z","paiNo":35}, {"No":126,"paiName":"白","paiCode":"5z","paiNo":35}, {"No":127,"paiName":"白","paiCode":"5z","paiNo":35}, {"No":128,"paiName":"發","paiCode":"6z","paiNo":36}, {"No":129,"paiName":"發","paiCode":"6z","paiNo":36}, {"No":130,"paiName":"發","paiCode":"6z","paiNo":36}, {"No":131,"paiName":"發","paiCode":"6z","paiNo":36}, {"No":132,"paiName":"中","paiCode":"7z","paiNo":37}, {"No":133,"paiName":"中","paiCode":"7z","paiNo":37}, {"No":134,"paiName":"中","paiCode":"7z","paiNo":37}, {"No":135,"paiName":"中","paiCode":"7z","paiNo":37} ]; 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 yama = new Array(135);//牌山の配列:136牌 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);//preTempTehai配列のクローン var red5manCount;//赤5マンの数 var red5pinCount;//赤5ピンの数 var red5souCount;//赤5ソウの数 var toitsu_suu;//トイツ数 var koutsu_suu;//コーツ数 var shuntsu_suu;//シュンツ数 var taatsu_suu;//ターツ数 var mentsu_suu;//メンツ数 var syanten_temp;//シャンテン数(作業用用) var syanten_normal;//シャンテン数(結果用) var kanzen_koutsu_suu;//完全コーツ数 var kanzen_shuntsu_suu;//完全シュンツ数 var kanzen_Koritsu_suu;//完全孤立牌数 //============================================================================ //赤ドラの有無をチェックしてカウントする処理【赤ドラのカウントを事前にしなかった場合に使う】 //各赤ドラはtehai配列の0,10,20番地にあるものとする //============================================================================ function checkReddora(){ //グローバル変数の初期化 red5manCount=0;//赤5マンの数 red5pinCount=0;//赤5ピンの数 red5souCount=0;//赤5ソウの数 //赤五萬の有無をチェックしてカウントする if(tehai[0]){ red5manCount+=tehai[0];//赤五萬の牌数を追加 } //赤五筒の有無をチェックしてカウントする if(tehai[10]){ red5pinCount+=tehai[10];//赤五筒の牌数を追加 } //赤五索の有無をチェックしてカウントする if(tehai[20]){ red5souCount+=tehai[20];//赤五索の牌数を追加 } } //============================================================================ //赤ドラの有無をチェックして配列操作する処理【シャンテン数やテンパイチェックを実行する前に使う】 //tehai配列内を0→5、10→15、20→25 //============================================================================ function moveReddora(){ //赤五萬の有無をチェックして番地を移動させる処理 if(tehai[0]&&red5manCount){ tehai[5]+=tehai[0];//赤五萬の牌数を五萬の番地5に追加 tehai[0]=0;//番地0を初期化 } //赤五筒の有無をチェックして番地を移動させる処理 if(tehai[10]&&red5pinCount){ tehai[15]+=tehai[10];//赤五筒の牌数を五筒の番地15に追加 tehai[10]=0;//番地10を初期化 } //赤五索の有無をチェックして番地を移動させる処理 if(tehai[20]&&red5souCount){ tehai[25]+=tehai[20];//赤五索の牌数を五索の番地25に追加 tehai[20]= 0;//番地20を初期化 } } //============================================================================ //赤ドラの有無をチェックして配列内の元の番地に戻す処理 //tehai配列内を5→0、15→10、25→20 //============================================================================ function removeReddora(){ //赤五萬の有無をチェックして番地を移動:5→0 if(!tehai[0]&&tehai[5]&&red5manCount){ tehai[5]--; tehai[0]++; } //赤五筒の有無をチェックして番地を移動:15→10 if(!tehai[10]&&tehai[15]&&red5pinCount){ tehai[15]--; tehai[10]++; } //赤五索の有無をチェックして番地を移動:25→20 if(!tehai[20]&&tehai[25]&&red5souCount){ tehai[25]--; tehai[20]++; } } //============================================================================ //国士無双のアガリ判定とシャンテン数を返す関数 //============================================================================ 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; //トイツを数える for(i=1;i<38;i++){ if(!tehai[i]){continue;}//牌が無い時は以降の処理を中断して、ループの最初に戻る syurui_suu++;//4枚チートイツを回避するために牌種をカウントしておく if(tehai[i]>=2){ toitsu_suu++; } } syanten7toitsu=6-toitsu_suu;//チートイツのシャンテン数を求める計算式 //4枚チートイツを回避する処理【チートイツのアガリまたはテンパイ時の牌種が7枚になるのが理由】 if(syurui_suu<7){ syanten7toitsu=7-syurui_suu; } return syanten7toitsu; } //============================================================================ //アガリ判定とシャンテン数を返す関数 //============================================================================ function syantenCheck(){ var i; //初期化 toitsu_suu=0;//トイツ数 koutsu_suu=0;//コーツ数 shuntsu_suu=0;//シュンツ数 taatsu_suu=0;//ターツ数 mentsu_suu=0;//メンツ数 syanten_temp=0;//シャンテン数(計算用) syanten_normal=8;//シャンテン数(結果用) kanzen_koutsu_suu=0;//完全コーツ数 kanzen_shuntsu_suu=0;//完全シュンツ数 kanzen_Koritsu_suu=0;//完全孤立牌数 tempTehai = $.extend(true, [], tehai);//tehai配列のバックアップを取る //前もって完全なシュンツ・コーツ・孤立牌を抜いておく kanzen_koutsu_suu = KanzenKoutsuCheck();//完全に独立したコーツを抜き出して個数を返す関数呼び出し kanzen_shuntsu_suu = kanzenShuntsuCheck();//完全に独立したシュンツを抜き出して個数を返す関数呼び出し kanzen_Koritsu_suu=KanzenKoritsuCheck();//完全に独立した孤立牌を抜き出して個数を返す関数の実行 //雀頭抜き出し→コーツ抜き出し→シュンツ抜き出し→ターツ候補抜き出し for(i=1;i<38;i++){ //頭抜き出し if(tempTehai[i]>=2){ toitsu_suu++; tempTehai[i]-=2; mentu_cut1(1); tempTehai[i]+=2; toitsu_suu--; } }//for toitsu_suu=0; //【雀頭が無い場合の処理】コーツ抜き出し→シュンツ抜き出し→ターツ候補抜き出し for(var i=1;i<38;i++){ mentu_cut1(1); //【不要っぽい】雀頭抜き出し→シュンツ抜き出し→コーツ抜き出し→ターツ候補抜き出し //mentu_cut2(1); return syanten_normal;//最終的な結果 } //============================================================================ //メンツ抜き出し1【→コーツ抜き出し→シュンツ抜き出し】 //============================================================================ function mentu_cut1(i){ for(var j=i;j<30;j++){//※字牌のコーツは完全コーツ処理で抜いているの数牌だけで良い //コーツ抜き出し if(tempTehai[j]>=3){ mentsu_suu++; koutsu_suu++; tempTehai[j]-=3; mentu_cut1(j); tempTehai[j]+=3; koutsu_suu--; }//if //シュンツ抜き出し if(tempTehai[j]&&tempTehai[j+1]&&tempTehai[j+2]&&j<28){ shuntsu_suu++; tempTehai[j]--; tempTehai[j+1]--; tempTehai[j+2]--; mentu_cut1(j);//自身を呼び出す tempTehai[j]++; tempTehai[j+1]++; tempTehai[j+2]++; shuntsu_suu--; }//if }//for taatu_cut(1);//ターツ抜きへ return; } //============================================================================ //メンツ抜き出し2【シュンツ抜き出し→コーツ抜き出し】 //============================================================================ function mentu_cut2(i){ for(var j=i;j<30;j++){//※字牌のコーツは完全コーツ処理で抜いているの数牌だけで良い //シュンツ抜き出し if(tempTehai[j]&&tempTehai[j+1]&&tempTehai[j+2]&&j<28){ shuntsu_suu++; tempTehai[j]--; tempTehai[j+1]--; tempTehai[j+2]--; mentu_cut2(j);//自身を呼び出す tempTehai[j]++; tempTehai[j+1]++; tempTehai[j+2]++; shuntsu_suu--; }//if //コーツ抜き出し if(tempTehai[j]>=3){ mentsu_suu++; koutsu_suu++; tempTehai[j]-=3; mentu_cut2(j); tempTehai[j]+=3; koutsu_suu--; }//if }//for taatu_cut(1);//ターツ抜きへ return; } //============================================================================ //ターツ抜き出し //============================================================================ function taatu_cut(i){ for(var j=i;j<38;j++){ mentsu_suu=kanzen_koutsu_suu+koutsu_suu+kanzen_shuntsu_suu+shuntsu_suu; if(mentsu_suu+taatsu_suu<4){//メンツとターツの合計は4まで //トイツ抜き出し if(tempTehai[j]==2){ taatsu_suu++; tempTehai[j]-=2; taatu_cut(j); tempTehai[j]+=2; taatsu_suu--; } //リャンメン・ペンチャン抜き出し if(tempTehai[j]&&tempTehai[j+1]&&j<29&&j%10<9){ taatsu_suu++; tempTehai[j]--; tempTehai[j+1]--; taatu_cut(j); tempTehai[j]++; tempTehai[j+1]++; taatsu_suu--; } //カンチャン抜き出し if(tempTehai[j]&&!tempTehai[j+1]&&tempTehai[j+2]&&j<28&&j%10<8){ taatsu_suu++; tempTehai[j]--; tempTehai[j+2]--; taatu_cut(j); tempTehai[j]++; tempTehai[j+2]++; taatsu_suu--; } }//if }//for syanten_temp=8-mentsu_suu*2-taatsu_suu-toitsu_suu; if(syanten_temp<syanten_normal) {syanten_normal=syanten_temp;} return; }//function_end //============================================================================ //完全コーツを抜き出して個数を返す関数 //============================================================================ function KanzenKoutsuCheck(){ var Kanzenkoutsu_suu = 0; var i,j; //字牌の完全コーツを抜き出す for(i=31;i<38;i++){ if(tempTehai[i]>=3){ tempTehai[i]-=3; Kanzenkoutsu_suu++; } }//for //数牌の完全コーツを抜き出す for(i=0;i<30;i+=10){ if(tempTehai[i+1]>=3&&!tempTehai[i+2]&&!tempTehai[i+3]){ tempTehai[i+1]-=3; Kanzenkoutsu_suu++; } if(!tempTehai[i+1]&&tempTehai[i+2]>=3&&!tempTehai[i+3]&&!tempTehai[i+4]){ tempTehai[i+2]-=3; Kanzenkoutsu_suu++; } //3~7の完全コーツを抜く for(j=0;j<5;j++){ if(!tempTehai[i+j+1]&&!tempTehai[i+j+2]&&tempTehai[i+j+3]>=3&&!tempTehai[i+j+4]&&!tempTehai[i+j+5]){ tempTehai[i+j+3]-=3; Kanzenkoutsu_suu++; } } if(!tempTehai[i+6]&&!tempTehai[i+7]&&tempTehai[i+8]>=3&&!tempTehai[i+9]){ tempTehai[i+8]-=3; Kanzenkoutsu_suu++; } if(!tempTehai[i+7]&&!tempTehai[i+8]&&tempTehai[i+9]>=3){ tempTehai[i+9]-=3; Kanzenkoutsu_suu++; } }//for return Kanzenkoutsu_suu; } //============================================================================ //完全シュンツを抜き出して個数を返す関数 //============================================================================ function kanzenShuntsuCheck(){ var kanzenshuntsu_suu=0; var i; //123,456のような完全に独立したシュンツを抜き出すための処理 ////【注意】番地0,10,20,30が「0」の必要あり。事前に赤ドラを移動させる処理をしておく。 for(i=0;i<30;i+=10){//マンズ→ピンズ→ソーズ //123▲▲ if(tempTehai[i+1]==2&&tempTehai[i+2]==2&&tempTehai[i+3]==2&&!tempTehai[i+4]&&!tempTehai[i+5]){ tempTehai[i+1]-=2; tempTehai[i+2]-=2; tempTehai[i+3]-=2; kanzenshuntsu_suu+=2; } //▲234▲▲ if(!tempTehai[i+1]&&tempTehai[i+2]==2&&tempTehai[i+3]==2&&tempTehai[i+4]==2&&!tempTehai[i+5]&&!tempTehai[i+6]){ tempTehai[i+2]-=2; tempTehai[i+3]-=2; tempTehai[i+4]-=2; kanzenshuntsu_suu+=2; } //▲▲345▲▲ if(!tempTehai[i+1]&&!tempTehai[i+2]&&tempTehai[i+3]==2&&tempTehai[i+4]==2&&tempTehai[i+5]==2&&!tempTehai[i+6]&&!tempTehai[i+7]){ tempTehai[i+3]-=2; tempTehai[i+4]-=2; tempTehai[i+5]-=2; kanzenshuntsu_suu+=2; } //▲▲456▲▲ if(!tempTehai[i+2]&&!tempTehai[i+3]&&tempTehai[i+4]==2&&tempTehai[i+5]==2&&tempTehai[i+6]==2&&!tempTehai[i+7]&&!tempTehai[i+8]){ tempTehai[i+4]-=2; tempTehai[i+5]-=2; tempTehai[i+6]-=2; kanzenshuntsu_suu+=2; } //▲▲567▲▲ if(!tempTehai[i+3]&&!tempTehai[i+4]&&tempTehai[i+5]==2&&tempTehai[i+6]==2&&tempTehai[i+7]==2&&!tempTehai[i+8]&&!tempTehai[i+9]){ tempTehai[i+5]-=2; tempTehai[i+6]-=2; tempTehai[i+7]-=2; kanzenshuntsu_suu+=2; } //▲▲678▲ if(!tempTehai[i+4]&&!tempTehai[i+5]&&tempTehai[i+6]==2&&tempTehai[i+7]==2&&tempTehai[i+8]==2&&!tempTehai[i+9]){ tempTehai[i+6]-=2; tempTehai[i+7]-=2; tempTehai[i+8]-=2; kanzenshuntsu_suu+=2; } //▲▲789 if(!tempTehai[i+5]&&!tempTehai[i+6]&&tempTehai[i+7]==2&&tempTehai[i+8]==2&&tempTehai[i+9]==2){ tempTehai[i+7]-=2; tempTehai[i+8]-=2; tempTehai[i+9]-=2; kanzenshuntsu_suu+=2; } } for(i=0;i<30;i+=10){//マンズ→ピンズ→ソーズ //123▲▲ if(tempTehai[i+1]==1&&tempTehai[i+2]==1&&tempTehai[i+3]==1&&!tempTehai[i+4]&&!tempTehai[i+5]){ tempTehai[i+1]--; tempTehai[i+2]--; tempTehai[i+3]--; kanzenshuntsu_suu++; } //▲234▲▲ if(!tempTehai[i+1]&&tempTehai[i+2]==1&&tempTehai[i+3]==1&&tempTehai[i+4]==1&&!tempTehai[i+5]&&!tempTehai[i+6]){ tempTehai[i+2]--; tempTehai[i+3]--; tempTehai[i+4]--; kanzenshuntsu_suu++; } //▲▲345▲▲ if(!tempTehai[i+1]&&!tempTehai[i+2]&&tempTehai[i+3]==1&&tempTehai[i+4]==1&&tempTehai[i+5]==1&&!tempTehai[i+6]&&!tempTehai[i+7]){ tempTehai[i+3]--; tempTehai[i+4]--; tempTehai[i+5]--; kanzenshuntsu_suu++; } //▲▲456▲▲ if(!tempTehai[i+2]&&!tempTehai[i+3]&&tempTehai[i+4]==1&&tempTehai[i+5]==1&&tempTehai[i+6]==1&&!tempTehai[i+7]&&!tempTehai[i+8]){ tempTehai[i+4]--; tempTehai[i+5]--; tempTehai[i+6]--; kanzenshuntsu_suu++; } //▲▲567▲▲ if(!tempTehai[i+3]&&!tempTehai[i+4]&&tempTehai[i+5]==1&&tempTehai[i+6]==1&&tempTehai[i+7]==1&&!tempTehai[i+8]&&!tempTehai[i+9]){ tempTehai[i+5]--; tempTehai[i+6]--; tempTehai[i+7]--; kanzenshuntsu_suu++; } //▲▲678▲ if(!tempTehai[i+4]&&!tempTehai[i+5]&&tempTehai[i+6]==1&&tempTehai[i+7]==1&&tempTehai[i+8]==1&&!tempTehai[i+9]){ tempTehai[i+6]--; tempTehai[i+7]--; tempTehai[i+8]--; kanzenshuntsu_suu++; } //▲▲789 if(!tempTehai[i+5]&&!tempTehai[i+6]&&tempTehai[i+7]==1&&tempTehai[i+8]==1&&tempTehai[i+9]==1){ tempTehai[i+7]--; tempTehai[i+8]--; tempTehai[i+9]--; kanzenshuntsu_suu++; } } return kanzenshuntsu_suu; } //============================================================================ //完全孤立牌を抜き出して個数を返す関数 //============================================================================ function KanzenKoritsuCheck(){ var KanzenKoritsu_suu=0; var i,j; //字牌の完全孤立牌を抜き出す for(i=31;i<38;i++){ if(tempTehai[i]==1){ tempTehai[i]--; KanzenKoritsu_suu++; } } //数牌の完全孤立牌を抜き出す for(i=0;i<30;i+=10){//マンズ→ピンズ→ソーズ //1の孤立牌を抜く if(tempTehai[i+1]==1&&!tempTehai[i+2]&&!tempTehai[i+3]){ tempTehai[i+1]--; KanzenKoritsu_suu++; } //2の完全孤立牌を抜く if(!tempTehai[i+1]&&tempTehai[i+2]==1&&!tempTehai[i+3]&&!tempTehai[i+4]){ tempTehai[i+2]--; KanzenKoritsu_suu++; } //3~7の完全孤立牌を抜く for(j=0;j<5;j++){ if(!tempTehai[i+j+1]&&!tempTehai[i+j+2]&&tempTehai[i+j+3]==1&&!tempTehai[i+j+4]&&!tempTehai[i+j+5]){ tempTehai[i+j+3]--; KanzenKoritsu_suu++; } } //8の完全孤立牌を抜く if(!tempTehai[i+6]&&!tempTehai[i+7]&&tempTehai[i+8]==1&&!tempTehai[i+9]){ tempTehai[i+8]--; KanzenKoritsu_suu++; } //9の完全孤立牌を抜く if(!tempTehai[i+7]&&!tempTehai[i+8]&&tempTehai[i+9]==1){ tempTehai[i+9]--; KanzenKoritsu_suu++; } } return KanzenKoritsu_suu; } //============================================================================ //抜き出した牌とシャンテン数を出力させる処理【動作チェック用】 //============================================================================ $("#SyantenCheckBtn").click(function() { $("#paiTehaiSyantenCheck").empty(); moveReddora();//赤ドラを配列内で移動させる var syanten_suu = syantenCheck();//syantenCheck()の動作テスト用関数 $("#paiTehaiSyanten").empty().append("シャンテン数 = " + syanten_suu); }); //============================================================================ //元になる牌山を生成する関数 function makePaiYama(){ var i; for(i=0;i<136;i++){ yama[i] = paiYama[i].paiNo; } } //============================================================================ //牌山をシャッフルする関数【Mersenne Twister in JavaScriptを利用】 function shufflePaiYama(){ var mt = new MersenneTwister();//MersenneTwister オブジェクトの初期化 var i,j,k; for(i=135;i>0;i--){ j = mt.nextInt(0, 135); // 0 以上 135 未満の乱数(整数)を発生させる k = yama[i];//変数kに退避 yama[i] = yama[j];//乱数で発生した番地の牌を代入する yama[j] = k;//変数Kから戻す } } //============================================================================ //牌山から手牌配列に格納する関数 function inputTehaiStore(){ 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 i; for(i=0;i<13;i++){ tehai[yama[i]] ++; } } //============================================================================ //配牌を取って牌画で表示する //============================================================================ $("#PaiSetBtn").click(function() { red5manCount = 0;//赤5マンの数 red5pinCount = 0;//赤5ピンの数 red5souCount = 0;//赤5ソウの数 $("#paiTehaiAllSyantenCheck").empty(); makePaiYama();//牌山を生成する関数を呼び出す shufflePaiYama();//牌山をシャッフルする関数を呼び出す inputTehaiStore();//手牌を配列(tehai)に格納する関数を呼び出す checkReddora();///赤ドラの有無をチェックする関数を呼び出す //手牌表示処理 (function (){ var paiTepai = $("#paiTehaiSort2");//要素をキャッシュする var i,k,kazu; var paiga=""; paiTepai.empty(); for(i=1;i<38;i++){ if(i%10===0){continue;} //赤五萬の位置を修正する if(i==5 && red5manCount==1){ //tehai[5]-=1; paiga = "<span class=\"" + paiType[0].cssSprite + "\"></span>";//cssスプライトの牌画を配置 paiTepai.append(paiga); } //赤五筒の位置を修正する if(i==15 && red5pinCount==1){ //tehai[15]-=1; paiga = "<span class=\"" + paiType[10].cssSprite + "\"></span>";//cssスプライトの牌画を配置 paiTepai.append(paiga); } //赤五索の位置を修正する if(i==25 && red5souCount==1){ //tehai[25]-=1; paiga = "<span class=\"" + paiType[20].cssSprite + "\"></span>";//cssスプライトの牌画を配置 paiTepai.append(paiga); } //通常の手牌表示処理 if(tehai[i]){ kazu = tehai[i]; for(k=0;k<kazu;k++){ paiga = "<span class=\"" + paiType[i].cssSprite + "\"></span>";//cssスプライトの牌画を配置 paiTepai.append(paiga); } } } })();//手牌表示処理-終了 //牌の数を表示する (function (){ var PaiCount = 0; //入力された牌の枚数 for(var i=0;i<38;i++){ PaiCount += tehai[i]; } $("#paikazu").empty().append(PaiCount); })(); }); //============================================================================ //シャンテン数を表示する //============================================================================ $("#SyantenCheckBtn").click(function() { var msg; red5manCount = 0;//赤5マンの数 red5pinCount = 0;//赤5ピンの数 red5souCount = 0;//赤5ソウの数 checkReddora();//赤ドラチェックして配列を操作する関数を呼び出す moveReddora();//赤ドラを移動させる操作する関数を呼び出す var syanten_suu = allsyantenCheck();//シャンテン数を算出する if(!syanten_suu){ msg = "テンパイです"; }else{ msg = syantenCheck() + "シャンテン<br>"; msg += "【通常手のシャンテン数】" + syantenCheck(13) + "シャンテン<br>"; msg += "【チートイツのシャンテン数】" + syanten_7toitsu() + "シャンテン"; } $("#paiTehaiAllSyantenCheck").empty().append(msg); }); //============================================================================ //アガリとシャンテン数を返す関数 //============================================================================ function allsyantenCheck(){ var syanten_suu; var syanten_temp = 0; var syantenkokusi = syanten_kokusi();//国士無双のシャンテン数を算出する関数の呼び出し if(!syantenkokusi||syantenkokusi==-1){ return syantenkokusi; } var syanten7toitsu = syanten_7toitsu();//チートイツのシャンテン数を算出する関数の呼び出し if(!syanten7toitsu||syanten7toitsu==-1){ return syanten7toitsu; } syanten_suu = syantenCheck(13);//通常手のシャンテン数を算出する関数の呼び出し if(!syanten_suu||syanten_suu==-1){ return syanten_suu; } return Math.min(syantenkokusi,syanten7toitsu,syanten_suu); } //============================================================================
+ program_012.cssを開く
@charset "utf-8"; #paiTehai > span , #paiTehaiSort2 > span{ background-color:transparent; background-image:url(../images/pai.png); background-repeat:no-repeat; background-attachment:scroll; display:inline-block; } .man1{background-position:0px 0px;height:47px;width:31px;} .man2{background-position:-31px 0px;height:47px;width:31px;} .man3{background-position:-62px 0px;height:47px;width:31px;} .man4{background-position:-93px 0px;height:47px;width:31px;} .man5{background-position:-124px 0px;height:47px;width:31px;} .man6{background-position:-155px 0px;height:47px;width:31px;} .man7{background-position:-186px 0px;height:47px;width:31px;} .man8{background-position:-217px 0px;height:47px;width:31px;} .man9{background-position:-248px 0px;height:47px;width:31px;} .man0{background-position:-279px 0px;height:47px;width:31px;} .pin1{background-position:0px -47px;height:47px;width:31px;} .pin2{background-position:-31px -47px;height:47px;width:31px;} .pin3{background-position:-62px -47px;height:47px;width:31px;} .pin4{background-position:-93px -47px;height:47px;width:31px;} .pin5{background-position:-124px -47px;height:47px;width:31px;} .pin6{background-position:-155px -47px;height:47px;width:31px;} .pin7{background-position:-186px -47px;height:47px;width:31px;} .pin8{background-position:-217px -47px;height:47px;width:31px;} .pin9{background-position:-248px -47px;height:47px;width:31px;} .pin0{background-position:-279px -47px;height:47px;width:31px;} .sou1{background-position:0px -94px;height:47px;width:31px;} .sou2{background-position:-31px -94px;height:47px;width:31px;} .sou3{background-position:-62px -94px;height:47px;width:31px;} .sou4{background-position:-93px -94px;height:47px;width:31px;} .sou5{background-position:-124px -94px;height:47px;width:31px;} .sou6{background-position:-155px -94px;height:47px;width:31px;} .sou7{background-position:-186px -94px;height:47px;width:31px;} .sou8{background-position:-217px -94px;height:47px;width:31px;} .sou9{background-position:-248px -94px;height:47px;width:31px;} .sou0{background-position:-279px -94px;height:47px;width:31px;} .ji1{background-position:0px -141px;height:47px;width:31px;} .ji2{background-position:-31px -141px;height:47px;width:31px;} .ji3{background-position:-62px -141px;height:47px;width:31px;} .ji4{background-position:-93px -141px;height:47px;width:31px;} .ji5{background-position:-124px -141px;height:47px;width:31px;} .ji6{background-position:-155px -141px;height:47px;width:31px;} .ji7{background-position:-186px -141px;height:47px;width:31px;} .ji0{background-position:-217px -141px;height:47px;width:31px;} @media (max-width: 960px) { #paiTehai > span , #paiTehaiSort2 > span{ background-color:transparent; background-image:url(../images/pai4.png); background-repeat:no-repeat; background-attachment:scroll; display:inline-block; } .man1{background-position:0px 0px;height:31px;width:23px;} .man2{background-position:-23px 0px;height:31px;width:23px;} .man3{background-position:-46px 0px;height:31px;width:23px;} .man4{background-position:-69px 0px;height:31px;width:23px;} .man5{background-position:-92px 0px;height:31px;width:23px;} .man6{background-position:-115px 0px;height:31px;width:23px;} .man7{background-position:-138px 0px;height:31px;width:23px;} .man8{background-position:-161px 0px;height:31px;width:23px;} .man9{background-position:-184px 0px;height:31px;width:23px;} .man0{background-position:-207px 0px;height:31px;width:23px;} .pin1{background-position:0px -31px;height:31px;width:23px;} .pin2{background-position:-23px -31px;height:31px;width:23px;} .pin3{background-position:-46px -31px;height:31px;width:23px;} .pin4{background-position:-69px -31px;height:31px;width:23px;} .pin5{background-position:-92px -31px;height:31px;width:23px;} .pin6{background-position:-115px -31px;height:31px;width:23px;} .pin7{background-position:-138px -31px;height:31px;width:23px;} .pin8{background-position:-161px -31px;height:31px;width:23px;} .pin9{background-position:-184px -31px;height:31px;width:23px;} .pin0{background-position:-207px -31px;height:31px;width:23px;} .sou1{background-position:0px -62px;height:31px;width:23px;} .sou2{background-position:-23px -62px;height:31px;width:23px;} .sou3{background-position:-46px -62px;height:31px;width:23px;} .sou4{background-position:-69px -62px;height:31px;width:23px;} .sou5{background-position:-92px -62px;height:31px;width:23px;} .sou6{background-position:-115px -62px;height:31px;width:23px;} .sou7{background-position:-138px -62px;height:31px;width:23px;} .sou8{background-position:-161px -62px;height:31px;width:23px;} .sou9{background-position:-184px -62px;height:31px;width:23px;} .sou0{background-position:-207px -62px;height:31px;width:23px;} .ji1{background-position:0px -93px;height:31px;width:23px;} .ji2{background-position:-23px -93px;height:31px;width:23px;} .ji3{background-position:-46px -93px;height:31px;width:23px;} .ji4{background-position:-69px -93px;height:31px;width:23px;} .ji5{background-position:-92px -93px;height:31px;width:23px;} .ji6{background-position:-115px -93px;height:31px;width:23px;} .ji7{background-position:-138px -93px;height:31px;width:23px;} .ji0{background-position:-161px -93px;height:31px;width:23px;} } @media (max-width: 768px) { #paiTehai > span , #paiTehaiSort2 > span{ background-color:transparent; background-image:url(../images/pai3.png); background-repeat:no-repeat; background-attachment:scroll; display:inline-block; } .man1{background-position:0px 0px;height:26px;width:19px;} .man2{background-position:-19px 0px;height:26px;width:19px;} .man3{background-position:-38px 0px;height:26px;width:19px;} .man4{background-position:-57px 0px;height:26px;width:19px;} .man5{background-position:-76px 0px;height:26px;width:19px;} .man6{background-position:-95px 0px;height:26px;width:19px;} .man7{background-position:-114px 0px;height:26px;width:19px;} .man8{background-position:-133px 0px;height:26px;width:19px;} .man9{background-position:-152px 0px;height:26px;width:19px;} .man0{background-position:-171px 0px;height:26px;width:19px;} .pin1{background-position:0px -26px;height:26px;width:19px;} .pin2{background-position:-19px -26px;height:26px;width:19px;} .pin3{background-position:-38px -26px;height:26px;width:19px;} .pin4{background-position:-57px -26px;height:26px;width:19px;} .pin5{background-position:-76px -26px;height:26px;width:19px;} .pin6{background-position:-95px -26px;height:26px;width:19px;} .pin7{background-position:-114px -26px;height:26px;width:19px;} .pin8{background-position:-133px -26px;height:26px;width:19px;} .pin9{background-position:-152px -26px;height:26px;width:19px;} .pin0{background-position:-171px -26px;height:26px;width:19px;} .sou1{background-position:0px -52px;height:26px;width:19px;} .sou2{background-position:-19px -52px;height:26px;width:19px;} .sou3{background-position:-38px -52px;height:26px;width:19px;} .sou4{background-position:-57px -52px;height:26px;width:19px;} .sou5{background-position:-76px -52px;height:26px;width:19px;} .sou6{background-position:-95px -52px;height:26px;width:19px;} .sou7{background-position:-114px -52px;height:26px;width:19px;} .sou8{background-position:-133px -52px;height:26px;width:19px;} .sou9{background-position:-152px -52px;height:26px;width:19px;} .sou0{background-position:-171px -52px;height:26px;width:19px;} .ji1{background-position:0px -78px;height:26px;width:19px;} .ji2{background-position:-19px -78px;height:26px;width:19px;} .ji3{background-position:-38px -78px;height:26px;width:19px;} .ji4{background-position:-57px -78px;height:26px;width:19px;} .ji5{background-position:-76px -78px;height:26px;width:19px;} .ji6{background-position:-95px -78px;height:26px;width:19px;} .ji7{background-position:-114px -78px;height:26px;width:19px;} .ji0{background-position:-133px -78px;height:26px;width:19px;} } #haiga{ background-color:#173B0B; padding:5px 15px 3px 15px; margin-bottom:5px; color:#fff; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;}
おすすめレンタルサーバー
エックスサーバー|高速・高機能レンタルサーバー
「オールSSDの快適ハイスペック環境」「国内管理、大容量バックボーン」「独自SSLが無料」「FastCGIなどの高速化機能」「最新のPHP7を実装」など、高機能・高コストパフォーマンスなレンタルサーバーです。※当サイトも「エックスサーバー」で運用しています。