ナンプレx-wing見つけ方支援プログラムのソースコード

ナンプレ解法 支援プログラムjavaに戻る

このソースコードは、2021年12月初旬のもので、最新版ではありません。プログラミング言語Javaで書かれています。

@charset "Shift_JIS";

//zerowrite(search)を使う /*定数定義*/BANbaseCOLOR = "#777777"; DISABLEDbgcolor="#ffffaa";/*黄色*/CROSSbg="#a8ffff";/*水色*/ function syokika(){ for (let i = 0; i < 10; i++){let b = document.getElementById( "b"+i );b.readOnly = true;}//1行目をreadOnlyにする for (let i = 0; i < 10; i++){let countid = document.getElementById( "count"+i );countid.disabled = true;}//2行目をdisabledにする for (let i = 11; i < 100; i++){if(i % 10 !=0){ let bii = document.getElementById( "b"+i ); bii.style.color = BANbaseCOLOR;}} } function zerowrite(search){if(search==0){return;} //縦に調べ、空きマスが1個なら、下に0をwrite(whereから呼ばれる) for(let Y=1; Y<10; Y++) {let whitecount=0;let first=0;let TY=0; for(let T=1; T<10; T++) {let bname = document.getElementById( "b"+T+Y ); let cc=bname.style.backgroundColor; if(cc=="white"){whitecount++;if(first==0){TY=T*10+Y;first=1;} } }//縦に調べる。 if(whitecount==1){let bname = document.getElementById( "dcheckC"+(TY % 10) );bname.value="↑"+search; } } //横に調べ、空きマスが1個なら、右に0をwrite for(let T=1; T<10; T++) {let whitecount=0;let first=0;let TY=0;//● for(let Y=1; Y<10; Y++)//●● {let bname = document.getElementById( "b"+T+Y ); let cc=bname.style.backgroundColor; if(cc=="white"){whitecount++;if(first==0){TY=T*10+Y;first=1;} } }//横に調●● if(whitecount==1){let bname = document.getElementById( "dcheckR"+(TY-(TY % 10))/10 );bname.value="←"+search; }//●●● } //ブロックを調べ、空きマスが1個なら、右下に0をwrite。Tはブロックグループ、Yはplusの添え字。完。 for (let T = 1; T < 10; T++){let plus=[0,-11,-10,-9,-1,0,+1,+9,+10,+11];let center=[0,22,25,28,52,55,58,82,85,88] let whitecount=0;let first=0;let TY=0;//● for(let Y=1; Y<10; Y++)//●● {let bname = document.getElementById( "b"+(center[T]+plus[Y]) ); let cc=bname.style.backgroundColor; if(cc=="white"){whitecount++;if(first==0){TY=center[T]+plus[Y];first=1;} } }//ブロックを調●● if(whitecount==1){let bnameR = document.getElementById( "dcheckR"+(TY-(TY % 10))/10 );bnameR.value="←"+search; let bnameC = document.getElementById( "dcheckC"+(TY % 10) );bnameC.value="↑"+search; }//●●● } } //=================盤クリア function cl(){ if (checkBox1.checked == true){candidateCLI.value="盤面は変更禁止";return;} for (let i = 11; i < 100; i++){if(i % 10 !=0){let bii = document.getElementById( "b"+i ); bii.value="";bii.disabled = false;bii.style.backgroundColor = "white";}} dcheck();fcount();} //=================盤→Text box。完成。 function bankara(){ var ttbox=""; for (let i = 11; i < 100; i++){if(i % 10 !=0){ let bii = document.getElementById( "b"+i ); if( bii.value != ""){ ttbox=ttbox+bii.value;} else { ttbox=ttbox+"0"; };ttbox=ttbox+",";}}document.ban.textarea.value=ttbox;} //=================Text box→盤。完成。 function banhe(){ let bname= checkBox1; if (bname.checked == true){candidateCLI.value="盤面は変更禁止";return;} var ttbox=document.ban.textarea.value; var ii=0; if(ttbox==""){return;} for (let i = 11; i < 100; i++){ if (i % 10 ==0) { ii=ii+2; } else {let bii = document.getElementById( "b"+i ); if (ttbox[(i-11)*2-ii]!=0) {bii.value=ttbox[(i-11)*2-ii]} else {bii.value="";} } } dcheck();fcount();checkBox1.checked = true;NoChange()} //=================カーソル位置クリアー=============================================NumberWritten.value:マスに入る数字 function cli(myobj){Possible(myobj);myobj.value=NumberWritten.value; fcount();dcheck();fnone();b1199.value=myobj.id; }//追加・変更 //-----クリックしたマスの候補を求めるcandidate。cli(myobj)からだけ呼ばれる。 function Possible(obj){let ii=parseInt(obj.id.substring(1)); let aryposs=[0,1,2,3,4,5,6,7,8,9];//●●●cliから呼ばれる。iiはクリックされたマスの座標(11〜99)変化しない。 for(let Y=1; Y<10; Y++){let T=(ii-(ii % 10))/10; let bTY = document.getElementById( "b"+T+Y );//●●TとYはクリックされたマスの縦と横。 for(let i=1; i<10; i++){if (aryposs[i]==bTY.value) {aryposs[i]=0} } }//● for(let T=1; T<10; T++){let Y=(ii % 10); let bTY = document.getElementById( "b"+T+Y ); for(let i=1; i<10; i++){if (aryposs[i]==bTY.value) {aryposs[i]=0} } }//● let plus=[0,1,2,10,11,12,20,21,22] for (let I = 0; I < 9; I++){let bnum=(Math.ceil((ii-(ii % 10))/30)*3-2)*10+(Math.ceil((ii % 10)/3)*3-2)+plus[I]; let bTY = document.getElementById( "b"+bnum ); for(let i=1; i<10; i++){if (aryposs[i]==bTY.value) {aryposs[i]=0} } }//● let strpossi="";for(let i=1; i<10; i++){if (aryposs[i]!=0) {strpossi=strpossi+aryposs[i]} } candidateCLI.value=strpossi+"だけ";return strpossi;} //-----candidateNSを求める function fnone(){one_position.value="";let aryposs=[0,1,2,3,4,5,6,7,8,9];//-----●●●cliからとwhereから呼ばれる for (let ii = 11; ii < 100; ii++){ if (ii % 10 !=0) { for(let Y=1; Y<10; Y++){let T=(ii-(ii % 10))/10; let bTY = document.getElementById( "b"+T+Y ); for(let i=1; i<10; i++){if (aryposs[i]==bTY.value) {aryposs[i]=0} } } for(let T=1; T<10; T++){let Y=(ii % 10); let bTY = document.getElementById( "b"+T+Y ); for(let i=1; i<10; i++){if (aryposs[i]==bTY.value) {aryposs[i]=0} } } let plus=[0,1,2,10,11,12,20,21,22] for (let I = 0; I < 9; I++){let bnum=(Math.ceil((ii-(ii % 10))/30)*3-2)*10+(Math.ceil((ii % 10)/3)*3-2)+plus[I]; let bTY = document.getElementById( "b"+bnum ); for(let i=1; i<10; i++){if (aryposs[i]==bTY.value) {aryposs[i]=0} } } let strpossi="";for(let a=1; a<10; a++){if (aryposs[a]!=0) {strpossi=strpossi+aryposs[a]} } candidateNS.value=""; let bname=document.getElementById( "b"+ii); if(strpossi.length==1 && bname.value==""){ one_position.value=ii; candidateNS.value=strpossi; aryposs=[0,1,2,3,4,5,6,7,8,9]; return;} aryposs=[0,1,2,3,4,5,6,7,8,9]; } } } //=================全角→半角 function han(obj){str=obj.value;UTF=obj.value.charCodeAt(0);if (UTF > 10000) { obj.value=String.fromCharCode(UTF-65248)};dcheck();} //=================変更禁止============================================= function NoChange(){ if(checkBox1.checked == false) { for (let i = 11; i < 100; i++){ if(i % 10 !=0){ let bname = document.getElementById( "b"+i );bname.disabled = false;bname.style.backgroundColor = "white";bname.style.color = BANbaseCOLOR;} } } else {/*変更禁止にする*/for (let i = 11; i < 100; i++) {if(i % 10 !=0) { let bname = document.getElementById( "b"+i ); if( bname.value != ""){bname.disabled = true; bname.style.backgroundColor = DISABLEDbgcolor; bname.style.color = "black";} else {bname.disabled = false; bname.style.backgroundColor = "white";bname.style.color = BANbaseCOLOR;} } } } } //----------重複チェック。バグ function dcheck(){ var iii=0; let dd=[-11,-10,-9,-1,0,+1,+9,+10,+11]; //-----行チェックR→T for (let T = 1; T < 10; T++){ for (let checki = 1; checki < 10; checki++){ let count=0; for (let Y = 1; Y < 10; Y++){let bname = document.getElementById( "b"+T+Y );if(bname.value==checki){count=count+1;}} if (count>1){let bname = document.getElementById( "dcheckR"+T );bname.value=checki+"D";break;} else {let bname = document.getElementById( "dcheckR"+T );bname.value="";} } } //-----列チェック for (let Y = 1; Y < 10; Y++){ for (let checki = 1; checki < 10; checki++){ let count=0; for (let T = 1; T < 10; T++){let bname = document.getElementById( "b"+T+Y );if(bname.value==checki){count=count+1;}} if (count>1){let bname = document.getElementById( "dcheckC"+Y );bname.value=checki+"D";break;}/*+"D"*/ else {let bname = document.getElementById( "dcheckC"+Y );bname.value="";} } } //-----ボックスチェック for (let BG = 1; BG < 10; BG++){let plus=[0,-11,-10,-9,-1,0,+1,+9,+10,+11];let center=[0,22,25,28,52,55,58,82,85,88] for (let checki = 1; checki < 10; checki++){ let count=0; for (let ii = 1; ii < 10; ii++){let bnum=center[BG]+plus[ii]; let bname = document.getElementById( "b"+bnum );if(bname.value==checki){count=count+1;}} if (count>1){bg.value=BG+"bx-"+checki;return;} else {bg.value="";} } } } //----------crosskesi alert();whereから呼ばれる。searchはボタンの数字(1〜9) function crosskesi(search){for(let i=1; i<10; i++){for(let ii=1; ii<10; ii++) { let bname = document.getElementById( "b"+i+ii );bname.style.color = "black"; if(bname.disabled == false){bname.style.backgroundColor = "white";} else {bname.style.backgroundColor = DISABLEDbgcolor;} } } } //----------1から9の個数のcount function fcount(){let Number=[0,0,0,0,0,0,0,0,0,0,0] for (let i = 0; i < 10; i++){ for (let ii = 11; ii < 100; ii++){if(ii % 10 !=0){let bname = document.getElementById( "b"+ii );num=parseInt(bname.value);if(num==i){ Number[i]=Number[i]+1;} }}}let sum=0; for (let i = 1; i < 10; i++){let bname = document.getElementById( "count"+i );bname.value= Number[i];sum=sum+Number[i];} let bname = document.getElementById( "count0" );bname.value=sum; } function clbotan(){if(b1199.value!=""){let masu = document.getElementById( b1199.value ); masu.value="";let saveNUM=NumberWritten.value;where(0);where(saveNUM);} b1199.value="";candidateCLI.value="";fcount(); for(let i=1; i<10; i++){let bname = document.getElementById("dcheckR"+i);bname.value=""; }bg.value=""; for(let i=1; i<10; i++){let bname = document.getElementById("dcheckC"+i);bname.value=""; }zerowrite(search); }//追加。 //=================searchはボタンの数字。crosskesiを呼んでbackgroundColorを白か黄色にした後、crossを呼んで水色。b1199.value function where(search){crosskesi(search);fcount();fnone();candidateCLI.value="";if (search!=0){NumberWritten.value=search;}else{NumberWritten.value="";fcount();}//追加NumberWritten.value:マスに入る数字 for(let i=0; i<10; i++){let bname = document.getElementById( "b"+i ); bname.style.color ="black"} //まず黒字にしておく let bname = document.getElementById( "b"+search );bname.style.color ="red";//(search)数字ボタンを赤にする。 for(let i=1; i<10; i++){let bname = document.getElementById("dcheckR"+i);bname.value=""; } for(let i=1; i<10; i++){let bname = document.getElementById("dcheckC"+i);bname.value=""; } for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i );{if(bname.value!=""){bname.style.backgroundColor = CROSSbg;}; if (bname.disabled == false){bname.style.color = BANbaseCOLOR} else {bname.style.color = "black"} } } } /*search!=0には意味がある*/ for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i ); if(bname.value==search && search!=0){bname.style.color = "red"; cross(i);} } }dcheck();fcount();zerowrite(search); } //レーザー発射法ボタン function laser(){where(0); for(iiii=1;iiii<10;iiii++){ for(let search=1; search<10; search++){//あ for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i ); if(bname.value==search){cross(i);}//●水色 } } numwrite(search);//白マスが1個なら、searchを記入 for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i ); if(bname.value==""){bname.style.backgroundColor = "white";}//白に戻す } } }//あ for(ii=11;ii<100;ii++){if(ii % 10 !=0){let bname = document.getElementById( "b"+ii ); if(bname.value !=""){bname.disabled = true;bname.style.backgroundColor = CROSSbg;} } }//◎ }where(0);fcount();/* 追加変更*/ } function mituke(TY){let bname = document.getElementById( "b"+TY );bname.value=search; bname.disabled = true; bname.style.backgroundColor = CROSSbg;} //------------------------------------------------------------------ function numwrite(search){//レーザー発射法ボタンから呼ばれる for(let Y=1; Y<10; Y++) {let whitecount=0;let first=0;let TY=0; for(let T=1; T<10; T++) {let bname = document.getElementById( "b"+T+Y ); let cc=bname.style.backgroundColor; if(cc=="white"){whitecount++;if(first==0){TY=T*10+Y;first=1;} } }//縦に調べる。 if(whitecount==1){let bname = document.getElementById( "b"+TY );bname.value=search; bname.disabled = true; bname.style.backgroundColor = CROSSbg;} }//△1 for(ii=11;ii<100;ii++){if(ii % 10 !=0){let bname = document.getElementById( "b"+ii ); if(bname.value !=""){bname.disabled = true;bname.style.backgroundColor = CROSSbg;} } }//◎2 //●●closs(i)をもう一度 for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i ); if(bname.value==search){cross(i);}// } }//●● for(let T=1; T<10; T++) {let whitecount=0;let first=0;let TY=0; for(let Y=1; Y<10; Y++) {let bname = document.getElementById( "b"+T+Y ); let cc=bname.style.backgroundColor; if(cc=="white"){whitecount++;if(first==0){TY=T*10+Y;first=1;} } }//横に調べる。 if(whitecount==1){let bname = document.getElementById( "b"+TY );bname.value=search; bname.disabled = true; bname.style.backgroundColor = CROSSbg;} }//△1 for(ii=11;ii<100;ii++){if(ii % 10 !=0){let bname = document.getElementById( "b"+ii ); if(bname.value !=""){bname.disabled = true;bname.style.backgroundColor = CROSSbg;} } }//◎2 //●●closs(i)をもう一度 for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i ); if(bname.value==search){cross(i);}// } }//●● let plus=[0,0,1,2,10,11,12,20,21,22]; let base=[0,11,14,17,41,44,47,71,74,77]; for (let I = 1; I < 10; I++) {let whitecount=0;let first=0;let TY=0; for(let II=1; II<10; II++) {let bnum=base[I]+plus[II];let bname = document.getElementById("b"+bnum); let cc=bname.style.backgroundColor;if(cc=="white"){whitecount++;if(first==0){TY=bnum;first=1;} } }//ブロック調べる。 if(whitecount==1){let bname = document.getElementById( "b"+TY );bname.value=search; bname.disabled = true; bname.style.backgroundColor = CROSSbg;} }//△1 for(ii=11;ii<100;ii++){if(ii % 10 !=0){let bname = document.getElementById( "b"+ii ); if(bname.value !=""){bname.disabled = true;bname.style.backgroundColor = CROSSbg;} } }//◎2 //●●closs(i)をもう一度 for (let i = 11; i < 100; i++){ if(i % 10 !=0){let bname = document.getElementById( "b"+i ); if(bname.value==search){cross(i);}// } }//●● } //----------whereから呼ばれて、biiから縦横にbackgroundColor = CROSSbg水色(bname.value==searchの時のbii)/*cross(bii)のbiiは11から99*/ function cross(bii){ for(let Y=1; Y<10; Y++){let T=(bii-(bii % 10))/10; let bname = document.getElementById( "b"+T+Y ); bname.style.backgroundColor = CROSSbg;}/*水色*/ for(let T=1; T<10; T++){let Y=(bii % 10); let bname = document.getElementById( "b"+T+Y ); bname.style.backgroundColor = CROSSbg;}/*水色*/ let plus=[0,1,2,10,11,12,20,21,22] for (let I = 0; I < 9; I++){/*bnumは11から99*/let bnum=(Math.ceil((bii-(bii % 10))/30)*3-2)*10+(Math.ceil((bii % 10)/3)*3-2)+plus[I]; let bname = document.getElementById( "b"+bnum );bname.style.backgroundColor = CROSSbg;}/*水色*/ } //----------盤b→メモリmem 不要か? //function bm(){ let m = new Array() ;mem[0]=0; //for (let i = 11; i < 100; i++) { let bname = document.getElementById( "b"+i ); if( bname.value != ""){ mem[i]=bname.value;} else { mem[i]=0; }; } } //================= function numdisp(){let loadnumid = document.getElementById("loadnum");str=loadnum; UTF=str.value.charCodeAt(0); UTF2=str.value.charCodeAt(1);//getElementByIdを削除。bbname.value="";→one.value=""; if (UTF > 10000 && UTF2!=NaN) { loadnumid.value=String.fromCharCode(UTF-65248)}; if (UTF > 10000 && UTF2> 10000) { loadnumid.value=String.fromCharCode(UTF-65248)+String.fromCharCode(UTF2-65248)}; num=loadnumid.value; switch (num){ case "1":obj = document.getElementById("mes");obj.value="Locked Candidates完"; break;//完。getElementByIdを削除。bbname.value="";→one.value=""; case "2":obj = document.getElementById("mes");obj.value="Naked Single完"; break;//完 case "3":obj = document.getElementById("mes");obj.value="Naked Singleを使用完"; break;//完 case "4":obj = document.getElementById("mes");obj.value="ステルスレーザー発射法"; break; case "5":obj = document.getElementById("mes");obj.value="星3 1127 単純作業だけで完。"; break;//完 case "6":obj = document.getElementById("mes");obj.value="星4 1203 Naked Singleを使用完"; break;//完 case "7":obj = document.getElementById("mes");obj.value="星5 1120 23マス"; break; case "8":obj = document.getElementById("mes");obj.value="星5 1120 単純作業終わり29マス"; break; case "9":obj = document.getElementById("mes");obj.value="星5 1205 25マス"; break; case "10":obj = document.getElementById("mes");obj.value="星5 1205 単純作業終わり27マス"; break; case "11":obj = document.getElementById("mes");obj.value="星4 1204Locked Candidatesだけで完"; break;//完 default:obj = document.getElementById("mes");obj.value="";}} //================= function load (){let bname = document.getElementById("loadnum"); num=bname.value; obj = document.getElementById("textarea"); switch (num){ case "1":obj.value="0,0,6,0,7,0,0,0,5,1,0,0,0,5,0,0,3,0,9,5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,0,3,0,0,6,0,0,8,7,0,0,0,0,0,0,1,0,0,0,0, 0,4,0,9,0,0,0,0,2,1,0,0,0,3,0,8,0,0,0,6,0,0,0,7,0,9,0,0,0,5,2,0, 0,0,0,1,0,2,0,0,0,0,0,4,0,0,0,0,0,0,2,5,0,0,7,0,0,4,0,0,"; break; case "8":obj.value="0,0,3,0,1,6,0,0,8,7,0,0,0,0,0,0,1,0,0,0,0, 0,4,7,9,0,0,0,7,2,1,0,0,0,3,0,8,0,0,0,6,0,0,0,7,0,9,0,0,7,5,2,0, 0,0,0,1,0,2,0,0,0,0,0,4,7,0,0,0,0,0,2,5,2,0,7,0,0,4,0,0,"; break; case "9":obj.value="0,3,0,0,0,1,6,0,0,9,0,0,0,2,0,0,3,0,0,0,8, 0,0,0,0,0,7,0,7,0,2,0,0,0,0,3,0,0,5,0,9,0,8,0,0,1,0,0,0,0,5,0,9, 0,6,0,0,0,0,0,5,0,0,0,9,0,0,7,0,0,0,4,0,0,4,8,0,0,0,2,0,"; break; case "10":obj.value="0,3,0,0,0,1,6,0,0,9,0,0,0,2,0,0,3,0,0,0,8, 0,0,0,0,0,7,0,7,9,2,0,0,0,5,3,0,0,5,0,9,0,8,0,0,1,0,0,0,0,5,0,9, 0,6,0,0,0,0,0,5,0,0,0,9,0,0,7,0,0,0,4,0,0,4,8,0,0,0,2,0,"; break; case "11":obj.value="0,7,0,4,0,0,0,5,0,0,0,0,0,2,0,1,0,0,8,0,0, 0,0,9,0,0,6,0,0,2,6,0,0,0,0,8,0,9,0,0,0,0,0,7,0,3,0,0,0,0,4,5,0, 0,6,0,0,1,0,0,0,0,2,0,0,5,0,7,0,0,0,0,0,3,0,0,0,8,0,9,0,"; break; default:obj = document.getElementById("mes");obj.value="";}}

最後まで読んでいただいて、ありがとうございました。