From 05d905b9170b20c434bb89c818c89b9be546b061 Mon Sep 17 00:00:00 2001 From: CmdBlock Date: Tue, 26 Sep 2023 19:28:44 +0800 Subject: [PATCH] add block 10 11 --- calc.js | 42 +++++++++++++++++++++++++++++++++++++----- calc.min.js | 2 +- index.html | 4 ++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/calc.js b/calc.js index 01973a5..dd61a6c 100644 --- a/calc.js +++ b/calc.js @@ -109,6 +109,33 @@ const blocks = [ [ [9] ] + ], + [ + [ + [10, 10] + ], + [ + [10], + [10] + ] + ], + [ + [ + [11, 11], + [11, 0], + ], + [ + [11, 11], + [0, 11], + ], + [ + [0, 11], + [11, 11], + ], + [ + [11, 0], + [11, 11], + ], ] ]; @@ -164,23 +191,28 @@ function dfs(p) { x[i] = a[i].map(x => x); } res.push(x); - return; + if (res.length >= 10000) { + alert('方案数太多,仅计算前一万种。减少一些方块吧~'); + return true; + } + return false; } const x = Math.floor(p / n), y = p % n; if (a[x][y] !== -1) { - dfs(p + 1); - return; + if (dfs(p + 1)) return true; + return false; } - for (let b = 0; b < 9; ++b) { + for (let b = 0; b < blocks.length; ++b) { if (!l[b]) continue; for (let d = 0; d < blocks[b].length; ++d) { if (!canPlaceBlock(x, y, b, d)) continue; placeBlock(x, y, b, d, b + 1); --l[b]; - dfs(p + 1); + if (dfs(p + 1)) return true; ++l[b]; placeBlock(x, y, b, d, -1); } } + return false; } diff --git a/calc.min.js b/calc.min.js index fe61dde..c355405 100644 --- a/calc.min.js +++ b/calc.min.js @@ -1 +1 @@ -const blocks=[[[[1,1],[1,1]]],[[[2,2,2,2]],[[2],[2],[2],[2]]],[[[3,3,0],[0,3,3]],[[0,3],[3,3],[3,0]]],[[[0,4,4],[4,4,0]],[[4,0],[4,4],[0,4]]],[[[5,0,0],[5,5,5]],[[5,5],[5,0],[5,0]],[[5,5,5],[0,0,5]],[[0,5],[0,5],[5,5]]],[[[0,0,6],[6,6,6]],[[6,6],[0,6],[0,6]],[[6,6,6],[6,0,0]],[[6,0],[6,0],[6,6]]],[[[0,7,0],[7,7,7]],[[7,7,7],[0,7,0]],[[7,0],[7,7],[7,0]],[[0,7],[7,7],[0,7]]],[[[0,8,0],[8,8,8],[0,8,0]]],[[[9]]]];let m,n,a,l,res;function Solve(arr,num){res=[];m=arr.length;n=arr[0].length;a=new Array(m);for(let i=0;ix)}l=num.map(x=>x);dfs(0);return res}function canPlaceBlock(x,y,b,d){const pat=blocks[b][d];let offset=0;while(!pat[0][offset])++offset;y-=offset;if(y<0)return false;for(let i=0;i=m||y+j>=n||a[x+i][y+j]!==-1))return false}}return true}function placeBlock(x,y,b,d,v){const pat=blocks[b][d];let offset=0;while(!pat[0][offset])++offset;y-=offset;for(let i=0;ix)}res.push(x);return}const x=Math.floor(p/n),y=p%n;if(a[x][y]!==-1){dfs(p+1);return}for(let b=0;b<9;++b){if(!l[b])continue;for(let d=0;d=m||e+i>=n||-1!==a[r+c][e+i]))return!1;return!0}function placeBlock(r,n,e,o,l){for(var t=blocks[e][o],f=0;!t[0][f];)++f;n-=f;for(var c=0;c=1e4&&(alert("方案数太多,仅计算前一万种。减少一些方块吧~"),!0)}var t=Math.floor(r/n),f=r%n;if(-1!==a[t][f])return!!dfs(r+1);for(var c=0;c