PageSourceSearch

https://labuladong.online/_next/static/chunks/15331.f98d8eeed75e743b.js

js labuladong.online collected 2026-10-01 12:22:03 UTC 9,450 bytes, 39 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[15331,85251,99431],{15331:(e,r,t)=>{t.r(r),t.d(r,{useCodeExecution:()=>i});var o=t(12115),n=t(85251),l=t(99431),a=t(52604);function i(e){let{communicationManager:r,getState:t,actions:i}=e,s=(0,o.useRef)(null),u=(0,o.useRef)("solver"),C=(0,o.useCallback)(e=>{try{r?.sendLog("接收到用户代码,准备执行","info"),i.clearAllProbabilities();let o=`
2				const console = this.customConsole;
3				return function(gameController) {
4					try {
5						${e.code}
6						if (typeof autoSweeper === 'function') {
7							autoSweeper(gameController);
8						} else {
9							console.error("未找到 autoSweeper 函数");
10						}
11					} catch (error) {
12						console.error("执行代码出错: " + error.message);
13					}
14				}
15			`,s={customConsole:a.Ay.createCustomConsole(console,r,!1)},u=Function(o).call(s),C=t(),d=C.boardData.map(e=>[...e]),c=C.flagCount,f=C.openedCellCount,g=C.gameStatus;u({getVisibleBoard:()=>(r?.sendLog("获取游戏板状态","info"),d.map(e=>e.map(e=>e===n.CellCode.OPENED?10:e>=n.CellCode.OPENED?10+e:e===n.CellCode.FLAG?1:2*(e===n.CellCode.QUESTION)))),openCell:(e,t)=>{if(r?.sendLog(`打开单元格 (${e}, ${t})`,"info"),e>=0&&e<C.height&&t>=0&&t<C.width&&g!==n.GameStatus.LOSE&&g!==n.GameStatus.WIN){let r=d[e][t];if(r>=n.CellCode.OPENED||r===n.CellCode.FLAG||r===n.CellCode.QUESTION||r===n.CellCode.MINE_FLAG||r===n.CellCode.MINE_QUESTION)return!1;if(r===n.CellCode.MINE)return g=n.GameStatus.LOSE,!0;let o=(0,l.expandOpenedCell)(d,t,e);return f+=o.openedCellCount,C.width*C.height-C.mineCount===f&&(g=n.GameStatus.WIN),!0}return!1},flagCell:(e,t)=>{if(r?.sendLog(`标记单元格 (${e}, ${t})`,"info"),e>=0&&e<C.height&&t>=0&&t<C.width&&g!==n.GameStatus.LOSE&&g!==n.GameStatus.WIN){let r=d[e][t];return!(r>=n.CellCode.OPENED)&&(d[e][t]=(0,l.getNextCellCode)(r),c+=(0,l.getFlagIncDec)(r),!0)}return!1},setProbability:(e,t,o)=>(r?.sendLog(`设置单元格 (${e}, ${t}) 的概率为 ${o}%`,"info"),o<0||o>100)?(r?.sendLog(`概率值必须在0-100之间`,"error"),!1):e>=0&&e<C.height&&t>=0&&t<C.width&&(i.setCellProbability(t,e,o),!0),getRemainingMinesCount:()=>{let e=C.mineCount-c;return r?.sendLog(`剩余地雷数:${e}`,"info"),e}});let N=g;return N===n.GameStatus.READY&&(f>C.openedCellCount||c!==C.flagCount)&&(N=n.GameStatus.RUN),i.syncSolverState(d,c,f,N),!0}catch(t){let e=t instanceof Error?t.message:String(t);return r?.sendLog(`执行代码出错: ${e}`,"error"),!1}},[r,t,i]),d=(0,o.useCallback)(e=>{try{r?.sendLog("接收到用户地图生成代码,准备执行","info");let o=`
16				const console = this.customConsole;
17				return function(width, height, mineCount) {
18					try {
19						${e.code}
20						if (typeof generate === 'function') {
21							return generate(width, height, mineCount);
22						} else {
23							console.error("未找到 generate 函数");
24						}
25					} catch (error) {
26						console.error("执行地图生成代码出错: " + error.message);
27						return null;
28					}
29				}
30			`,l={customConsole:a.Ay.createCustomConsole(console,r,!1)},s=Function(o).call(l),{width:u,height:C,mineCount:d}=t(),c=s(u,C,d),f=Array(C).fill(0).map(()=>Array(u).fill(n.CellCode.NOTHING));if(!c||!Array.isArray(c))return r?.sendLog("返回值无效,应该是坐标数组","error"),i.initializeGame(f),!1;if(c.length!==d)return r?.sendLog(`地雷数量不正确,要求${d}个,实际${c.length}个`,"error"),i.initializeGame(f),!1;let g=new Set;for(let e=0;e<c.length;e++){let t=c[e];if(!Array.isArray(t)||2!==t.length)return r?.sendLog(`第${e+1}个坐标格式错误,应为[x,y]`,"error"),i.initializeGame(f),!1;let[o,n]=t;if("number"!=typeof o||"number"!=typeof n)return r?.sendLog(`第${e+1}个坐标[${o},${n}]包含非数字值`,"error"),i.initializeGame(f),!1;if(o<0||o>=u||n<0||n>=C)return r?.sendLog(`第${e+1}个坐标[${o},${n}]超出范围`,"error"),i.initializeGame(f),!1;let l=`${o},${n}`;if(g.has(l))return r?.sendLog(`第${e+1}个坐标[${o},${n}]重复`,"error"),i.initializeGame(f),!1;g.add(l)}for(let[e,r]of c)f[r][e]=n.CellCode.MINE;return i.initializeGame(f),r?.sendLog("使用用户算法成功生成地图","info"),!0}catch(a){let e=a instanceof Error?a.message:String(a);r?.sendLog(`执行地图生成代码出错: ${e}`,"error");let o=t(),l=Array(o.height).fill(0).map(()=>Array(o.width).fill(n.CellCode.NOTHING));return i.initializeGame(l),!1}},[r,t,i]),c=(0,o.useCallback)(e=>{try{return r?.sendLog("接收到用户代码,已保存","info"),i.setUserCode(e.code),s.current=e.code,!0}catch(t){let e=t instanceof Error?t.message:String(t);return r?.sendLog(`保存代码出错: ${e}`,"error"),!1}},[r,i]),f=(0,o.useCallback)((e,o)=>{if("click"!==u.current)return!0;
30if(!s.current)return r?.sendLog("请先提交代码","error"),!1;if(!r)return!1;try{let u=`
31				const console = this.customConsole;
32				return function(board, i, j) {
33					try {
34						(${s.current})(board, i, j);
35					} catch (error) {
36						console.error("执行代码出错: " + error.message);
37					}
38				}
39			`,C={customConsole:a.Ay.createCustomConsole(console,r,!0)},d=Function(u).call(C),c=t(),f=c.boardData.map(e=>[...e]),g=c.boardData.map(e=>[...e]);r.sendInfoLog(`点击单元格 (${o}, ${e})`);let N=c.boardData.map(e=>[...e]);if(N[o][e]===n.CellCode.MINE){i.initializeGame(N),i.setGameStatus(n.GameStatus.LOSE),r.sendErrorLog(`游戏结束!你点击了地雷!`);return}d(f,o,e),(0,l.expandStandard)(g,o,e);let E=!0,h=[],m=0;for(let e=0;e<f.length;e++)for(let r=0;r<f[e].length;r++)f[e][r]!==N[e][r]?(N[e][r]===n.CellCode.NOTHING&&f[e][r]>=0&&m++,f[e][r]!==g[e][r]&&(E=!1,g[e][r]>=0&&f[e][r]===N[e][r]?h.push(`单元格 (${e}, ${r}) 应该被打开并显示 ${g[e][r]}`):N[e][r]===n.CellCode.NOTHING&&f[e][r]>=0&&f[e][r]!==g[e][r]&&h.push(`单元格 (${e}, ${r}) 的值应为 ${g[e][r]},但得到 ${f[e][r]}`))):g[e][r]!==N[e][r]&&(E=!1,h.push(`单元格 (${e}, ${r}) 应该被打开`));m>0?(i.initializeGame(f),E)?r.sendSuccessLog(`恭喜!你的实现是正确的,成功打开了 ${m} 个单元格`):(r.sendWarningLog(`你的实现与标准不一致,打开了 ${m} 个单元格`),h.slice(0,3).forEach(e=>{r.sendWarningLog(e)}),h.length>3&&r.sendWarningLog(`还有 ${h.length-3} 个错误未显示...`)):r.sendWarningLog("警告:你的代码没有打开任何单元格,请检查逻辑")}catch(t){let e=t instanceof Error?t.message:String(t);r.sendErrorLog(`执行代码出错: ${e}`)}},[r,t,i]);return{userCodeRef:s,currentModeRef:u,handleAutoSweeper:C,handleGenerate:d,handleClick:c,executeUserClickExpand:f}}},52604:(e,r,t)=>{t.d(r,{Ay:()=>n});let o=e=>e.map(e=>{if(void 0===e)return"undefined";if(null===e)return"null";if("object"==typeof e)try{return JSON.stringify(e)}catch(e){}return String(e)}).join(" "),n={formatLogArgs:o,createCustomConsole:function(e,r){let t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return{log:function(){for(var n=arguments.length,l=Array(n),a=0;a<n;a++)l[a]=arguments[a];let i=o(l);t?r.sendInfoLog(i):r?.sendLog(i,"info"),e.log(...l)},error:function(){for(var n=arguments.length,l=Array(n),a=0;a<n;a++)l[a]=arguments[a];let i=o(l);t?r.sendErrorLog(i):r?.sendLog(i,"error"),e.error(...l)}}}}},85251:(e,r,t)=>{t.r(r),t.d(r,{CellCode:()=>o,GameStatus:()=>n});var o=function(e){return e[e.OPENED=0]="OPENED",e[e.NOTHING=-1]="NOTHING",e[e.FLAG=-2]="FLAG",e[e.QUESTION=-3]="QUESTION",e[e.MINE=-4]="MINE",e[e.MINE_FLAG=-5]="MINE_FLAG",e[e.MINE_QUESTION=-6]="MINE_QUESTION",e}({}),n=function(e){return e.READY="ready",e.RUN="run",e.WIN="win",e.LOSE="lose",e}({})},99431:(e,r,t)=>{t.r(r),t.d(r,{expandOpenedCell:()=>i,expandStandard:()=>function e(r,t,n){let l=r.length,a=r[0].length;if(t<0||t>=l||n<0||n>=a||r[t][n]===o.CellCode.MINE||r[t][n]!==o.CellCode.NOTHING)return;let i=0;for(let e=-1;e<=1;e++)for(let s=-1;s<=1;s++){if(0===e&&0===s)continue;let u=t+e,C=n+s;u>=0&&u<l&&C>=0&&C<a&&r[u][C]===o.CellCode.MINE&&i++}if(r[t][n]=i,0===i)for(let o=-1;o<=1;o++)for(let l=-1;l<=1;l++)e(r,t+o,n+l)},getFlagIncDec:()=>a,getNextCellCode:()=>l,initBoard:()=>n});var o=t(85251);function n(e,r,t){let n=Array(e*r).fill(0).map((e,r)=>r),l=[],a=[];for(;n.length>e*r-t;){let e=n.splice(Math.floor(Math.random()*n.length),1)[0];l.push(e)}for(let t=0;t<r;t++){let r=Array(e).fill(o.CellCode.NOTHING);a.push(r)}for(let r=0;r<l.length;r++){let t=l[r]%e;a[Math.floor(l[r]/e)][t]=o.CellCode.MINE}return a}function l(e){switch(e){case o.CellCode.NOTHING:return o.CellCode.FLAG;case o.CellCode.MINE:return o.CellCode.MINE_FLAG;case o.CellCode.FLAG:return o.CellCode.QUESTION;case o.CellCode.MINE_FLAG:return o.CellCode.MINE_QUESTION;case o.CellCode.QUESTION:return o.CellCode.NOTHING;case o.CellCode.MINE_QUESTION:return o.CellCode.MINE;default:return e}}function a(e){switch(e){case o.CellCode.NOTHING:case o.CellCode.MINE:return 1;case o.CellCode.FLAG:case o.CellCode.MINE_FLAG:return -1;default:return 0}}function i(e,r,t){let n=0,l=(r,t)=>{let a;if(e[t][r]!==o.CellCode.NOTHING)return;e[t][r]=(a=[],a=(a=e[t-1]?a.concat(e[t-1][r-1],e[t-1][r],e[t-1][r+1]):a).concat(e[t][r-1],e[t][r+1]),(a=e[t+1]?a.concat(e[t+1][r-1],e[t+1][r],e[t+1][r+1]):a).filter(e=>[o.CellCode.MINE,o.CellCode.MINE_FLAG,o.CellCode.MINE_QUESTION].includes(e)).length),n++;let i=[];i=(i=e[t-1]?i.concat({x:r-1,y:t-1},{x:r,y:t-1},{x:r+1,y:t-1}
39):i).concat({x:r-1,y:t},{x:r+1,y:t}),i=e[t+1]?i.concat({x:r-1,y:t+1},{x:r,y:t+1},{x:r+1,y:t+1}):i,0===e[t][r]&&i.forEach(e=>{l(e.x,e.y)})};return l(r,t),{boardData:e,openedCellCount:n}}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.