我刚刚为游戏启动了一个 AI 机器人nethack
,我无法绕过源代码中的“人工检查”。我正在谈论的代码部分是nethack/sys/unix/unixunix.c
:
#ifdef TTY_GRAPHICS
/* idea from rpick%ucqais@uccba.uc.edu
* prevent automated rerolling of characters
* test input (fd0) so that tee'ing output to get a screen dump still
* works
* also incidentally prevents development of any hack-o-matic programs
*/
/* added check for window-system type -dlc */
if (!strcmp(windowprocs.name, "tty"))
if (!isatty(0))
error("You must play from a terminal.");
#endif
我正在使用 JavaScript(更具体地说是 Node.js),由于上述原因,它不会让我从程序中播放,即使我正在生成一个 bash shell 子进程并告诉它 start nethack
。我需要想办法绕过上述方法而不重新编译源代码。
我正在使用的当前代码是:
"use strict";
var env = { TERM: 'tty' };
for (var k in process.env) {
env[k] = process.env[k];
}
var terminal = require('child_process').spawn('bash', [], {
env: env,
});
terminal.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
setTimeout(function() {
terminal.stdin.write('nethack');
terminal.stdin.end();
}, 1000);
程序的输出是:
stdout: You must play from a terminal.
child process exited with code 1
我可以使用什么 Node.js/JavaScript(而不是任何其他语言或框架,如果可能的话)黑魔法来解决这个问题?