11.9 脚本调试 手机网页调试参考
效果在页面下方

网页调试,不方便打开控制台,可以拿来用,当然,和程序写在一个js里最好
termux直接跑~
<!-- ✅ 调试面板:随时可删 -->
<div id="debugPanel" style="
position: fixed;
bottom: 0; left: 0; right: 0;
height: 120px;
background: rgba(0,0,0,0.85);
color: #0f0;
font: 12px/1.4 monospace;
overflow-y: auto;
padding: 6px 8px;
box-sizing: border-box;
z-index: 9999;
white-space: pre-wrap;
"></div>
<script>
/* ================ 调试钩子:随时可删 ================ */
(function(){
const panel = document.getElementById('debugPanel');
function log(...args) {
panel.textContent = [...args].join(' ') + '\n' + panel.textContent;
panel.scrollTop = 0;
}
// 保存原函数
const oldMakeMove = GomokuGame.prototype.makeMove;
const oldFindThreeThreat = GomokuGame.prototype.findThreeThreat;
const oldCheckThreeInDirection = GomokuGame.prototype.checkThreeInDirection;
// 落子钩子:打印下了哪、当前棋盘
GomokuGame.prototype.makeMove = function(index, player) {
const row = Math.floor(index / this.boardSize);
const col = index % this.boardSize;
log(`[落子] ${player} → (${row},${col})`);
// 调用原版
return oldMakeMove.call(this, index, player);
};
// 检测三连钩子:打印检测过程
GomokuGame.prototype.findThreeThreat = function(player) {
log(`[findThreeThreat] 开始检测 player=${player}`);
const res = oldFindThreeThreat.call(this, player);
log(`[findThreeThreat] 返回威胁索引:${res}`);
return res;
};
// 方向检测钩子:打印详细参数
GomokuGame.prototype.checkThreeInDirection = function(row, col, player, [dx, dy]) {
const res = oldCheckThreeInDirection.call(this, row, col, player, [dx, dy]);
log(`[checkThreeInDirection] (${row},${col}) dir(${dx},${dy}) → ${res ? '✅活三' : '❌不是活三'}`);
return res;
};
})();
</script>
<!-- ✅ 调试面板
